liquid-rails 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +8 -3
  4. data/CHANGELOG.md +28 -0
  5. data/Gemfile +4 -4
  6. data/README.md +6 -2
  7. data/Rakefile +2 -2
  8. data/gemfiles/rails_32.gemfile +3 -3
  9. data/gemfiles/rails_40.gemfile +3 -3
  10. data/gemfiles/rails_41.gemfile +3 -3
  11. data/gemfiles/rails_42.gemfile +11 -0
  12. data/lib/liquid-rails/drops/collection_drop.rb +2 -2
  13. data/lib/liquid-rails/file_system.rb +3 -4
  14. data/lib/liquid-rails/filters/misc_filter.rb +0 -18
  15. data/lib/liquid-rails/filters/paginate_filter.rb +59 -0
  16. data/lib/liquid-rails/filters/text_filter.rb +0 -1
  17. data/lib/liquid-rails/filters/translate_filter.rb +4 -3
  18. data/lib/liquid-rails/rspec/view_controller_context.rb +3 -2
  19. data/lib/liquid-rails/tags/content_for_tag.rb +13 -4
  20. data/lib/liquid-rails/tags/paginate_tag.rb +2 -1
  21. data/lib/liquid-rails/version.rb +1 -1
  22. data/liquid-rails.gemspec +1 -1
  23. data/spec/dummy/app/controllers/foospace/bar_controller.rb +5 -0
  24. data/spec/dummy/app/views/foospace/bar/_partial.liquid +1 -0
  25. data/spec/dummy/app/views/foospace/bar/index_partial.liquid +3 -0
  26. data/spec/dummy/config/locales/en.yml +1 -0
  27. data/spec/dummy/config/locales/km.yml +1 -0
  28. data/spec/dummy/config/routes.rb +3 -1
  29. data/spec/lib/liquid-rails/filters/translate_filter_spec.rb +6 -2
  30. data/spec/lib/liquid-rails/tags/content_for_tag_spec.rb +7 -1
  31. data/spec/lib/liquid-rails/tags/csrf_meta_tag_spec.rb +11 -2
  32. data/spec/lib/liquid-rails/tags/paginate_tag_spec.rb +68 -4
  33. data/spec/lib/liquid-rails/template_handler_spec.rb +7 -1
  34. data/spec/spec_helper.rb +0 -2
  35. data/spec/support/delegate_matcher.rb +7 -7
  36. metadata +16 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e9723ef54a8b5602a0eece9ecbf5a3eef85e53f
4
- data.tar.gz: 660456e3598bacf1b5f435bea0b7875d46bd7a54
3
+ metadata.gz: 60effe936f0e73722ccb5017936e8ebd3194225a
4
+ data.tar.gz: 5184c687fab2ae2966cce49ca46d78576936889e
5
5
  SHA512:
6
- metadata.gz: ff1a8eca8c43f25d3829951b86b55d747abb5d343224568919f7c25be686ca5a11c469de95111c78caede8327c708cb494fdb81af02b10a94cd671e02603bc5b
7
- data.tar.gz: a596f42ec4296f3863f81dab54123ca1f47fbb6fe2d4c6e81ba401470f7cfd509b3737cebf9ca92c9a6d5be99def38238a4483603a785fd4311387447cf69286
6
+ metadata.gz: cc4fbd79de3c6d0f6529bc597184553dfb2abdce2a195f48d641f1179ab52c5a7ad8401cb71b2131306409252173e6a573beb4a4bd64f95b90c78e60b0a872a3
7
+ data.tar.gz: bba6ac533ec927f2619948a5761e7ed3230080133f551774371b0e7aaa9b67d564946831452a0f7b73a70d9bd6280142bf9a2b92212e55061f8db40f5c3ebc4b
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1.3
1
+ ruby-2.2.0
data/.travis.yml CHANGED
@@ -2,16 +2,21 @@ language: ruby
2
2
  script: "bundle exec rake spec"
3
3
  rvm:
4
4
  - 2.0.0
5
- - 2.1.0
6
- - 2.1.1
7
- - 2.1.2
5
+ - 2.1.5
6
+ - 2.2.0
8
7
  env:
9
8
  - CODECLIMATE_REPO_TOKEN=891d362268d07d6ff0f5534f92252b6195f6be8795054d3627643eb6314a8c9e
10
9
  gemfile:
10
+ - gemfiles/rails_32.gemfile
11
11
  - gemfiles/rails_40.gemfile
12
12
  - gemfiles/rails_41.gemfile
13
+ - gemfiles/rails_42.gemfile
13
14
  notifications:
14
15
  email: false
16
+ matrix:
17
+ exclude:
18
+ - rvm: 2.2.0
19
+ gemfile: gemfiles/rails_32.gemfile
15
20
  addons:
16
21
  code_climate:
