dry_haml_handlebars 0.0.6 → 0.0.7
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.
- data/lib/dry_haml_handlebars/controller_helpers/action_controller.rb +81 -0
- data/lib/dry_haml_handlebars/version.rb +1 -1
- data/lib/dry_haml_handlebars/view_helpers/action_view.rb +46 -0
- data/lib/dry_haml_handlebars.rb +14 -5
- metadata +3 -4
- data/lib/action_controller/base.rb +0 -80
- data/lib/action_view/base.rb +0 -31
- data/lib/action_view/helpers/capture_helper.rb +0 -22
@@ -0,0 +1,81 @@
|
|
1
|
+
module DryHamlHandlebars
|
2
|
+
module ControllerHelpers
|
3
|
+
module ActionController
|
4
|
+
|
5
|
+
def render_extra_content_for(*args)
|
6
|
+
options = args.extract_options!
|
7
|
+
args.each do |identifier|
|
8
|
+
name, path = get_content_for_name_and_path(identifier, options)
|
9
|
+
DryHamlHandlebars.content_cache.add_item(name, path)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def get_content_for_name_and_path(identifier, options)
|
17
|
+
|
18
|
+
case identifier
|
19
|
+
when Symbol
|
20
|
+
|
21
|
+
name = identifier
|
22
|
+
|
23
|
+
possible_folders = [
|
24
|
+
Rails.root.join( *%w[app views] << params[:controller] ).to_s,
|
25
|
+
Rails.root.join( *%w[app views application] ).to_s
|
26
|
+
]
|
27
|
+
|
28
|
+
if folders = options[:prepend_search_folders]
|
29
|
+
possible_folders = folders + possible_folders
|
30
|
+
end
|
31
|
+
|
32
|
+
if folders = options[:append_search_folders]
|
33
|
+
possible_folders += folders
|
34
|
+
end
|
35
|
+
|
36
|
+
possible_filenames = [
|
37
|
+
"#{params[:action]}_#{name}.html.haml",
|
38
|
+
"#{name}.html.haml",
|
39
|
+
"#{params[:action]}_content_for_#{name}.html.haml",
|
40
|
+
"content_for_#{name}.html.haml"
|
41
|
+
]
|
42
|
+
|
43
|
+
possible_paths = []
|
44
|
+
|
45
|
+
possible_folders.each do |folder|
|
46
|
+
possible_filenames.each do |fname|
|
47
|
+
possible_paths << File.join( folder, fname )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
path = possible_paths.find { |p| File.exist?(p) }
|
52
|
+
raise "couldn't find any of the following expected files:\n#{possible_paths.join("\n")}" if path.nil?
|
53
|
+
|
54
|
+
when Array
|
55
|
+
|
56
|
+
path = Rails.root.join( *%w[app views] << "#{identifier.last}.html.haml" ).to_s
|
57
|
+
name = identifier.first.to_sym
|
58
|
+
|
59
|
+
when String
|
60
|
+
|
61
|
+
path = Rails.root.join( *%w[app views] << "#{identifier}.html.haml" ).to_s
|
62
|
+
name_match = identifier.match(/.*content_for_(?<name>\w*)/)
|
63
|
+
if name_match
|
64
|
+
name = name_match[:name].to_sym
|
65
|
+
else
|
66
|
+
name = identifier
|
67
|
+
end
|
68
|
+
|
69
|
+
else
|
70
|
+
raise ArgumentError, "expected identifier to be a Array, Symbol or String, but got #{identifier}"
|
71
|
+
end
|
72
|
+
|
73
|
+
raise "the file #{path} does not exist" unless File.exist?(path)
|
74
|
+
|
75
|
+
return name, path
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module DryHamlHandlebars
|
2
|
+
module ViewHelpers
|
3
|
+
module ActionView
|
4
|
+
|
5
|
+
# WARNING: content_for is ignored in caches. So you shouldn't use it
|
6
|
+
# for elements that will be fragment cached.
|
7
|
+
def handlebars_content_for(name, content = nil, flush = false)
|
8
|
+
|
9
|
+
if content
|
10
|
+
flush ? @view_flow.set(name, content) : @view_flow.append(name, content)
|
11
|
+
nil
|
12
|
+
else
|
13
|
+
@view_flow.get(name)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def handlebars_render(*args, &block)
|
19
|
+
|
20
|
+
#we simply wrap render so that we can detect that 'handlebars_render' was the calling function
|
21
|
+
#we do this by adding a local variable :handlebars_partial => true
|
22
|
+
|
23
|
+
if args.first.is_a?(Hash)
|
24
|
+
|
25
|
+
options = args.first
|
26
|
+
options[:locals] ||= {}
|
27
|
+
options[:locals].merge!(:__handlebars_partial => true)
|
28
|
+
|
29
|
+
elsif args.last.is_a?(Hash)
|
30
|
+
|
31
|
+
locals = args.last
|
32
|
+
locals[:__handlebars_partial] = true
|
33
|
+
|
34
|
+
else
|
35
|
+
|
36
|
+
args << {:__handlebars_partial => true}
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
render(*args, &block)
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/dry_haml_handlebars.rb
CHANGED
@@ -7,11 +7,6 @@ require "dry_haml_handlebars/register"
|
|
7
7
|
require "haml-rails"
|
8
8
|
require "rabl"
|
9
9
|
require "gon"
|
10
|
-
require 'action_view'
|
11
|
-
require 'action_controller'
|
12
|
-
require_relative "action_view/base"
|
13
|
-
require_relative "action_view/helpers/capture_helper"
|
14
|
-
require_relative "action_controller/base"
|
15
10
|
|
16
11
|
module DryHamlHandlebars
|
17
12
|
|
@@ -28,6 +23,20 @@ module DryHamlHandlebars
|
|
28
23
|
DryHamlHandlebars.prepare_handlebars
|
29
24
|
end
|
30
25
|
|
26
|
+
initializer "dry_haml_handlebars.configure" do |app|
|
27
|
+
|
28
|
+
ActiveSupport.on_load :action_view do
|
29
|
+
require 'dry_haml_handlebars/view_helpers/action_view'
|
30
|
+
include DryHamlHandlebars::ViewHelpers::ActionView
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveSupport.on_load :action_controller do
|
34
|
+
require 'dry_haml_handlebars/controller_helpers/action_controller'
|
35
|
+
include DryHamlHandlebars::ControllerHelpers::ActionController
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
31
40
|
end
|
32
41
|
|
33
42
|
class ContentCache
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dry_haml_handlebars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jonathan Chambers
|
@@ -96,13 +96,12 @@ files:
|
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
98
|
- dry_haml_handlebars.gemspec
|
99
|
-
- lib/action_controller/base.rb
|
100
|
-
- lib/action_view/base.rb
|
101
|
-
- lib/action_view/helpers/capture_helper.rb
|
102
99
|
- lib/dry_haml_handlebars.rb
|
100
|
+
- lib/dry_haml_handlebars/controller_helpers/action_controller.rb
|
103
101
|
- lib/dry_haml_handlebars/handler.rb
|
104
102
|
- lib/dry_haml_handlebars/register.rb
|
105
103
|
- lib/dry_haml_handlebars/version.rb
|
104
|
+
- lib/dry_haml_handlebars/view_helpers/action_view.rb
|
106
105
|
- vendor/assets/javascripts/underscore.js
|
107
106
|
homepage: https://github.com/jmchambers/dry_haml_handlebars
|
108
107
|
licenses:
|
@@ -1,80 +0,0 @@
|
|
1
|
-
module ActionController
|
2
|
-
class Base
|
3
|
-
|
4
|
-
def render_extra_content_for(*args)
|
5
|
-
options = args.extract_options!
|
6
|
-
args.each do |identifier|
|
7
|
-
name, path = get_content_for_name_and_path(identifier, options)
|
8
|
-
DryHamlHandlebars.content_cache.add_item(name, path)
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def get_content_for_name_and_path(identifier, options)
|
16
|
-
|
17
|
-
case identifier
|
18
|
-
when Symbol
|
19
|
-
|
20
|
-
name = identifier
|
21
|
-
|
22
|
-
possible_folders = [
|
23
|
-
Rails.root.join( *%w[app views] << params[:controller] ).to_s,
|
24
|
-
Rails.root.join( *%w[app views application] ).to_s
|
25
|
-
]
|
26
|
-
|
27
|
-
if folders = options[:prepend_search_folders]
|
28
|
-
possible_folders = folders + possible_folders
|
29
|
-
end
|
30
|
-
|
31
|
-
if folders = options[:append_search_folders]
|
32
|
-
possible_folders += folders
|
33
|
-
end
|
34
|
-
|
35
|
-
possible_filenames = [
|
36
|
-
"#{params[:action]}_#{name}.html.haml",
|
37
|
-
"#{name}.html.haml",
|
38
|
-
"#{params[:action]}_content_for_#{name}.html.haml",
|
39
|
-
"content_for_#{name}.html.haml"
|
40
|
-
]
|
41
|
-
|
42
|
-
possible_paths = []
|
43
|
-
|
44
|
-
possible_folders.each do |folder|
|
45
|
-
possible_filenames.each do |fname|
|
46
|
-
possible_paths << File.join( folder, fname )
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
path = possible_paths.find { |p| File.exist?(p) }
|
51
|
-
raise "couldn't find any of the following expected files:\n#{possible_paths.join("\n")}" if path.nil?
|
52
|
-
|
53
|
-
when Array
|
54
|
-
|
55
|
-
path = Rails.root.join( *%w[app views] << "#{identifier.last}.html.haml" ).to_s
|
56
|
-
name = identifier.first.to_sym
|
57
|
-
|
58
|
-
when String
|
59
|
-
|
60
|
-
path = Rails.root.join( *%w[app views] << "#{identifier}.html.haml" ).to_s
|
61
|
-
name_match = identifier.match(/.*content_for_(?<name>\w*)/)
|
62
|
-
if name_match
|
63
|
-
name = name_match[:name].to_sym
|
64
|
-
else
|
65
|
-
name = identifier
|
66
|
-
end
|
67
|
-
|
68
|
-
else
|
69
|
-
raise ArgumentError, "expected identifier to be a Array, Symbol or String, but got #{identifier}"
|
70
|
-
end
|
71
|
-
|
72
|
-
raise "the file #{path} does not exist" unless File.exist?(path)
|
73
|
-
|
74
|
-
return name, path
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
data/lib/action_view/base.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module ActionView
|
2
|
-
class Base
|
3
|
-
|
4
|
-
def handlebars_render(*args, &block)
|
5
|
-
|
6
|
-
#we simply wrap render so that we can detect that 'handlebars_render' was the calling function
|
7
|
-
#we do this by adding a local variable :handlebars_partial => true
|
8
|
-
|
9
|
-
if args.first.is_a?(Hash)
|
10
|
-
|
11
|
-
options = args.first
|
12
|
-
options[:locals] ||= {}
|
13
|
-
options[:locals].merge!(:__handlebars_partial => true)
|
14
|
-
|
15
|
-
elsif args.last.is_a?(Hash)
|
16
|
-
|
17
|
-
locals = args.last
|
18
|
-
locals[:__handlebars_partial] = true
|
19
|
-
|
20
|
-
else
|
21
|
-
|
22
|
-
args << {:__handlebars_partial => true}
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
render(*args, &block)
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
include ActionView::Helpers
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
module Helpers
|
5
|
-
module CaptureHelper
|
6
|
-
|
7
|
-
# WARNING: content_for is ignored in caches. So you shouldn't use it
|
8
|
-
# for elements that will be fragment cached.
|
9
|
-
def handlebars_content_for(name, content = nil, flush = false)
|
10
|
-
|
11
|
-
if content
|
12
|
-
flush ? @view_flow.set(name, content) : @view_flow.append(name, content)
|
13
|
-
nil
|
14
|
-
else
|
15
|
-
@view_flow.get(name)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|