Skip to content

Commit

Permalink
Support Liquid 4 and Rails 5
Browse files Browse the repository at this point in the history
  • Loading branch information
chamnap committed Dec 31, 2017
1 parent 6181b7b commit 19f5f44
Show file tree
Hide file tree
Showing 69 changed files with 550 additions and 218 deletions.
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ rvm:
env:
- CODECLIMATE_REPO_TOKEN=891d362268d07d6ff0f5534f92252b6195f6be8795054d3627643eb6314a8c9e
gemfile:
- gemfiles/rails_32.gemfile
- gemfiles/rails_40.gemfile
- gemfiles/rails_41.gemfile
- gemfiles/rails_42.gemfile
- gemfiles/rails_50.gemfile
- gemfiles/rails_51.gemfile
- gemfiles/rails_52.gemfile
notifications:
email: false
matrix:
exclude:
- rvm: 2.2.0
gemfile: gemfiles/rails_32.gemfile
addons:
code_climate:
repo_token: 891d362268d07d6ff0f5534f92252b6195f6be8795054d3627643eb6314a8c9e
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Overview

## 0.2.0

### Resolved Issues

* Fix `Content-Type` issue
* Support from Liquid v4, Rails v5, and Kaminari v1 and up
* Use `ActionView::Resolver` as Liquid filesystem (lowang, streppa-ent)

## 0.1.4

### Resolved Issues
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in liquid-rails.gemspec
gemspec

gem 'rails', '~> 4.2.10'
gem 'rails', '~> 5.0.6'
gem 'rake', '~> 12.3.0'
gem 'rspec-rails', '~> 3.5.2'
gem 'guard-rspec', '~> 4.7.3'
gem 'capybara', '~> 2.16.1'
gem 'pry-rails', '~> 0.3.6'
gem 'coveralls', '~> 0.8.21'
gem 'simplecov', '~> 0.14.1'
gem 'sqlite3', '~> 1.3.13'
7 changes: 4 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ end
task default: 'spec:all'

namespace :spec do
%w(rails_42 rails_41 rails_40 rails_32).each do |gemfile|
rails_versions = %w(rails_50 rails_51 rails_52)
rails_versions.each do |gemfile|
desc "Run Tests against #{gemfile}"
task gemfile do
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
Expand All @@ -19,9 +20,9 @@ namespace :spec do

desc "Run Tests against rails versions"
task :all do
%w(rails_42 rails_41 rails_40 rails_32).each do |gemfile|
rails_versions.each do |gemfile|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
end
end
end
end
12 changes: 0 additions & 12 deletions gemfiles/rails_42.gemfile

This file was deleted.

4 changes: 2 additions & 2 deletions gemfiles/rails_32.gemfile → gemfiles/rails_50.gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
source 'https://rubygems.org'

gem 'rails', '~> 3.2.21'
gem 'rails', '~> 5.0.6'
gem 'rake', '~> 12.3.0'
gem 'rspec-rails', '~> 3.5.2'
gem 'guard-rspec', '~> 4.7.3'
gem 'capybara', '~> 2.16.1'
gem 'test-unit', '~> 3.0'
gem 'pry-rails', '~> 0.3.6'
gem 'coveralls', '~> 0.8.21'
gem 'simplecov', '~> 0.14.1'
gem 'sqlite3', '~> 1.3.13'

gemspec path: '../'
3 changes: 2 additions & 1 deletion gemfiles/rails_40.gemfile → gemfiles/rails_51.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
source 'https://rubygems.org'

gem 'rails', '~> 4.0.13'
gem 'rails', '~> 5.1.4'
gem 'rake', '~> 12.3.0'
gem 'rspec-rails', '~> 3.5.2'
gem 'guard-rspec', '~> 4.7.3'
gem 'capybara', '~> 2.16.1'
gem 'pry-rails', '~> 0.3.6'
gem 'coveralls', '~> 0.8.21'
gem 'simplecov', '~> 0.14.1'
gem 'sqlite3', '~> 1.3.13'