17
22
  repo_token: 891d362268d07d6ff0f5534f92252b6195f6be8795054d3627643eb6314a8c9e
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Overview
2
+
3
+ ## 0.1.1 - Not released
4
+
5
+ ### New Features
6
+
7
+ * Add `bootstrap_pagination` filter. (Radin Reth)
8
+
9
+ * Allow `translate` filter with interpolation. (Tomasz Stachewicz, Chamnap Chhorn)
10
+
11
+ * Support `rails` 4.2 and `ruby` 2.2. (Chamnap Chhorn)
12
+
13
+ * Support `scope` on collection drop. (Radin Reth)
14
+
15
+
16
+ ### Resolved Issues
17
+
18
+ * Add `rel="prev"` and `rel="next"` to `default_pagination` filter. (Radin Reth)
19
+
20
+ * Fix `content_for` and `yield` tag on `rails` 3.2. (Chamnap Chhorn)
21
+
22
+ * \#4 Makes partial template work in namespaced controller. (Tomasz Stachewicz)
23
+
24
+ * `truncate` filter now forwards to the standard filters. (Radin Reth)
25
+
26
+ ## 0.1.0
27
+
28
+ * Initial Release
data/Gemfile CHANGED
@@ -3,10 +3,10 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in liquid-rails.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rails', '~> 4.0.10'
7
- gem 'rspec-rails', '~> 2.14.2'
6
+ gem 'rails', '~> 4.0.13'
7
+ gem 'rspec-rails', '~> 3.2.0'
8
+ gem 'guard-rspec', '~> 4.5.0'
8
9
  gem 'capybara', '~> 2.4.1'
9
10
  gem 'pry-rails'
10
11
  gem 'coveralls'
