quintype-liquid 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quintype/liquid/file_system.rb +46 -48
- data/lib/quintype/liquid/liquid_template_caching_module.rb +21 -24
- data/lib/quintype/liquid/railtie.rb +13 -15
- data/lib/quintype/liquid/templates.rb +22 -24
- data/lib/quintype/liquid/version.rb +1 -1
- data/lib/quintype/liquid.rb +6 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac1ddb27ce800219d1d39260cd06a92629442dc1
|
4
|
+
data.tar.gz: 8fe24b80efbfa962c19508a054a470ca429672ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02e2676ae099f80c61a934366fe07e42974e031fd38f84be0492bb472221b1c49aa98dc11374edf954b9bb2f19fbe775f5e54d30c470de9bb90e36fe6437fde8
|
7
|
+
data.tar.gz: dcfeda8a97a130f77f3841ddd86c293148e88933184311c42ab975d0bf527118ddddf85dfb3d5f700effd5508ef5ea5692ebad44479b8d3837b692671a40c6d4
|
@@ -1,53 +1,51 @@
|
|
1
|
-
module Quintype
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
break if file
|
27
|
-
end
|
28
|
-
|
29
|
-
raise Liquid::FileSystemError, "No such template '#{template_path}'" unless file
|
30
|
-
|
31
|
-
file
|
32
|
-
end
|
33
|
-
|
34
|
-
def full_path(template_path)
|
35
|
-
raise Liquid::FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /\A[^.\/][a-zA-Z0-9_\.\/]+\z/
|
36
|
-
|
37
|
-
full_path = if template_path.include?('/'.freeze)
|
38
|
-
File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
|
39
|
-
else
|
40
|
-
File.join(root, @pattern % template_path)
|
41
|
-
end
|
42
|
-
|
43
|
-
raise Liquid::FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path) =~ /\A#{File.expand_path(root)}/
|
44
|
-
|
45
|
-
full_path
|
1
|
+
module Quintype::Liquid
|
2
|
+
class FileSystem < ::Liquid::LocalFileSystem
|
3
|
+
def caching_enabled?
|
4
|
+
Rails.env.production?
|
5
|
+
end
|
6
|
+
|
7
|
+
def read_file(path)
|
8
|
+
full_path = full_path(path)
|
9
|
+
File.read(full_path) if File.exists?(full_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def read_template_file(template_path, context)
|
13
|
+
controller = context.registers[:controller]
|
14
|
+
controller_path = controller.controller_path
|
15
|
+
formats = controller.formats.map { |format| '.' + format.to_s } + ['']
|
16
|
+
|
17
|
+
file = nil
|
18
|
+
|
19
|
+
formats.each do |format|
|
20
|
+
path = template_path.include?('/') ? template_path : "#{controller_path}/#{template_path}"
|
21
|
+
path = path + format
|
22
|
+
|
23
|
+
file = caching_enabled? ? Rails.cache.fetch(cache_path(path)) { read_file(path) } : read_file(path)
|
24
|
+
|
25
|
+
break if file
|
46
26
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
27
|
+
|
28
|
+
raise Liquid::FileSystemError, "No such template '#{template_path}'" unless file
|
29
|
+
|
30
|
+
file
|
31
|
+
end
|
32
|
+
|
33
|
+
def full_path(template_path)
|
34
|
+
raise Liquid::FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /\A[^.\/][a-zA-Z0-9_\.\/]+\z/
|
35
|
+
|
36
|
+
full_path = if template_path.include?('/'.freeze)
|
37
|
+
File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
|
38
|
+
else
|
39
|
+
File.join(root, @pattern % template_path)
|
50
40
|
end
|
41
|
+
|
42
|
+
raise Liquid::FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path) =~ /\A#{File.expand_path(root)}/
|
43
|
+
|
44
|
+
full_path
|
45
|
+
end
|
46
|
+
|
47
|
+
def cache_path(path)
|
48
|
+
"liquid:#{path}"
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
@@ -1,27 +1,24 @@
|
|
1
|
-
module Quintype
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
render_method = (::Rails.env.development? || ::Rails.env.test?) ? :render! : :render
|
23
|
-
liquid.send(render_method, assigns, filters: filters, registers: { view: @view, controller: @controller, helper: @helper }).html_safe
|
24
|
-
end
|
1
|
+
module Quintype::Liquid
|
2
|
+
module LiquidTemplateCachingModule
|
3
|
+
CACHED_TEMPLATES = Concurrent::Map.new do |m, template|
|
4
|
+
Rails.logger.info "Compiling Template"
|
5
|
+
m[template] = ::Liquid::Template.parse(template)
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(template, local_assigns = {})
|
9
|
+
@view.controller.headers['Content-Type'] ||= 'text/html; charset=utf-8'
|
10
|
+
|
11
|
+
assigns = if @controller.respond_to?(:liquid_assigns, true)
|
12
|
+
@controller.send(:liquid_assigns)
|
13
|
+
else
|
14
|
+
@view.assigns
|
15
|
+
end
|
16
|
+
assigns['content_for_layout'] = @view.content_for(:layout) if @view.content_for?(:layout)
|
17
|
+
assigns.merge!(local_assigns.stringify_keys)
|
18
|
+
|
19
|
+
liquid = LiquidTemplateCachingModule::CACHED_TEMPLATES[template]
|
20
|
+
render_method = (::Rails.env.development? || ::Rails.env.test?) ? :render! : :render
|
21
|
+
liquid.send(render_method, assigns, filters: filters, registers: { view: @view, controller: @controller, helper: @helper }).html_safe
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
@@ -1,19 +1,17 @@
|
|
1
|
-
module Quintype
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
1
|
+
module Quintype::Liquid
|
2
|
+
class Railtie < Rails::Engine
|
3
|
+
initializer "quintype-liquid.assets.precompile" do |app|
|
4
|
+
app.config.assets.paths << root.join("assets", "javascripts").to_s
|
5
|
+
app.config.assets.paths << root.join("vendor", "assets", "javascripts").to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer "quintype-liquid.liquid-file-system" do |app|
|
9
|
+
template_path = ::Rails.root.join('app/views')
|
10
|
+
::Liquid::Template.file_system = Quintype::Liquid::FileSystem.new(template_path)
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
initializer "quintype-liquid.fix-caching" do |app|
|
14
|
+
::Liquid::Rails::TemplateHandler.send(:prepend, Quintype::Liquid::LiquidTemplateCachingModule)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -1,28 +1,26 @@
|
|
1
|
-
module Quintype
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
acc
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def clean_path(path)
|
21
|
-
path
|
22
|
-
.sub(@root, '')
|
23
|
-
.sub('.liquid', '')
|
24
|
-
.sub(/^\//, '')
|
1
|
+
module Quintype::Liquid
|
2
|
+
class Templates
|
3
|
+
attr_reader :paths
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@root = Rails.root.join("app", "views").to_s
|
7
|
+
@paths = Dir.glob("#{@root}/**/*.liquid").sort
|
8
|
+
end
|
9
|
+
|
10
|
+
def templates
|
11
|
+
paths.reduce({}) do |acc, path|
|
12
|
+
acc[clean_path(path)] = IO.read path
|
13
|
+
acc
|
25
14
|
end
|
26
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def clean_path(path)
|
20
|
+
path
|
21
|
+
.sub(@root, '')
|
22
|
+
.sub('.liquid', '')
|
23
|
+
.sub(/^\//, '')
|
24
|
+
end
|
27
25
|
end
|
28
26
|
end
|
data/lib/quintype/liquid.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require "liquid-rails"
|
1
2
|
require "quintype/liquid/version"
|
2
|
-
require "quintype/liquid/templates"
|
3
|
-
require "quintype/liquid/liquid_template_caching_module"
|
4
|
-
require "quintype/liquid/file_system"
|
5
|
-
require "quintype/liquid/railtie"
|
6
3
|
|
7
4
|
module Quintype
|
8
5
|
module Liquid
|
6
|
+
autoload :Templates, "quintype/liquid/templates"
|
7
|
+
autoload :LiquidTemplateCachingModule, "quintype/liquid/liquid_template_caching_module"
|
8
|
+
autoload :FileSystem, "quintype/liquid/file_system"
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
require "quintype/liquid/railtie" if defined?(Rails)
|