gemspec path: '../'
3 changes: 2 additions & 1 deletion gemfiles/rails_41.gemfile → gemfiles/rails_52.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
source 'https://rubygems.org'

gem 'rails', '~> 4.1.9'
gem 'rails', '~> 5.2.0.beta2'
gem 'rake', '~> 12.3.0'
gem 'rspec-rails', '~> 3.5.2'
gem 'guard-rspec', '~> 4.7.3'
gem 'capybara', '~> 2.16.1'
gem 'pry-rails', '~> 0.3.6'
gem 'coveralls', '~> 0.8.21'
gem 'simplecov', '~> 0.14.1'
gem 'sqlite3', '~> 1.3.13'

gemspec path: '../'
2 changes: 1 addition & 1 deletion lib/liquid-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def self.setup_drop(base)
end

require 'liquid-rails/railtie' if defined?(Rails)
Dir[File.dirname(__FILE__) + '/liquid-rails/{filters,tags,drops}/*.rb'].each { |f| require f }
Dir[File.dirname(__FILE__) + '/liquid-rails/{filters,tags,drops}/*.rb'].each { |f| require f }
33 changes: 29 additions & 4 deletions lib/liquid-rails/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,36 @@

module Liquid
module Rails
class FileSystem < ::Liquid::LocalFileSystem
def read_template_file(template_path, context)
controller_path = context.registers[:controller].controller_path
class FileSystem
def initialize(view)
@view = view
end

def read_template_file(template_path)
controller_path = view.controller_path
template_path = "#{controller_path}/#{template_path}" unless template_path.include?('/')
super

name = template_path.split('/').last
prefix = template_path.split('/')[0...-1].join('/')

result = view.view_paths.find_all(name, prefix, true, lookup_details)
raise FileSystemError, "No such template '#{template_path}'" unless result.present?

result.first.source
end

private

attr_reader :view

def lookup_details
{
locale: [view.locale, :en],
formats: view.formats,
variants: [],
handlers: [:liquid],
versions: []
}
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions lib/liquid-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ class Railtie < ::Rails::Railtie
end
end

initializer 'liquid-rails.include_partial' do |app|
template_path = ::Rails.root.join('app/views')
Liquid::Template.file_system = Liquid::Rails::FileSystem.new(template_path)
end

initializer 'liquid-rails.setup_drop' do |app|
[:active_record, :mongoid].each do |orm|
ActiveSupport.on_load orm do
Expand All @@ -23,4 +18,4 @@ class Railtie < ::Rails::Railtie
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/liquid-rails/rspec/drop_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module DropExampleGroup
end
}

before(:all) { setup_view_and_controller }
before(:each) { setup_view_and_controller }
before(:each) { subject.context = context }
end
end
Expand All @@ -35,4 +35,4 @@ module DropExampleGroup
else
config.include Liquid::Rails::Rspec::DropExampleGroup, type: :drop, example_group: { file_path: %r{spec/drops} }
end
end
end
4 changes: 2 additions & 2 deletions lib/liquid-rails/rspec/filter_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module FilterExampleGroup
included do
metadata[:type] = :filter

before(:all) { setup_view_and_controller }
before(:each) { setup_view_and_controller }
end
end
end
Expand All @@ -21,4 +21,4 @@ module FilterExampleGroup
else
config.include Liquid::Rails::Rspec::FilterExampleGroup, type: :filter, example_group: { file_path: %r{spec/filters} }
end
end
end
4 changes: 2 additions & 2 deletions lib/liquid-rails/rspec/tag_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module TagExampleGroup
included do
metadata[:type] = :tag

before(:all) { setup_view_and_controller }
before(:each) { setup_view_and_controller }
end
end
end
Expand All @@ -21,4 +21,4 @@ module TagExampleGroup
else
config.include Liquid::Rails::Rspec::TagExampleGroup, type: :tag, example_group: { file_path: %r{spec/tags} }
end
end
end
8 changes: 4 additions & 4 deletions lib/liquid-rails/rspec/view_controller_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module ViewControllerContext