11
- gem 'simplecov'
12
- gem 'guard-rspec'
12
+ gem 'simplecov'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/yoolk/liquid-rails.svg?branch=master)](https://travis-ci.org/yoolk/liquid-rails)[![Coverage Status](https://coveralls.io/repos/yoolk/liquid-rails/badge.png?branch=master)](https://coveralls.io/r/yoolk/liquid-rails?branch=master)
1
+ [![Build Status](https://travis-ci.org/yoolk/liquid-rails.svg?branch=master)](https://travis-ci.org/yoolk/liquid-rails)[![Coverage Status](https://coveralls.io/repos/yoolk/liquid-rails/badge.png?branch=master)](https://coveralls.io/r/yoolk/liquid-rails?branch=master)[![Gem Version](https://badge.fury.io/rb/liquid-rails.svg)](http://badge.fury.io/rb/liquid-rails)
2
2
  # Liquid-Rails
3
3
 
4
4
  It allows you to render `.liquid` templates with layout and partial support. It also provides filters, tags, drops class to be used inside your liquid template.
@@ -135,6 +135,10 @@ describe CommentDrop do
135
135
  end
136
136
  ```
137
137
 
138
+ ## Contributors
139
+
140
+ * [Radin Reth](https://github.com/radin-reth/)
141
+
138
142
  ## Authors
139
143
 
140
- * [Chamnap Chhorn](https://github.com/chamnap)
144
+ * [Chamnap Chhorn](https://github.com/chamnap)
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ end
9
9
  task default: 'spec:all'
10
10
 
11
11
  namespace :spec do
12
- %w(rails_41 rails_40 rails_32).each do |gemfile|
12
+ %w(rails_42 rails_41 rails_40 rails_32).each do |gemfile|
13
13
  desc "Run Tests against #{gemfile}"
14
14
  task gemfile do
15
15
  sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
@@ -19,7 +19,7 @@ namespace :spec do
19
19
 
20
20
  desc "Run Tests against rails versions"
21
21
  task :all do
22
- %w(rails_41 rails_40 rails_32).each do |gemfile|
22
+ %w(rails_42 rails_41 rails_40 rails_32).each do |gemfile|
23
23
  sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
24
24
  sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
25
25
  end
@@ -1,11 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 3.2.19'
4
- gem 'rspec-rails', '~> 2.14.2'
3
+ gem 'rails', '~> 3.2.21'
4
+ gem 'rspec-rails', '~> 3.2.0'
5
+ gem 'guard-rspec', '~> 4.5.0'
5
6
  gem 'capybara', '~> 2.4.1'
6
7
  gem 'pry-rails'
7
8
  gem 'coveralls'
8
9
  gem 'simplecov'
9
- gem 'guard-rspec'
10
10
 
11
11
  gemspec path: '../'
@@ -1,11 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 4.0.10'
4
- gem 'rspec-rails', '~> 2.14.2'
3
+ gem 'rails', '~> 4.0.13'
4
+ gem 'rspec-rails', '~> 3.2.0'
5
+ gem 'guard-rspec', '~> 4.5.0'
5
6
  gem 'capybara', '~> 2.4.1'
6
7
  gem 'pry-rails'
7
8
  gem 'coveralls'
8
9
  gem 'simplecov'
9
- gem 'guard-rspec'
10
10
 
11
11
  gemspec path: '../'
@@ -1,11 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 4.1.6'
4
- gem 'rspec-rails', '~> 2.14.2'
3
+ gem 'rails', '~> 4.1.9'
4
+ gem 'rspec-rails', '~> 3.2.0'
5
+ gem 'guard-rspec', '~> 4.5.0'
5
6
  gem 'capybara', '~> 2.4.1'
6
7
  gem 'pry-rails'
7
8
  gem 'coveralls'
8
9
  gem 'simplecov'
9
- gem 'guard-rspec'
10
10
 
11
11
  gemspec path: '../'
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.2.0'
4
+ gem 'rspec-rails', '~> 3.2.0'
5
+ gem 'guard-rspec', '~> 4.5.0'
6
+ gem 'capybara', '~> 2.4.1'
7
+ gem 'pry-rails'
8
+ gem 'coveralls'
9
+ gem 'simplecov'
10
+
11
+ gemspec path: '../'
@@ -29,9 +29,9 @@ module Liquid
29
29
  delegate :total_count, :total_pages, to: :objects
30
30
 
31
31
  def initialize(objects, options={})
32
- options.assert_valid_keys(:with)
32
+ options.assert_valid_keys(:with, :scope)
33
33
 
34
- @objects = objects
34
+ @objects = options[:scope].nil? ? objects : objects.send(options[:scope])
35
35
  @drop_class_name = options[:with]
36
36
  end
37
37
 
@@ -4,11 +4,10 @@ module Liquid
4
4
  module Rails
5
5
  class FileSystem < ::Liquid::LocalFileSystem
6
6
  def read_template_file(template_path, context)
7
- controller_name = context.registers[:controller].controller_name
8
- template_path = "#{controller_name}/#{template_path}" unless template_path.include?('/')
9
-
7
+ controller_path = context.registers[:controller].controller_path
8
+ template_path = "#{controller_path}/#{template_path}" unless template_path.include?('/')
10
9
  super
11
10
  end
12
11
  end
13
12
  end
14
- end
13
+ end
@@ -22,24 +22,6 @@ module Liquid
22
22
  def toggle_class_name(class_name, condition)
23
23
  condition ? class_name : nil
24
24
  end
25
-
26
- def default_pagination(paginate)
27
- html = []
28
- html << %(<span class="prev">#{link_to(paginate['previous']['title'], paginate['previous']['url'])}</span>) if paginate['previous']
29
-
30
- for part in paginate['parts']
31
- if part['is_link']
32
- html << %(<span class="page">#{link_to(part['title'], part['url'])}</span>)
33
- elsif part['title'].to_i == paginate['current_page'].to_i
34
- html << %(<span class="page current">#{part['title']}</span>)
35
- else
36
- html << %(<span class="deco">#{part['title']}</span>)
37
- end
38
- end
39
-
40
- html << %(<span class="next">#{link_to(paginate['next']['title'], paginate['next']['url'])}</span>) if paginate['next']
41
- html.join(' ')
42
- end
43
25
  end
44
26
  end
45
27
  end
@@ -0,0 +1,59 @@
1
+ module Liquid
2
+ module Rails
3
+ module PaginateFilter
4
+ def default_pagination(paginate)
5
+ html = []
6
+ html << %(<span class="prev"><a href="#{paginate['previous']['url']}" rel="prev">#{paginate['previous']['title']}</a></span>) if paginate['previous']
7
+
8
+ for part in paginate['parts']
9
+ if part['is_link']
10
+ html << %(<span class="page">#{link_to(part['title'], part['url'])}</span>)
11
+ elsif part['title'].to_i == paginate['current_page'].to_i
12
+ html << %(<span class="page current">#{part['title']}</span>)
13
+ else
14
+ html << %(<span class="deco">#{part['title']}</span>)
15
+ end
16
+ end
17
+
18
+ html << %(<span class="next"><a href="#{paginate['next']['url']}" rel="next">#{paginate['next']['title']}</a></span>) if paginate['next']
19
+ html.join(' ')
20
+ end
21
+
22
+ # Bootstrap pagination filter
23
+ #
24
+ # @param [ paginate ]
25
+ # @param [ size ]: .pagination-lg, .pagination-sm
26
+ def bootstrap_pagination(paginate, size='')
27
+ html = []
28
+ html << %{<nav><ul class="pagination #{size}">}
29
+
30
+ if paginate['previous']
31
+ html << %(<li><a href="#{paginate['previous']['url']}" aria-label="Previous"><span aria-hidden="true">#{paginate['previous']['title']}</span></a></li>)
32
+ else
33
+ html << %(<li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo; Previous</span></a></li>)
34
+ end
35
+
36
+ for part in paginate['parts']
37
+ if part['is_link']
38
+ html << %(<li><a href="#{part['url']}">#{part['title']}</a></li>)
39
+ elsif part['title'].to_i == paginate['current_page'].to_i
40
+ html << %(<li class="active"><span>#{part['title']}</span></li>)
41
+ else
42
+ html << %(<li class="disabled"><span>#{part['title']}</span></li>)
43
+ end
44
+ end
45
+
46
+ if paginate['next']
47
+ html << %(<li><a href="#{paginate['next']['url']}" aria-label="Next"><span aria-hidden="true">#{paginate['next']['title']}</span></a></li>)
48
+ else
49
+ html << %(<li class="disabled"><a href="#" aria-label="Next"><span aria-hidden="true">Next &raquo;</span></a></li>)
50
+ end
51
+
52
+ html << '</nav></ul>'
53
+ html.join(' ')
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ Liquid::Template.register_filter(Liquid::Rails::PaginateFilter)
@@ -2,7 +2,6 @@ module Liquid
2
2
  module Rails
3
3
  module TextFilter
4
4
  delegate \
5
- :truncate,
6
5
  :highlight,
7
6
  :excerpt,
8
7
  :pluralize,
@@ -1,11 +1,12 @@
1
1
  module Liquid
2
2
  module Rails
3
3
  module TranslateFilter
4
- def translate(key, locale = nil, scope = nil)
5
- locale ||= ::I18n.locale.to_s
4
+ def translate(key, options={})
5
+ options = { 'locale' => ::I18n.locale.to_s }.merge(options)
6
6
 
7
- @context.registers[:view].translate(key.to_s, locale: locale, scope: scope)
7
+ @context.registers[:view].translate(key.to_s, options.with_indifferent_access)
8
8
  end
9
+ alias_method :t, :translate
9
10
  end
10
11
  end
11
12
  end
@@ -7,7 +7,7 @@ module Liquid
7
7
  def setup_view_and_controller
8
8
  @view = ActionView::Base.new
9
9
  @controller = ApplicationController.new
10
- @request = ActionController::TestRequest.new
10
+ @request = ActionController::TestRequest.new('PATH_INFO' => '/')
11
11
  @response = ActionController::TestResponse.new
12
12
  @response.request = @request
13
13
  @controller.request = @request
@@ -15,6 +15,7 @@ module Liquid
15
15
  @controller.params = {}
16
16
  @view.assign_controller(@controller)
17
17
  @view.class.send(:include, @controller._helpers)
18
+ @view.class.send(:include, ::Rails.application.routes.url_helpers)
18
19
  end
19
20
 
20
21
  def view
@@ -36,7 +37,7 @@ module Liquid
36
37
  end
37
38
 
38
39
  actual = Liquid::Template.parse(template).render!(context)
39
- expect(actual).to eq(expected)
40
+ expect(actual.strip).to eq(expected.strip)
40
41
  end
41
42
  end
42
43
  end
@@ -22,8 +22,8 @@ module Liquid
22
22
  super
23
23
 
24
24
  if markup =~ Syntax
25
- @identifier = $1.to_s
26
25
  @flush = $3
26
+ @identifier = $1.gsub('\'', '')
27
27
  else
28
28
  raise SyntaxError.new("Syntax Error - Valid syntax: {% content_for [name] %}")
29
29
  end
@@ -31,9 +31,18 @@ module Liquid
31
31
 
32
32
  def render(context)
33
33
  @context = context
34
+ content = super.html_safe
34
35
 
35
- options = @flush == 'true' ? { flush: true } : {}
36
- @context.registers[:view].content_for(@identifier, super.html_safe, options)
36
+ if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 2
37
+ if @flush == 'true'
38
+ @context.registers[:view].view_flow.set(@identifier, content) if content
39
+ else
40
+ @context.registers[:view].view_flow.append(@identifier, content) if content
41
+ end
42
+ else
43
+ options = @flush == 'true' ? { flush: true } : {}
44
+ @context.registers[:view].content_for(@identifier, content, options)
45
+ end
37
46
  ''
38
47
  end
39
48
  end
@@ -49,7 +58,7 @@ module Liquid
49
58
  super
50
59
 
51
60
  if markup =~ Syntax
52
- @identifier = $1
61
+ @identifier = $1.gsub('\'', '')
53
62
  else
54
63
  raise SyntaxError.new("Syntax Error - Valid syntax: {% yield [name] %}")
55
64
  end
@@ -50,11 +50,12 @@ module Liquid
50
50
  pagination = {}
51
51
  pagination['collection'] = paginated_collection
52
52
  pagination['current_offset'] = (current_page-1) * @page_size
53
+ pagination['current_page'] = current_page
53
54
  pagination['page_size'] = @page_size
54
55
  pagination['pages'] = page_count
55
56
  pagination['items'] = paginated_collection.total_count
56
57
  pagination['previous'] = link('&laquo; Previous'.html_safe, current_page-1 ) unless 1 >= current_page
57
- pagination['next'] = link('Next &raquo;'.html_safe, current_page+1 ) unless page_count <= current_page+1
58
+ pagination['next'] = link('Next &raquo;'.html_safe, current_page+1 ) unless page_count < current_page+1
58
59
  pagination['parts'] = []
59
60
 
60
61
  hellip_break = false
@@ -1,5 +1,5 @@
1
1
  module Liquid
2
2
  module Rails
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
data/liquid-rails.gemspec CHANGED
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_dependency 'rails', '>= 3.2'
24
- spec.add_dependency 'liquid', '~> 3.0.0.rc1'
24
+ spec.add_dependency 'liquid', '>= 3.0.0'
25
25
  spec.add_dependency 'kaminari', '~> 0.16.1'
26
26
  end
@@ -0,0 +1,5 @@
1
+ class Foospace::BarController < ApplicationController
2
+ def index_partial
3
+ render layout: false
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ Bar Partial
@@ -0,0 +1,3 @@
1
+ Foospace::BarController
2
+
3
+ {% include 'partial' %}
@@ -1,4 +1,5 @@
1
1
  en:
2
2
  welcome: 'Welcome everyone!'
3
+ welcome_name: 'Welcome, %{name}'
3
4
  links:
4
5
  home: 'Home'
@@ -1,4 +1,5 @@
1
1
  km:
2
2
  welcome: 'សូមស្វាគមន៍'
3
+ welcome_name: 'សូមស្វាគមន៍ %{name}'
3
4
  links:
4
5
  home: 'ទំព័រដើម'
@@ -7,4 +7,6 @@ Rails.application.routes.draw do
7
7
 
8
8
  get '/index_partial', to: 'home#index_partial'
9
9
  get '/index_partial_with_full_path', to: 'home#index_partial_with_full_path'
10
- end
10
+
11
+ get '/foospace/bar/index_partial', to: 'foospace/bar#index_partial'
12
+ end
@@ -14,11 +14,15 @@ module Liquid
14
14
  end
15
15
 
16
16
  it 'translate with specified locale' do
17
- expect(::Liquid::Variable.new("'welcome' | translate: 'km'").render(context)).to eq('សូមស្វាគមន៍')
17
+ expect(::Liquid::Variable.new("'welcome' | translate: locale: 'km'").render(context)).to eq('សូមស្វាគមន៍')
18
18
  end
19
19
 
20
20
  it 'translate with scope' do
21
- expect(::Liquid::Variable.new("'home' | translate: 'km', 'links'").render(context)).to eq('ទំព័រដើម')
21
+ expect(::Liquid::Variable.new("'home' | translate: locale: 'km', scope: 'links'").render(context)).to eq('ទំព័រដើម')
22
+ end
23
+
24
+ it 'translate with interpolation' do
25
+ expect(::Liquid::Variable.new("'welcome_name' | translate: locale: 'en', name: 'Jeremy'").render(context)).to eq('Welcome, Jeremy')
22
26
  end
23
27
  end
24
28
  end
@@ -3,7 +3,13 @@ require 'spec_helper'
3
3
  module Liquid
4
4
  module Rails
5
5
  describe ContentForTag, type: :tag do
6
- it 'content_for and yield' do
6
+ it 'content_for and yield with non-quoted key' do
7
+ Liquid::Template.parse(%|{% content_for not_authorized0 %}alert('You are not authorized to do that!');{% endcontent_for %}|).render(context)
8
+
9
+ expect_template_result(%|{% yield not_authorized0 %}|, "alert('You are not authorized to do that!');")
10
+ end
11
+
12
+ it 'content_for and yield with quoted key' do
7
13
  Liquid::Template.parse(%|{% content_for 'not_authorized1' %}alert('You are not authorized to do that!');{% endcontent_for %}|).render(context)
8
14
 
9
15
  expect_template_result(%|{% yield 'not_authorized1' %}|, "alert('You are not authorized to do that!');")
@@ -6,10 +6,19 @@ module Liquid
6
6
  let(:context) { ::Liquid::Context.new({}, {}, { view: view }) }
7
7
 
8
8
  it '#crsf_meta_tags' do
9
- view.stub(:protect_against_forgery?).and_return(true)
9
+ allow(view).to receive(:protect_against_forgery?).and_return(true)
10
+ allow(view).to receive(:form_authenticity_token).and_return('rails_form_authenticity_token')
10
11
 
11
12
  result = Liquid::Template.parse('{% csrf_meta_tags %}').render(context)
12
- expect(result).to eq(%|<meta content=\"authenticity_token\" name=\"csrf-param\" />\n<meta content=\"#{view.form_authenticity_token}\" name=\"csrf-token\" />|)
13
+ metas = result.split("\n").map { |item| Nokogiri::XML(item).children.first }
14
+ expect(metas.length).to eq(2)
15
+ expect(metas[0].name).to eq('meta')
16
+ expect(metas[0]['name']).to eq('csrf-param')
17
+ expect(metas[0]['content']).to eq('authenticity_token')
18
+
19
+ expect(metas[1].name).to eq('meta')
20
+ expect(metas[1]['name']).to eq('csrf-token')
21
+ expect(metas[1]['content']).to eq('rails_form_authenticity_token')
13
22
  end
14
23
  end
15
24
  end
@@ -27,6 +27,10 @@ module Liquid
27
27
  expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_offset }}{% endpaginate %}", '0', { 'post' => @post_drop })
28
28
  end
29
29
 
30
+ it '#current_page' do
31
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_page }}{% endpaginate %}", '1', { 'post' => @post_drop })
32
+ end
33
+
30
34
  it '#page_size' do
31
35
  expect_template_result("{% paginate post.comments by 2 %}{{ paginate.page_size }}{% endpaginate %}", '2', { 'post' => @post_drop })
32
36
  end
@@ -44,16 +48,34 @@ module Liquid
44
48
  end
45
49
 
46
50
  it '#next' do
47
- expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %|{"title"=>"Next &raquo;", "url"=>"?page=2", "is_link"=>true}|, { 'post' => @post_drop })
51
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %|{"title"=>"Next &raquo;", "url"=>"/?page=2", "is_link"=>true}|, { 'post' => @post_drop })
48
52
  end
49
53
 
50
54
  it '#parts' do
51
- expect_template_result("{% paginate post.comments by 2 %}{{ paginate.parts }}{% endpaginate %}", %|{"title"=>1, "is_link"=>false, "hellip_break"=>false}{"title"=>2, "url"=>"?page=2", "is_link"=>true}{"title"=>3, "url"=>"?page=3", "is_link"=>true}|, { 'post' => @post_drop })
55
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.parts }}{% endpaginate %}", %|{"title"=>1, "is_link"=>false, "hellip_break"=>false}{"title"=>2, "url"=>"/?page=2", "is_link"=>true}{"title"=>3, "url"=>"/?page=3", "is_link"=>true}|, { 'post' => @post_drop })
56
+ end
57
+ end
58
+
59
+ context 'second_page' do
60
+ before(:all) { controller.params[:page] = 2 }
61
+ after(:all) { controller.params[:page] = nil }
62
+
63
+ it '#current_page' do
64
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_page }}{% endpaginate %}", '2', { 'post' => @post_drop })
65
+ end
66
+
67
+ it '#previous' do
68
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", %|{"title"=>"&laquo; Previous", "url"=>"/?page=1", "is_link"=>true}|, { 'post' => @post_drop })
69
+ end
70
+
71
+ it '#next' do
72
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %|{"title"=>"Next &raquo;", "url"=>"/?page=3", "is_link"=>true}|, { 'post' => @post_drop })
52
73
  end
53
74
  end
54
75
 
55
76
  context 'last_page' do
56
77
  before(:all) { controller.params[:page] = 3 }
78
+ after(:all) { controller.params[:page] = nil }
57
79
 
58
80
  it 'returns the page size' do
59
81
  expect_template_result("{% paginate post.comments by 2 %}{{ paginate.collection | size }}{% endpaginate %}", '1', { 'post' => @post_drop })
@@ -67,6 +89,10 @@ module Liquid
67
89
  expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_offset }}{% endpaginate %}", '4', { 'post' => @post_drop })
68
90
  end
69
91
 
92
+ it '#current_page' do
93
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_page }}{% endpaginate %}", '3', { 'post' => @post_drop })
94
+ end
95
+
70
96
  it '#page_size' do
71
97
  expect_template_result("{% paginate post.comments by 2 %}{{ paginate.page_size }}{% endpaginate %}", '2', { 'post' => @post_drop })
72
98
  end
@@ -80,7 +106,7 @@ module Liquid
80
106
  end
81
107
 
82
108
  it '#previous' do
83
- expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", %|{"title"=>"&laquo; Previous", "url"=>"?page=2", "is_link"=>true}|, { 'post' => @post_drop })
109
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", %|{"title"=>"&laquo; Previous", "url"=>"/?page=2", "is_link"=>true}|, { 'post' => @post_drop })
84
110
  end
85
111
 
86
112
  it '#next' do
@@ -88,7 +114,45 @@ module Liquid
88
114
  end
89
115
 
90
116
  it '#parts' do
91
- expect_template_result("{% paginate post.comments by 2 %}{{ paginate.parts }}{% endpaginate %}", %|{"title"=>1, "url"=>"?page=1", "is_link"=>true}{"title"=>2, "url"=>"?page=2", "is_link"=>true}{"title"=>3, "is_link"=>false, "hellip_break"=>false}|, { 'post' => @post_drop })
117
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.parts }}{% endpaginate %}", %|{"title"=>1, "url"=>"/?page=1", "is_link"=>true}{"title"=>2, "url"=>"/?page=2", "is_link"=>true}{"title"=>3, "is_link"=>false, "hellip_break"=>false}|, { 'post' => @post_drop })
118
+ end
119
+ end
120
+
121
+ context 'default_pagination' do
122
+ after(:all) { controller.params[:page] = nil }
123
+
124
+ it 'is in the first_page' do
125
+ controller.params[:page] = 1
126
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate | default_pagination }}{% endpaginate %}", %|<span class=\"page current\">1</span> <span class=\"page\"><a href=\"/?page=2\">2</a></span> <span class=\"page\"><a href=\"/?page=3\">3</a></span> <span class=\"next\"><a href=\"/?page=2\" rel=\"next\">Next &raquo;</a></span>|, { 'post' => @post_drop })
127
+ end
128
+
129
+ it 'is in the second_page' do
130
+ controller.params[:page] = 2
131
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate | default_pagination }}{% endpaginate %}", %|<span class=\"prev\"><a href=\"/?page=1\" rel=\"prev\">&laquo; Previous</a></span> <span class=\"page\"><a href=\"/?page=1\">1</a></span> <span class=\"page current\">2</span> <span class=\"page\"><a href=\"/?page=3\">3</a></span> <span class=\"next\"><a href=\"/?page=3\" rel=\"next\">Next &raquo;</a></span>|, { 'post' => @post_drop })
132
+ end
133
+
134
+ it 'is in the last_page' do
135
+ controller.params[:page] = 3
136
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate | default_pagination }}{% endpaginate %}", %|<span class=\"prev\"><a href=\"/?page=2\" rel=\"prev\">&laquo; Previous</a></span> <span class=\"page\"><a href=\"/?page=1\">1</a></span> <span class=\"page\"><a href=\"/?page=2\">2</a></span> <span class=\"page current\">3</span>|, { 'post' => @post_drop })
137
+ end
138
+ end
139
+
140
+ context 'bootstrap_pagination' do
141
+ after(:all) { controller.params[:page] = nil }
142
+
143
+ it 'is in the first_page' do
144
+ controller.params[:page] = 1
145
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate | bootstrap_pagination }}{% endpaginate %}", %|<nav><ul class="pagination "> <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo; Previous</span></a></li> <li class="active"><span>1</span></li> <li><a href="/?page=2">2</a></li> <li><a href="/?page=3">3</a></li> <li><a href="/?page=2" aria-label="Next"><span aria-hidden="true">Next &raquo;</span></a></li> </nav></ul>|, { 'post' => @post_drop })
146
+ end
147
+
148
+ it 'is in the second_page' do
149
+ controller.params[:page] = 2
150
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate | bootstrap_pagination }}{% endpaginate %}", %|<nav><ul class="pagination "> <li><a href="/?page=1" aria-label="Previous"><span aria-hidden="true">&laquo; Previous</span></a></li> <li><a href="/?page=1">1</a></li> <li class="active"><span>2</span></li> <li><a href="/?page=3">3</a></li> <li><a href="/?page=3" aria-label="Next"><span aria-hidden="true">Next &raquo;</span></a></li> </nav></ul>|, { 'post' => @post_drop })
151
+ end
152
+
153
+ it 'is in the last_page' do
154
+ controller.params[:page] = 3
155
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate | bootstrap_pagination }}{% endpaginate %}", %|<nav><ul class="pagination "> <li><a href="/?page=2" aria-label="Previous"><span aria-hidden="true">&laquo; Previous</span></a></li> <li><a href="/?page=1">1</a></li> <li><a href="/?page=2">2</a></li> <li class="active"><span>3</span></li> <li class="disabled"><a href="#" aria-label="Next"><span aria-hidden="true">Next &raquo;</span></a></li> </nav></ul>|, { 'post' => @post_drop })
92
156
  end
93
157
  end
94
158
  end
@@ -35,6 +35,12 @@ describe 'Request', type: :feature do
35
35
 
36
36
  expect(page.body).to eq "Application Layout\nLiquid on Rails\n\nHome Partial\nShared Partial"
37
37
  end
38
+
39
+ it 'respects namespace of original template for partials path' do
40
+ visit '/foospace/bar/index_partial'
41
+ expect(page.body.strip).to eq("Foospace::BarController\n\nBar Partial")
42
+ end
43
+
38
44
  end
39
45
 
40
46
  context 'render with filter' do
@@ -50,4 +56,4 @@ describe 'Request', type: :feature do
50
56
  expect(page.body).to eq("Application Layout\nLiquid on Rails\nThis is a long section of text")
51
57
  end
52
58
  end
53
- end
59
+ end
data/spec/spec_helper.rb CHANGED
@@ -22,7 +22,6 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__)
22
22
  require 'pry'
23
23
  require 'liquid-rails'
24
24
  require 'rspec/rails'
25
- require 'rspec/autorun'
26
25
  require 'capybara/rspec'
27
26
  require 'liquid-rails/matchers'
28
27
 
@@ -35,7 +34,6 @@ require 'fixtures/poro'
35
34
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
36
35
 
37
36
  RSpec.configure do |config|
38
- config.treat_symbols_as_metadata_keys_with_true_values = true
39
37
  config.filter_run focus: true
40
38
  config.run_all_when_everything_filtered = true
41
39
  config.include Capybara::RSpecMatchers
@@ -1,6 +1,6 @@
1
1
  # RSpec matcher to spec delegations.
2
- # Forked from https://gist.github.com/ssimeonov/5942729 with fixes
3
- # for arity + custom prefix.
2
+ # Gist Version https://gist.github.com/joeytheman/0fe021821e4c62f552ce
3
+ #
4
4
  #
5
5
  # Usage:
6
6
  #
@@ -30,7 +30,7 @@ RSpec::Matchers.define :delegate do |method|
30
30
  unless [0,-1].include?(@delegator.method(@to).arity)
31
31
  raise "#{@delegator}'s' #{@to} method does not have zero or -1 arity (it expects parameters)"
32
32
  end
33
- @delegator.stub(@to).and_return receiver_double(method)
33
+ allow(@delegator).to receive(@to).and_return(receiver_double(method))
34
34
  @delegator.send(@method) == :called
35
35
  else
36
36
  raise "#{@delegator} does not respond to #{@to}"
@@ -41,20 +41,20 @@ RSpec::Matchers.define :delegate do |method|
41
41
  "delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
42
42
  end
43
43
 
44
- failure_message_for_should do |text|
44
+ failure_message do |text|
45
45
  "expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
46
46
  end
47
47
 
48
- failure_message_for_should_not do |text|
48
+ failure_message_when_negated do |text|
49
49
  "expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
50
50
  end
51
51
 
52
52
  chain(:to) { |receiver| @to = receiver }
53
- chain(:with_prefix) { |prefix| @prefix = prefix || @to }
53
+ chain(:with_prefix) { |*prefix| @prefix = prefix.first || @to }
54
54
 
55
55
  def receiver_double(method)
56
56
  double('receiver').tap do |receiver|
57
- receiver.stub(method).and_return :called
57
+ allow(receiver).to receive(method).and_return(:called)
58
58
  end
59
59
  end
60
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chamnap Chhorn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-10 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: liquid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0.rc1
33
+ version: 3.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0.rc1
40
+ version: 3.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: kaminari
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,7 @@ files:
66
66
  - ".ruby-gemset"
67
67
  - ".ruby-version"
68
68
  - ".travis.yml"
69
+ - CHANGELOG.md
69
70
  - Gemfile
70
71
  - Guardfile
71
72
  - LICENSE.txt
@@ -74,6 +75,7 @@ files:
74
75
  - gemfiles/rails_32.gemfile
75
76
  - gemfiles/rails_40.gemfile
76
77
  - gemfiles/rails_41.gemfile
78
+ - gemfiles/rails_42.gemfile
77
79
  - lib/liquid-rails.rb
78
80
  - lib/liquid-rails/drops/collection_drop.rb
79
81
  - lib/liquid-rails/drops/drop.rb
@@ -85,6 +87,7 @@ files:
85
87
  - lib/liquid-rails/filters/google_static_map_url_filter.rb
86
88
  - lib/liquid-rails/filters/misc_filter.rb
87
89
  - lib/liquid-rails/filters/number_filter.rb
90
+ - lib/liquid-rails/filters/paginate_filter.rb
88
91
  - lib/liquid-rails/filters/sanitize_filter.rb
89
92
  - lib/liquid-rails/filters/text_filter.rb
90
93
  - lib/liquid-rails/filters/translate_filter.rb
@@ -111,12 +114,15 @@ files:
111
114
  - spec/dummy/app/assets/stylesheets/application.css
112
115
  - spec/dummy/app/controllers/application_controller.rb
113
116
  - spec/dummy/app/controllers/concerns/.keep
117
+ - spec/dummy/app/controllers/foospace/bar_controller.rb
114
118
  - spec/dummy/app/controllers/home_controller.rb
115
119
  - spec/dummy/app/controllers/pages_controller.rb
116
120
  - spec/dummy/app/helpers/application_helper.rb
117
121
  - spec/dummy/app/mailers/.keep
118
122
  - spec/dummy/app/models/.keep
119
123
  - spec/dummy/app/models/concerns/.keep
124
+ - spec/dummy/app/views/foospace/bar/_partial.liquid
125
+ - spec/dummy/app/views/foospace/bar/index_partial.liquid
120
126
  - spec/dummy/app/views/home/_partial.liquid
121
127
  - spec/dummy/app/views/home/index.liquid
122
128
  - spec/dummy/app/views/home/index_partial.liquid
@@ -189,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
195
  version: 1.8.11
190
196
  requirements: []
191
197
  rubyforge_project:
192
- rubygems_version: 2.2.2
198
+ rubygems_version: 2.4.5
193
199
  signing_key:
194
200
  specification_version: 4
195
201
  summary: Renders liquid templates with layout and partial support
@@ -201,12 +207,15 @@ test_files:
201
207
  - spec/dummy/app/assets/stylesheets/application.css
202
208
  - spec/dummy/app/controllers/application_controller.rb
203
209
  - spec/dummy/app/controllers/concerns/.keep
210
+ - spec/dummy/app/controllers/foospace/bar_controller.rb
204
211
  - spec/dummy/app/controllers/home_controller.rb
205
212
  - spec/dummy/app/controllers/pages_controller.rb
206
213
  - spec/dummy/app/helpers/application_helper.rb
207
214
  - spec/dummy/app/mailers/.keep
208
215
  - spec/dummy/app/models/.keep
209
216
  - spec/dummy/app/models/concerns/.keep
217
+ - spec/dummy/app/views/foospace/bar/_partial.liquid
218
+ - spec/dummy/app/views/foospace/bar/index_partial.liquid
210
219
  - spec/dummy/app/views/home/_partial.liquid
211
220
  - spec/dummy/app/views/home/index.liquid
212
221
  - spec/dummy/app/views/home/index_partial.liquid