express_templates 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/core_extensions/proc.rb +13 -1
- data/lib/express_templates/components/base.rb +30 -8
- data/lib/express_templates/components/capabilities/resourceful.rb +1 -0
- data/lib/express_templates/components/configurable.rb +10 -1
- data/lib/express_templates/components/forms/submit.rb +7 -8
- data/lib/express_templates/version.rb +1 -1
- data/test/core_extensions/proc_test.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e93820b0563b5a327dea57ec300ff2878641cb3
|
4
|
+
data.tar.gz: 5a5f7d0954ca6be289f8e0ba6de35e7b01c04988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03b9541ab3544bbbb721f1efd2b92adafdd1c68bb33626702b9623ebcb0e314cb21ecdd7fa205aa991b70a9c731c9583bb7d267c07f2989204cf4b2e494c58b6
|
7
|
+
data.tar.gz: 3e262ad21e99a696376ba705a33103c1bf375cd83e8bb8643b3052b41e44722df3a8c23e1e1341dd0eb343ef6284e83163c82420688c3e64a8dce8e0393b7136
|
data/lib/core_extensions/proc.rb
CHANGED
@@ -29,7 +29,8 @@ class Proc
|
|
29
29
|
tokens = Ripper.lex File.read(file)
|
30
30
|
tokens_on_line = tokens.select {|pos, lbl, str| pos[0].eql?(line_no) }
|
31
31
|
starting_token = tokens_on_line.detect do |pos, lbl, str|
|
32
|
-
TOKEN_PAIRS.keys.include?
|
32
|
+
TOKEN_PAIRS.keys.include?([lbl, str]) &&
|
33
|
+
_actually_starting_a_proc?(tokens, [pos, lbl, str])
|
33
34
|
end
|
34
35
|
starting_token_type = [starting_token[1], starting_token[2]]
|
35
36
|
ending_token_type = TOKEN_PAIRS[starting_token_type]
|
@@ -54,6 +55,17 @@ class Proc
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
58
|
+
def _actually_starting_a_proc?(tokens, tok)
|
59
|
+
return true if tokens.index(tok).eql?(0)
|
60
|
+
look_back = tokens.slice(0..tokens.index(tok)-1)
|
61
|
+
look_back.pop if look_back.last.try(:[], 1).eql? :on_sp
|
62
|
+
if [:on_tlambeg, :on_tlambda].include?(tok[1])
|
63
|
+
true
|
64
|
+
else
|
65
|
+
![:on_comma, :on_lparen, :on_label].include?(look_back.last.try(:[], 1))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
57
69
|
# Examines the source of a proc to extract the body by
|
58
70
|
# removing the outermost block delimiters and any surrounding.
|
59
71
|
# whitespace.
|
@@ -12,6 +12,9 @@ module ExpressTemplates
|
|
12
12
|
#
|
13
13
|
class Base < Arbre::Component
|
14
14
|
|
15
|
+
class_attribute :before_build_hooks
|
16
|
+
self.before_build_hooks = []
|
17
|
+
|
15
18
|
def self.builder_method_and_class(method_name, klass)
|
16
19
|
Arbre::Element::BuilderMethods.class_eval <<-EOF, __FILE__, __LINE__
|
17
20
|
def #{method_name}(*args, &block)
|
@@ -45,19 +48,21 @@ module ExpressTemplates
|
|
45
48
|
_default_attributes.merge!(attribs)
|
46
49
|
end
|
47
50
|
|
48
|
-
def self.before_build(proc_or_symbol = nil, &block)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def self.before_build(proc_or_symbol = nil, exclusive: false, &block)
|
52
|
+
hook = (proc_or_symbol || block)
|
53
|
+
unless hook.kind_of?(Symbol) or hook.respond_to?(:call)
|
54
|
+
raise "before_build requires symbol (method_name), proc or block"
|
55
|
+
end
|
56
|
+
if exclusive
|
57
|
+
self.before_build_hooks = [hook]
|
53
58
|
else
|
54
|
-
|
59
|
+
self.before_build_hooks += [hook]
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
63
|
def build(*args, &block)
|
59
64
|
_extract_class!(args)
|
60
|
-
|
65
|
+
_run_before_build_hooks
|
61
66
|
super(*args) {
|
62
67
|
_build_body(&block) if respond_to?(:_build_body)
|
63
68
|
}
|
@@ -68,7 +73,15 @@ module ExpressTemplates
|
|
68
73
|
end
|
69
74
|
|
70
75
|
def self.inherited(subclass)
|
71
|
-
builder_method_and_class subclass.
|
76
|
+
builder_method_and_class subclass.builder_method_name, subclass
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.builder_method_name
|
80
|
+
to_s.demodulize.underscore
|
81
|
+
end
|
82
|
+
|
83
|
+
def builder_method_name
|
84
|
+
self.class.builder_method_name
|
72
85
|
end
|
73
86
|
|
74
87
|
def self.descendants
|
@@ -82,6 +95,15 @@ module ExpressTemplates
|
|
82
95
|
|
83
96
|
|
84
97
|
private
|
98
|
+
def _run_before_build_hooks
|
99
|
+
before_build_hooks.each do |hook|
|
100
|
+
if hook.kind_of?(Symbol)
|
101
|
+
self.send(hook)
|
102
|
+
else
|
103
|
+
instance_exec &hook
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
85
107
|
def _extract_class!(args)
|
86
108
|
add_class args.last.delete(:class) if args.last.try(:kind_of?, Hash)
|
87
109
|
end
|
@@ -6,6 +6,7 @@ module ExpressTemplates
|
|
6
6
|
|
7
7
|
def self.included(base)
|
8
8
|
base.class_eval do
|
9
|
+
has_argument :id, "The name of the collection", type: :symbol, optional: false
|
9
10
|
has_option :collection, 'Provide an explicit collection as a resource.'
|
10
11
|
has_option :collection_path, 'Provide an explicit path for the collection resource.'
|
11
12
|
has_option :resource_class, 'Overrides namespaced resource_class for using resources from a different module or namespace.'
|
@@ -99,7 +99,13 @@ module ExpressTemplates
|
|
99
99
|
else
|
100
100
|
definition[:type] || []
|
101
101
|
end
|
102
|
-
valid_type_names.map
|
102
|
+
valid_type_names.map do |type_name|
|
103
|
+
if type_name.eql?(:boolean)
|
104
|
+
type_name
|
105
|
+
else
|
106
|
+
type_name.to_s.classify.constantize
|
107
|
+
end
|
108
|
+
end
|
103
109
|
end
|
104
110
|
|
105
111
|
def _is_valid?(value, definition)
|
@@ -108,6 +114,9 @@ module ExpressTemplates
|
|
108
114
|
true
|
109
115
|
elsif valid_types.include?(value.class)
|
110
116
|
true
|
117
|
+
elsif valid_types.include?(:boolean) &&
|
118
|
+
[1, 0, true, false].include?(value)
|
119
|
+
true
|
111
120
|
else
|
112
121
|
false
|
113
122
|
end
|
@@ -11,16 +11,15 @@ module ExpressTemplates
|
|
11
11
|
submit_tag(value, input_attributes)
|
12
12
|
}
|
13
13
|
|
14
|
-
before_build
|
15
|
-
|
16
|
-
|
17
|
-
super()
|
18
|
-
rescue
|
19
|
-
add_class(config[:wrapper_class])
|
20
|
-
remove_class('submit')
|
21
|
-
end
|
14
|
+
before_build(exclusive: true) {
|
15
|
+
add_class(config[:wrapper_class])
|
16
|
+
remove_class('submit')
|
22
17
|
}
|
23
18
|
|
19
|
+
def resource_name
|
20
|
+
parent_form ? super : nil
|
21
|
+
end
|
22
|
+
|
24
23
|
def value
|
25
24
|
config[:value]
|
26
25
|
end
|
@@ -68,7 +68,7 @@ class ProcTest < ActiveSupport::TestCase
|
|
68
68
|
assert_equal 'foo', Proc.from_source(src).call
|
69
69
|
end
|
70
70
|
|
71
|
-
test "
|
71
|
+
test "#source_body captures full body when parens around parameters not provided" do
|
72
72
|
block = return_block { something(:one, "two") }
|
73
73
|
assert_equal 'something(:one, "two")', block.source_body
|
74
74
|
block = return_block -> { something :one, "two" }
|
@@ -78,4 +78,13 @@ class ProcTest < ActiveSupport::TestCase
|
|
78
78
|
# assert_equal 'something :one, "two"', block.source_body
|
79
79
|
end
|
80
80
|
|
81
|
+
def return_proc_value(*args, options)
|
82
|
+
options.values.first.values.first
|
83
|
+
end
|
84
|
+
|
85
|
+
test "#source works when a proc is inside a hash literal" do
|
86
|
+
block = return_proc_value(:one, two: {a: -> {'proc_inside'}})
|
87
|
+
assert_equal "-> {'proc_inside'}", block.source
|
88
|
+
end
|
89
|
+
|
81
90
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: express_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Talcott Smith
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|