taktsoft_liquid-rails 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +24 -0
  4. data/.rspec +1 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +28 -0
  8. data/CHANGELOG.md +44 -0
  9. data/Gemfile +4 -0
  10. data/Guardfile +33 -0
  11. data/LICENSE.txt +22 -0
  12. data/README.md +152 -0
  13. data/Rakefile +25 -0
  14. data/gemfiles/rails_32.gemfile +9 -0
  15. data/gemfiles/rails_40.gemfile +8 -0
  16. data/gemfiles/rails_41.gemfile +8 -0
  17. data/gemfiles/rails_42.gemfile +8 -0
  18. data/gemfiles/rails_50.gemfile +5 -0
  19. data/lib/liquid-rails/drops/collection_drop.rb +91 -0
  20. data/lib/liquid-rails/drops/drop.rb +114 -0
  21. data/lib/liquid-rails/drops/droppable.rb +22 -0
  22. data/lib/liquid-rails/file_system.rb +13 -0
  23. data/lib/liquid-rails/filters/asset_tag_filter.rb +25 -0
  24. data/lib/liquid-rails/filters/asset_url_filter.rb +37 -0
  25. data/lib/liquid-rails/filters/date_filter.rb +19 -0
  26. data/lib/liquid-rails/filters/google_static_map_url_filter.rb +30 -0
  27. data/lib/liquid-rails/filters/misc_filter.rb +29 -0
  28. data/lib/liquid-rails/filters/number_filter.rb +24 -0
  29. data/lib/liquid-rails/filters/paginate_filter.rb +59 -0
  30. data/lib/liquid-rails/filters/sanitize_filter.rb +19 -0
  31. data/lib/liquid-rails/filters/text_filter.rb +46 -0
  32. data/lib/liquid-rails/filters/translate_filter.rb +14 -0
  33. data/lib/liquid-rails/filters/url_filter.rb +24 -0
  34. data/lib/liquid-rails/matchers.rb +5 -0
  35. data/lib/liquid-rails/railtie.rb +26 -0
  36. data/lib/liquid-rails/rspec/drop_example_group.rb +38 -0
  37. data/lib/liquid-rails/rspec/drop_matchers.rb +165 -0
  38. data/lib/liquid-rails/rspec/filter_example_group.rb +24 -0
  39. data/lib/liquid-rails/rspec/tag_example_group.rb +24 -0
  40. data/lib/liquid-rails/rspec/view_controller_context.rb +63 -0
  41. data/lib/liquid-rails/tags/content_for_tag.rb +77 -0
  42. data/lib/liquid-rails/tags/csrf_meta_tags.rb +11 -0
  43. data/lib/liquid-rails/tags/google_analytics_tag.rb +40 -0
  44. data/lib/liquid-rails/tags/javascript_tag.rb +22 -0
  45. data/lib/liquid-rails/tags/paginate_tag.rb +118 -0
  46. data/lib/liquid-rails/template_handler.rb +44 -0
  47. data/lib/liquid-rails/version.rb +5 -0
  48. data/lib/liquid-rails.rb +23 -0
  49. data/liquid-rails.gemspec +43 -0
  50. metadata +262 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a5b2eea67d42cc7d46a644036e8f496c62da876
