quintype-liquid 0.1.3 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a34fc3f84d0f305db9050e633109e09f68a42d61
4
- data.tar.gz: 535b4b74d57e0c15d5f5ff37f0820c4ce341124f
3
+ metadata.gz: ac1ddb27ce800219d1d39260cd06a92629442dc1
4
+ data.tar.gz: 8fe24b80efbfa962c19508a054a470ca429672ab
5
5
  SHA512:
6
- metadata.gz: c37b6ccb4222729a80af49002f44bf2e136dd59c2dd89899df5f249211e8600e15671e6d4ab5aab71f990f79efbd4f686d18e1e83ba1fd012b1f110664961393
7
- data.tar.gz: 3ea20bc1f7756a42251c4fee9b1fc315c6f4e95d246f80e025f2ba6f6714b9ec1250f2db22aaf3f48cc5cc80402e8da896f89b527f936db854c9d784d9d22482
6
+ metadata.gz: 02e2676ae099f80c61a934366fe07e42974e031fd38f84be0492bb472221b1c49aa98dc11374edf954b9bb2f19fbe775f5e54d30c470de9bb90e36fe6437fde8
7
+ data.tar.gz: dcfeda8a97a130f77f3841ddd86c293148e88933184311c42ab975d0bf527118ddddf85dfb3d5f700effd5508ef5ea5692ebad44479b8d3837b692671a40c6d4
@@ -1,53 +1,51 @@
1
- module Quintype
2
- module Liquid
3
- class FileSystem < ::Liquid::LocalFileSystem
4
- def caching_enabled?
5
- Rails.env.production?
6
- end
7
-
8
- def read_file(path)
9
- full_path = full_path(path)
10
- File.read(full_path) if File.exists?(full_path)
11
- end
12
-
13
- def read_template_file(template_path, context)
14
- controller = context.registers[:controller]
15
- controller_path = controller.controller_path
16
- formats = controller.formats.map { |format| '.' + format.to_s } + ['']
17
-
18
- file = nil
19
-
20
- formats.each do |format|
21
- path = template_path.include?('/') ? template_path : "#{controller_path}/#{template_path}"
22
- path = path + format
23
-
24
- file = caching_enabled? ? Rails.cache.fetch(cache_path(path)) { read_file(path) } : read_file(path)
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
- def cache_path(path)
49
- "liquid:#{path}"
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 Liquid
3
- module LiquidTemplateCachingModule
4
- CACHED_TEMPLATES = Concurrent::Map.new do |m, template|
5
- Rails.logger.info "Compiling Template"
6
- m[template] = ::Liquid::Template.parse(template)
7
- end
8
-
9
- def render(template, local_assigns = {})
10
- @view.controller.headers['Content-Type'] ||= 'text/html; charset=utf-8'
11
-
12
- assigns = if @controller.respond_to?(:liquid_assigns, true)
13
- @controller.send(:liquid_assigns)
14
- else
15
- @view.assigns
16
- end
17
- assigns['content_for_layout'] = @view.content_for(:layout) if @view.content_for?(:layout)
18
- assigns.merge!(local_assigns.stringify_keys)
19
-
20
-
21
- liquid = LiquidTemplateCachingModule::CACHED_TEMPLATES[template]
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
- module Liquid
3
- class Railtie < Rails::Engine
4
- initializer "quintype-liquid.assets.precompile" do |app|
5
- app.config.assets.paths << root.join("assets", "javascripts").to_s
6
- app.config.assets.paths << root.join("vendor", "assets", "javascripts").to_s
7
- end
8
-
9
- initializer "quintype-liquid.liquid-file-system" do |app|
10
- template_path = ::Rails.root.join('app/views')
11
- ::Liquid::Template.file_system = Quintype::Liquid::FileSystem.new(template_path)
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
- initializer "quintype-liquid.fix-caching" do |app|
15
- ::Liquid::Rails::TemplateHandler.send(:prepend, Quintype::Liquid::LiquidTemplateCachingModule) unless Rails.env.development?
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
- module Liquid
3
- class Templates
4
- attr_reader :paths
5
-
6
- def initialize
7
- @root = Rails.root.join("app", "views").to_s
8
- @paths = Dir.glob("#{@root}/**/*.liquid").sort
9
- end
10
-
11
- def templates
12
- paths.reduce({}) do |acc, path|
13
- acc[clean_path(path)] = IO.read path
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
@@ -1,5 +1,5 @@
1
1
  module Quintype
2
2
  module Liquid
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quintype-liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tejas Dinkar