def setup_view_and_controller
@view = ActionView::Base.new
@controller = ApplicationController.new
@request = ActionController::TestRequest.new('PATH_INFO' => '/')
@response = ActionController::TestResponse.new
@controller = ActionController::Base.new
@request = ActionDispatch::TestRequest.new({'PATH_INFO' => '/'})
@response = ActionDispatch::TestResponse.new
@response.request = @request
@controller.request = @request
@controller.response = @response
Expand Down Expand Up @@ -42,4 +42,4 @@ def expect_template_result(template, expected, assigns={})
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/liquid-rails/tags/paginate_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ def link(title, page)
end
end

Liquid::Template.register_tag('paginate', Liquid::Rails::PaginateTag)
Liquid::Template.register_tag('paginate', Liquid::Rails::PaginateTag)
20 changes: 15 additions & 5 deletions lib/liquid-rails/template_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def initialize(view)
end

def render(template, local_assigns={})
@view.controller.headers['Content-Type'] ||= 'text/html; charset=utf-8'

assigns = if @controller.respond_to?(:liquid_assigns, true)
@controller.send(:liquid_assigns)
else
Expand All @@ -23,9 +21,8 @@ def render(template, local_assigns={})
assigns['content_for_layout'] = @view.content_for(:layout) if @view.content_for?(:layout)
assigns.merge!(local_assigns.stringify_keys)

liquid = Liquid::Template.parse(template)
render_method = (::Rails.env.development? || ::Rails.env.test?) ? :render! : :render
liquid.send(render_method, assigns, filters: filters, registers: { view: @view, controller: @controller, helper: @helper }).html_safe
liquid = Liquid::Template.parse(template)
liquid.send(render_method, assigns, filters: filters, registers: registers).html_safe
end

def filters
Expand All @@ -36,9 +33,22 @@ def filters
end
end

def registers
{
view: @view,
controller: @controller,
helper: @helper,
file_system: Liquid::Rails::FileSystem.new(@view)
}
end

def compilable?
false
end

def render_method
(::Rails.env.development? || ::Rails.env.test?) ? :render! : :render
end
end
end
end
2 changes: 1 addition & 1 deletion lib/liquid-rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Liquid
module Rails
VERSION = '0.1.4'
VERSION = '0.2.0.beta1'
end
end
6 changes: 3 additions & 3 deletions liquid-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'rails', ">= 3.2", "< 5"
spec.add_dependency 'liquid', '~> 3.0.6'
spec.add_dependency 'kaminari', '~> 0.17.0'
spec.add_dependency 'rails', ">= 5.0.6"
spec.add_dependency 'liquid', '~> 4.0.0'
spec.add_dependency 'kaminari', '~> 1.1.1'
end
4 changes: 2 additions & 2 deletions spec/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require_relative 'config/application'

Dummy::Application.load_tasks
Rails.application.load_tasks
3 changes: 3 additions & 0 deletions spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
12 changes: 8 additions & 4 deletions spec/dummy/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class HomeController < ApplicationController
before_filter :set_book
before_action :set_book

def index
render layout: false
Expand All @@ -20,9 +20,13 @@ def index_with_filter
def erb_with_html_liquid_partial
end

def index_with_rss
render layout: false
end

private

def set_book
@book = { 'name' => 'Liquid on Rails' }
end
def set_book
@book = { 'name' => 'Liquid on Rails' }
end
end
4 changes: 2 additions & 2 deletions spec/dummy/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class PagesController < ApplicationController
before_filter :set_book
before_action :set_book

def index_witout_filter
end
Expand All @@ -13,4 +13,4 @@ def liquid_filters
def set_book
@book = { 'name' => 'Liquid on Rails' }
end
end
end
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 19f5f44

Please sign in to comment.