4
+ data.tar.gz: 40ba15806d2bdef4506e3201037c54d6207cb29c
5
+ SHA512:
6
+ metadata.gz: a697171930d6419496a994b44369bba26ca3729c841b0e4f3ba1d35d1258fb61ca52b7ff1ce23ba684d7c7bb1a18f93bc1166e85ea867f1ebf5706c97476a737
7
+ data.tar.gz: f9b176b77314bdb5395ab274ed06f2042e694c903ddb24a86348b6a0dc56a1df22143c2f6ce2b3a58edf8234607e8f93bc159305188dfc587cb0f463a61be8c3
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: stxQNkczi4haKGRjKZvd7i8PAooQrahCX
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ spec/dummy/log/*
24
+ gemfiles/*.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ liquid-rails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.5
data/.travis.yml ADDED
@@ -0,0 +1,28 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.10
6
+ - 2.2.5
7
+ - 2.3.1
8
+ gemfile:
9
+ - gemfiles/rails_32.gemfile
10
+ - gemfiles/rails_40.gemfile
11
+ - gemfiles/rails_41.gemfile
12
+ - gemfiles/rails_42.gemfile
13
+ - gemfiles/rails_50.gemfile
14
+ before_install:
15
+ - gem install bundler
16
+ - bundle --version
17
+ matrix:
18
+ exclude:
19
+ - rvm: 2.2.5
20
+ gemfile: gemfiles/rails_32.gemfile
21
+ - rvm: 2.3.1
22
+ gemfile: gemfiles/rails_32.gemfile
23
+ - rvm: 2.0.0
24
+ gemfile: gemfiles/rails_50.gemfile
25
+ - rvm: 2.1.10
26
+ gemfile: gemfiles/rails_50.gemfile
27
+ notifications:
28
+ email: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Overview
2
+
3
+ ## 0.1.4
4
+
5
+ * Support for Rails 5.0
6
+
7
+ ## 0.1.3
8
+
9
+ * ?!?
10
+
11
+ ## 0.1.2
12
+
13
+ ### New Features
14
+
15
+ * Use google analytics universal (Chamnap Chhorn)
16
+
17
+ * Render liquid template as html_safe by default (Dan Kubb)
18
+
19
+ ## 0.1.1
20
+
21
+ ### New Features
22
+
23
+ * Add `bootstrap_pagination` filter. (Radin Reth)
24
+
25
+ * Allow `translate` filter with interpolation. (Tomasz Stachewicz, Chamnap Chhorn)
26
+
27
+ * Support `rails` 4.2 and `ruby` 2.2. (Chamnap Chhorn)
28
+
29
+ * Support `scope` on collection drop. (Radin Reth)
30
+
31
+
32
+ ### Resolved Issues
33
+
34
+ * Add `rel="prev"` and `rel="next"` to `default_pagination` filter. (Radin Reth)
35
+
36
+ * Fix `content_for` and `yield` tag on `rails` 3.2. (Chamnap Chhorn)
37
+
38
+ * \#4 Makes partial template work in namespaced controller. (Tomasz Stachewicz)
39
+
40
+ * `truncate` filter now forwards to the standard filters. (Radin Reth)
41
+
42
+ ## 0.1.0
43
+
44
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in liquid-rails.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ # Rails example
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('config/routes.rb') { "spec/routing" }
23
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
24
+ watch('spec/rails_helper.rb') { "spec" }
25
+
26
+ # Capybara features specs
27
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28
+
29
+ # Turnip features and steps
30
+ watch(%r{^spec/acceptance/(.+)\.feature$})
31
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32
+ end
33
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chamnap Chhorn
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ [![Build Status](https://travis-ci.org/taktsoft/liquid-rails.svg?branch=master)](https://travis-ci.org/taktsoft/liquid-rails) [![Gem Version](https://badge.fury.io/rb/liquid-rails.svg)](http://badge.fury.io/rb/liquid-rails)
2
+
3
+ # Liquid-Rails
4
+
5
+ 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.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'taktsoft_liquid-rails', require: 'liquid-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install taktsoft_liquid-rails
20
+
21
+ ## Usage
22
+
23
+ In order to render with layout, in your layout file `app/views/layouts/application.liquid`, put this:
24
+
25
+ ```html
26
+ {{ content_for_layout }}
27
+ ```
28
+
29
+ ```html
30
+ # It will render app/views/home/_partial.liquid when the current controller is `HomeController`.
31
+ {% include 'partial' %}
32
+
33
+ # It will render app/views/shared/_partial.liquid.
34
+ {% include 'shared/partial' %}
35
+ ```
36
+
37
+ ### Template Rendering
38
+
39
+ By default, **Liquid-Rails** makes all instance variables from controller available to liquid template. To limit only some instance variables, do this inside your controller:
40
+
41
+ ```ruby
42
+ def liquid_assigns
43
+ { 'listing' => current_listing, 'content_for_header' => content_for_header, 'current_account' => current_account }
44
+ end
45
+ ```
46
+
47
+ By default, **Liquid-Rails** makes all your helper methods inside your rails app available to liquid template. To limit only some helpers, do this inside your controller:
48
+
49
+ ```ruby
50
+ def liquid_filters
51
+ []
52
+ end
53
+ ```
54
+
55
+ You can render liquid templates from other template engines, eg. `erb`, `haml`, ...
56
+
57
+ ```ruby
58
+ = render 'shared/partial.liquid'
59
+ ```
60
+
61
+ ### Filter
62
+
63
+ > Filters are simple methods that modify the output of numbers, strings, variables and objects. They are placed within an output tag `{{` `}}` and are separated with a pipe character `|`.
64
+
65
+ Currently, **Liquid-Rails** adds only the followings:
66
+
67
+ 1. [AssetTagFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/asset_tag_filter.rb)
68
+ 2. [AssetUrlFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/asset_url_filter.rb)
69
+ 3. [DateFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/date_filter.rb)
70
+ 4. [NumberFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/number_filter.rb)
71
+ 5. [SanitizeFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/sanitize_filter.rb)
72
+ 6. [TextFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/text_filter.rb)
73
+ 7. [TranslateFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/translate_filter.rb)
74
+ 8. [UrlFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/url_filter.rb)
75
+ 9. [MiscFilter](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/filters/misc_filter.rb)
76
+
77
+ ### Tag
78
+
79
+ > Liquid tags are the programming logic that tells templates what to do. Tags are wrapped in: `{%` `%}`.
80
+
81
+ Currently, **Liquid-Rails** adds only the followings:
82
+
83
+ 1. [csrf_meta_tags](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/tags/csrf_meta_tags.rb)
84
+ 2. [google_analytics_tag](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/tags/google_analytics_tag.rb)
85
+ 3. [javascript_tag](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/tags/javascript_tag.rb)
86
+ 4. [paginate](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/tags/paginate_tag.rb)
87
+ 4. [content_for](https://github.com/taktsoft/liquid-rails/blob/master/lib/liquid-rails/tags/content_for.rb)
88
+
89
+ ### Drop Class
90
+
91
+ > Drops let you provide the user with custom functionality. They are very much like a standard Ruby class, but have all unused and potentially dangerous methods removed. From the user's perspective a drop acts very much like a Hash, though methods are accessed with dot-notation as well as element selection. A drop method cannot be invoked with arguments. Drops are called just-in-time, thus allowing you to lazily load objects.
92
+
93
+ Given two models, a Post(title: string, body: text) and a Comment(name:string, body:text, post_id:integer), you will have two drops:
94
+
95
+ ```ruby
96
+ class PostDrop < Liquid::Rails::Drop
97
+ attributes :id, :title, :body
98
+
99
+ has_many :comments
100
+ end
101
+ ```
102
+
103
+ and
104
+
105
+ ```ruby
106
+ class CommentDrop < Liquid::Rails::Drop
107
+ attributes :id, :name, :body
108
+
109
+ belongs_to :post
110
+ end
111
+ ```
112
+
113
+ Check out more [examples](https://github.com/taktsoft/liquid-rails/blob/master/spec/fixtures/poro.rb).
114
+
115
+ It works for any ORMs. The PORO should include `Liquid::Rails::Droppable`. That's all you need to do to have your POROs supported.
116
+
117
+ ### RSpec
118
+
119
+ In spec_helper.rb, you'll need to require the matchers:
120
+
121
+ ```ruby
122
+ require 'liquid-rails/matchers'
123
+ ```
124
+
125
+ Example:
126
+
127
+ ```ruby
128
+ describe PostDrop do
129
+ it { should have_attribute(:id) }
130
+ it { should have_attribute(:title) }
131
+ it { should have_attribute(:body) }
132
+ it { should have_many(:comments) }
133
+ end
134
+ ```
135
+
136
+ ```ruby
137
+ describe CommentDrop do
138
+ it { should have_attribute(:id) }
139
+ it { should have_attribute(:name) }
140
+ it { should have_attribute(:body) }
141
+ it { should belongs_to(:post) }
142
+ end
143
+ ```
144
+
145
+ ## Contributors
146
+
147
+ * [Radin Reth](https://github.com/radin-reth/)
148
+
149
+ ## Authors
150
+
151
+ * [Chamnap Chhorn](https://github.com/chamnap)
152
+ * [Taktsoft Developers](https://github.com/taktsoft)
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ namespace :spec do
10
+ %w(rails_50 rails_42 rails_41 rails_40 rails_32).each do |gemfile|
11
+ desc "Run Tests against #{gemfile}"
12
+ task gemfile do
13
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
14
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
15
+ end
16
+ end
17
+
18
+ desc "Run Tests against rails versions"
19
+ task :all do
20
+ %w(rails_50 rails_42 rails_41 rails_40 rails_32).each do |gemfile|
21
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
22
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 3.2.22'
4
+
5
+ gem 'test-unit', '~> 3.0'
6
+ gem 'mime-types', '< 3.0'
7
+ gem 'listen', '< 3.1'
8
+
9
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.0.13'
4
+
5
+ gem 'mime-types', '< 3.0'
6
+ gem 'listen', '< 3.1'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.1.16'
4
+
5
+ gem 'mime-types', '< 3.0'
6
+ gem 'listen', '< 3.1'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.2.7'
4
+
5
+ gem 'mime-types', '< 3.0'
6
+ gem 'listen', '< 3.1'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.0.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,91 @@
1
+ module Liquid
2
+ module Rails
3
+ class CollectionDrop < ::Liquid::Drop
4
+
5
+ class << self
6
+ attr_accessor :_scopes
7
+ end
8
+
9
+ def self.inherited(base)
10
+ base._scopes = []
11
+ end
12
+
13
+ def self.scope(*scope_names)
14
+ @_scopes.concat scope_names
15
+
16
+ scope_names.each do |scope_name|
17
+ define_method(scope_name) do
18
+ value = instance_variable_get("@_#{scope_name}")
19
+ return value if value
20
+
21
+ raise ArgumentError, "#{objects.class.name} doesn't define scope: #{scope_name}" unless objects.respond_to?(scope_name)
22
+ instance_variable_set("@_#{scope_name}", self.class.new(objects.send(scope_name)))
23
+ end
24
+ end
25
+ end
26
+
27
+ array_methods = Array.instance_methods - Object.instance_methods
28
+ delegate *array_methods, to: :dropped_collection
29
+ delegate :total_count, :total_pages, to: :objects
30
+
31
+ def initialize(objects, options={})
32
+ options.assert_valid_keys(:with, :scope)
33
+
34
+ @objects = options[:scope].nil? ? objects : objects.send(options[:scope])
35
+ @drop_class_name = options[:with]
36
+ end
37
+
38
+ def page(number)
39
+ self.class.new(objects.page(number))
40
+ end
41
+
42
+ def per(number)
43
+ self.class.new(objects.per(number))
44
+ end
45
+
46
+ def dropped_collection
47
+ @dropped_collection ||= @objects.map { |item| drop_item(item) }
48
+ end
49
+
50
+ def kind_of?(klass)
51
+ dropped_collection.kind_of?(klass) || super
52
+ end
53
+ alias_method :is_a?, :kind_of?
54
+
55
+ ## :[] is invoked by parser before the actual. However, this method has the same name as array method.
56
+ ## Override this, so it will work for both cases.
57
+ ## {{ post_drop.comments[0] }}
58
+ ## {{ post_drop.<other_methods> }}
59
+ def [](method)
60
+ if method.is_a?(Integer)
61
+ dropped_collection.at(method)
62
+ else
63
+ public_send(method)
64
+ end
65
+ end
66
+
67
+ ## Need to override this. I don't understand too, otherwise it will return an array of drop objects.
68
+ ## Need to return self so that we can do chaining.
69
+ def to_liquid
70
+ self
71
+ end
72
+
73
+ def inspect
74
+ "#<#{self.class.name} of #{drop_class} for #{objects.inspect}>"
75
+ end
76
+
77
+ protected
78
+
79
+ attr_reader :objects
80
+
81
+ def drop_class
82
+ @drop_class ||= @drop_class_name.is_a?(String) ? @drop_class_name.safe_constantize : @drop_class_name
83
+ end
84
+
85
+ def drop_item(item)
86
+ liquid_drop_class = drop_class || item.drop_class
87
+ liquid_drop_class.new(item)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,114 @@
1
+ module Liquid
2
+ module Rails
3
+ class Drop < ::Liquid::Drop
4
+
5
+ class << self
6
+ attr_accessor :_attributes
7
+ attr_accessor :_associations
8
+ end
9
+
10
+ def self.inherited(base)
11
+ base._attributes = []
12
+ base._associations = {}
13
+ end
14
+
15
+ def self.attributes(*attrs)
16
+ @_attributes.concat attrs
17
+
18
+ attrs.each do |attr|
19
+ next if method_defined?(attr)
20
+
21
+ define_method(attr) do
22
+ object.send(attr) if object.respond_to?(attr, true)
23
+ end
24
+ end
25
+ end
26
+
27
+ # By default, `Product` maps to `ProductDrop`.
28
+ # Array of products maps to `Liquid::Rails::CollectionDrop`.
29
+ def self.drop_class_for(resource)
30
+ if resource.respond_to?(:to_ary)
31
+ Liquid::Rails::CollectionDrop
32
+ else
33
+ if self == Liquid::Rails::Drop
34
+ resource.drop_class || Liquid::Rails::Drop
35
+ else
36
+ self
37
+ end
38
+ end
39
+ end
40
+
41
+ # Create a drop instance when it cannot be inferred.
42
+ def self.dropify(resource, options={})
43
+ drop_class = if options[:class_name]
44
+ options[:class_name].constantize
45
+ else
46
+ drop_class_for(resource)
47
+ end
48
+
49
+ drop_class.new(resource, options.except(:class_name))
50
+ end
51
+
52
+ def self.belongs_to(*attrs)
53
+ associate(:belongs_to, attrs)
54
+ end
55
+
56
+ def self.has_many(*attrs)
57
+ associate(:has_many, attrs)
58
+ end
59
+
60
+ def self.associate(type, attrs)
61
+ options = attrs.extract_options!
62
+ self._associations = _associations.dup
63
+
64
+ attrs.each do |attr|
65
+ next if method_defined?(attr)
66
+
67
+ define_method attr do
68
+ value = instance_variable_get("@_#{attr}")
69
+ return value if value
70
+
71
+ association = object.send(attr)
72
+ return nil if association.nil?
73
+
74
+ drop_instance = Liquid::Rails::Drop.dropify(association, options)
75
+ instance_variable_set("@_#{attr}", drop_instance)
76
+ end
77
+
78
+ self._associations[attr] = { type: type, options: options }
79
+ end
80
+ end
81
+
82
+ # Wraps an object in a new instance of the drop.
83
+ def initialize(object, options={})
84
+ @object = object
85
+ end
86
+
87
+ def attributes
88
+ @attributes ||= self.class._attributes.dup.each_with_object({}) do |name, hash|
89
+ hash[name.to_s] = send(name)
90
+ end
91
+ end
92
+
93
+ def as_json(options={})
94
+ attributes.as_json(options)
95
+ end
96
+
97
+ def to_json(options={})
98
+ as_json.to_json(options)
99
+ end
100
+
101
+ def before_method(method)
102
+ attributes[method.to_s]
103
+ end
104
+
105
+ def inspect
106
+ "#<#{self.class.name} @object: #{object.inspect} @attributes: #{attributes.inspect}>"
107
+ end
108
+
109
+ protected
110
+
111
+ attr_reader :object
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,22 @@
1
+ module Liquid
2
+ module Rails
3
+ module Droppable
4
+ extend ActiveSupport::Concern
5
+
6
+ def to_liquid
7
+ drop_class.new(self)
8
+ end
9
+ alias_method :dropify, :to_liquid
10
+
11
+ def drop_class
12
+ self.class.drop_class
13
+ end
14
+
15
+ module ClassMethods
16
+ def drop_class
17
+ "#{self.name}Drop".safe_constantize
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'liquid/file_system'
2
+
3
+ module Liquid
4
+ module Rails
5
+ class FileSystem < ::Liquid::LocalFileSystem
6
+ def read_template_file(template_path, context)
7
+ controller_path = context.registers[:controller].controller_path
8
+ template_path = "#{controller_path}/#{template_path}" unless template_path.include?('/')
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ module Liquid
2
+ module Rails
3
+ module AssetTagFilter
4
+ delegate \
5
+ :audio_tag,
6
+ :auto_discovery_link_tag,
7
+ :favicon_link_tag,
8
+ :image_alt,
9
+ :image_tag,
10
+ :javascript_include_tag,
11
+ :stylesheet_link_tag,
12
+ :video_tag,
13
+
14
+ to: :h
15
+
16
+ private
17
+
18
+ def h
19
+ @h ||= @context.registers[:view]
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ Liquid::Template.register_filter(Liquid::Rails::AssetTagFilter)