liquid_renderer 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +10 -0
- data/MIT-LICENSE +20 -0
- data/README.md +50 -0
- data/Rakefile +29 -0
- data/lib/liquid_renderer/controller.rb +80 -0
- data/lib/liquid_renderer/renderer.rb +56 -0
- data/lib/liquid_renderer/version.rb +4 -0
- data/lib/liquid_renderer.rb +11 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZmQ4ZGM1ZjI2ZWE1ZDA4YzQ1NGQyYTA5ODU5YWQ2ZGY0YTM1OTUxNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmZiNmViMjQ5YjYyNjcyZGI3NDgxZjQ5MTIxMzg1MTk0ZGRhMmJlNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmNkMzVmYzg5MTFmNDdhY2FkZGRhZDU3NTM2MTgxZGQ1MGE4MmU3OThhMmRk
|
10
|
+
M2RhOTc4YWI1OGYwZDg2OGUxNDIwMjJjNWFkYWNlZjUzZDQ0NmNkNjkxYThl
|
11
|
+
OGEzOGRiMTc4NjViOTQ2ZDc2NjA4ODNjNDhjNTgwM2UwOTUzMTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWRkNzM5NDUxMGNhM2EwNWJlNjFkYTJhZThiZjcyOTkwYzNiYzA4Mzk2ZmZj
|
14
|
+
NzUyNmQyYThjMTUzY2IxNjQxMjlmNDY5MDBiZGEzNGVjMjVhYTA2OGY4NTQ4
|
15
|
+
ZDRmMmUzN2E1ZGYzMjJmODY1YzMxMmZmMjAxYmNjNjNmOTY5NjU=
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# liquid_renderer
|
2
|
+
|
3
|
+
LiquidRenderer adds liquid renderer and option to include liquid filters like Rails helpers.
|
4
|
+
|
5
|
+
To use it, add this line to your Gemfile:
|
6
|
+
|
7
|
+
gem "liquid_renderer"
|
8
|
+
|
9
|
+
|
10
|
+
## How to use
|
11
|
+
|
12
|
+
### Rendering views
|
13
|
+
Just create `.liquid` files inside your `app/views` directory.
|
14
|
+
|
15
|
+
|
16
|
+
### Using filters
|
17
|
+
|
18
|
+
Creates liquid_filters folder inside your app directory and adds filters using same naming convention of Rails helpers.
|
19
|
+
|
20
|
+
class HomeController < ApplicationController
|
21
|
+
include LiquidRenderer::Controller
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
Create filters inside `app/helpers/liquid_filters` directory
|
26
|
+
|
27
|
+
module LiquidFilters::HomeFilter
|
28
|
+
# this filter will be used to render HomeController views
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
## Code Status
|
33
|
+
|
34
|
+
|
35
|
+
## Contributors
|
36
|
+
|
37
|
+
Reference:
|
38
|
+
|
39
|
+
- http://royvandermeij.com/blog/2011/09/21/create-a-liquid-handler-for-rails-3-dot-1/
|
40
|
+
- http://pragprog.com/book/jvrails/crafting-rails-applications
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
Ruby license or MIT license, take your pick.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rdoc/task'
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
|
14
|
+
Rake::TestTask.new(:test) do |t|
|
15
|
+
t.libs << 'lib'
|
16
|
+
t.libs << 'test'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = false
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => :test
|
22
|
+
|
23
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
25
|
+
rdoc.title = 'LiquidRenderer'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README.rdoc')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module LiquidRenderer
|
2
|
+
|
3
|
+
module Controller
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :_liquid_filters
|
8
|
+
self._liquid_filters = Module.new
|
9
|
+
|
10
|
+
default_liquid_module! unless anonymous?
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
|
15
|
+
def liquid_filter(*args)
|
16
|
+
modules_for_liquid_filters(args).each do |mod|
|
17
|
+
add_liquid_template_filter(mod)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def liquid_filters
|
22
|
+
_liquid_filters
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Returns a list of modules, normalized from the acceptable kinds of
|
28
|
+
# helpers with the following behavior:
|
29
|
+
#
|
30
|
+
# String or Symbol:: :FooBar or "FooBar" becomes "foo_bar_helper",
|
31
|
+
# and "foo_bar_helper.rb" is loaded using require_dependency.
|
32
|
+
#
|
33
|
+
# Module:: No further processing
|
34
|
+
#
|
35
|
+
# After loading the appropriate files, the corresponding modules
|
36
|
+
# are returned.
|
37
|
+
#
|
38
|
+
# ==== Parameters
|
39
|
+
# * <tt>args</tt> - An array of helpers
|
40
|
+
#
|
41
|
+
# ==== Returns
|
42
|
+
# * <tt>Array</tt> - A normalized list of modules for the list of
|
43
|
+
# helpers provided.
|
44
|
+
def modules_for_liquid_filters(args)
|
45
|
+
args.flatten.map! do |arg|
|
46
|
+
case arg
|
47
|
+
when String, Symbol
|
48
|
+
file_name = "liquid_filters/#{arg.to_s.underscore}_filter"
|
49
|
+
require_dependency(file_name, "Missing liquid file %s.rb")
|
50
|
+
file_name.camelize.constantize
|
51
|
+
when Module
|
52
|
+
arg
|
53
|
+
else
|
54
|
+
raise ArgumentError, "filter must be a String, Symbol, or Module"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_liquid_template_filter(mod)
|
60
|
+
_liquid_filters.module_eval { include mod }
|
61
|
+
end
|
62
|
+
|
63
|
+
def default_liquid_module!
|
64
|
+
module_name = name.sub(/Controller$/, '')
|
65
|
+
module_path = module_name.underscore
|
66
|
+
liquid_filter module_path
|
67
|
+
rescue MissingSourceFile => e
|
68
|
+
raise e unless e.is_missing? "liquid_filters/#{module_path}_filter"
|
69
|
+
rescue NameError => e
|
70
|
+
raise e unless e.missing_name? "#{module_name}Filter"
|
71
|
+
end
|
72
|
+
|
73
|
+
end #end ClassMethods
|
74
|
+
|
75
|
+
end #end Controller
|
76
|
+
|
77
|
+
end #end LiquidRenderer
|
78
|
+
|
79
|
+
|
80
|
+
#ActionController::Base.send(:include, LiquidRenderer::Controller)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module LiquidRenderer
|
2
|
+
|
3
|
+
# http://royvandermeij.com/blog/2011/09/21/create-a-liquid-handler-for-rails-3-dot-1/
|
4
|
+
class Renderer
|
5
|
+
|
6
|
+
def initialize(view)
|
7
|
+
@view = view
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.call(template)
|
11
|
+
"LiquidRenderer::Renderer.new(self).render(#{template.source.inspect}, local_assigns)"
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(template, local_assigns = {})
|
15
|
+
_set_default_content_type
|
16
|
+
assigns = _merge_assigns(local_assigns)
|
17
|
+
liquid = Liquid::Template.parse(template)
|
18
|
+
liquid.render(assigns, filters: _filters, registers: _registers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def compilable?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def _set_default_content_type
|
28
|
+
_controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
|
29
|
+
end
|
30
|
+
|
31
|
+
def _merge_assigns(local_assigns)
|
32
|
+
assigns = @view.assigns
|
33
|
+
assigns["content_for_layout"] = @view.content_for(:layout) if @view.content_for?(:layout)
|
34
|
+
assigns.merge!(local_assigns.stringify_keys)
|
35
|
+
end
|
36
|
+
|
37
|
+
def _controller
|
38
|
+
@view.controller
|
39
|
+
end
|
40
|
+
|
41
|
+
def _filters
|
42
|
+
if _controller.class.ancestors.include? Controller
|
43
|
+
_controller._liquid_filters
|
44
|
+
else
|
45
|
+
[]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def _registers
|
50
|
+
{action_view: @view, controller: _controller}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
ActionView::Template.register_template_handler :liquid, LiquidRenderer::Renderer
|
56
|
+
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: liquid_renderer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Ra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: liquid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.6.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.6.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.17
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.17
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.17
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.17
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: capybara
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.4.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.4.0
|
97
|
+
description: LiquidRenderer adds liquid renderer and option to include liquid filters
|
98
|
+
like Rails helpers.
|
99
|
+
email: rodrigorcomp@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/liquid_renderer/controller.rb
|
105
|
+
- lib/liquid_renderer/renderer.rb
|
106
|
+
- lib/liquid_renderer/version.rb
|
107
|
+
- lib/liquid_renderer.rb
|
108
|
+
- MIT-LICENSE
|
109
|
+
- Rakefile
|
110
|
+
- Gemfile
|
111
|
+
- README.md
|
112
|
+
homepage: https://github.com/imaboldcompany/liquid_renderer
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.9.3p125
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.1.10
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: LiquidRenderer adds liquid renderer and option to include liquid filters
|
136
|
+
like Rails helpers.
|
137
|
+
test_files: []
|