express_admin 1.4.4 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/app/assets/stylesheets/express_admin/shared/_forms.sass +15 -2
- data/app/components/express_admin/definition_list.rb +8 -5
- data/app/components/express_admin/smart_form.rb +2 -1
- data/app/components/express_admin/smart_table.rb +3 -6
- data/app/views/layouts/express_admin/external.html.et +1 -1
- data/app/views/shared/express_admin/_messages.html.et +1 -1
- data/config/initializers/tinymce-rails.rb +1 -0
- data/config/tinymce.yml +4 -2
- data/lib/express_admin/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/test/components/definition_list_test.rb +71 -0
- data/test/dummy/test/components/definition_table_test.rb +72 -0
- data/test/dummy/test/components/flash_messages_test.rb +35 -0
- data/test/dummy/test/components/icon_link_test.rb +77 -0
- data/test/dummy/test/components/icon_test.rb +31 -0
- data/test/dummy/test/components/mega_menu_test.rb +45 -0
- data/test/dummy/test/components/module_sidebar_test.rb +56 -0
- data/test/dummy/test/components/widget_box_test.rb +30 -0
- data/vendor/gems/express_templates/Gemfile.lock +1 -1
- data/vendor/gems/express_templates/README.md +1 -1
- data/vendor/gems/express_templates/express_templates-0.9.3.gem +0 -0
- data/vendor/gems/express_templates/express_templates-0.9.4.gem +0 -0
- data/vendor/gems/express_templates/lib/core_extensions/proc.rb +13 -1
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb +1 -0
- data/vendor/gems/express_templates/lib/express_templates/components/configurable.rb +10 -1
- data/vendor/gems/express_templates/lib/express_templates/components/forms/form_component.rb +2 -0
- data/vendor/gems/express_templates/lib/express_templates/components/tree_for.rb +1 -1
- data/vendor/gems/express_templates/lib/express_templates/template/handler.rb +17 -1
- data/vendor/gems/express_templates/lib/express_templates/version.rb +1 -1
- data/vendor/gems/express_templates/test/components/forms/basic_fields_test.rb +58 -0
- data/vendor/gems/express_templates/test/components/forms/submit_test.rb +4 -0
- data/vendor/gems/express_templates/test/components/tree_for_test.rb +1 -6
- data/vendor/gems/express_templates/test/core_extensions/proc_test.rb +10 -1
- data/vendor/gems/express_templates/test/dummy/log/test.log +4761 -0
- data/vendor/gems/express_templates/test/handler_test.rb +24 -0
- data/vendor/gems/express_templates/test/test_helper.rb +5 -5
- metadata +21 -3
- data/app/assets/stylesheets/express_admin/components/_modals.sass +0 -7
@@ -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
|
@@ -8,6 +8,8 @@ module ExpressTemplates
|
|
8
8
|
before_build -> {
|
9
9
|
set_attribute(:id, "#{resource_name}_#{field_name}_wrapper")
|
10
10
|
add_class(config[:wrapper_class])
|
11
|
+
add_class('error') if resource.respond_to?(:errors) &&
|
12
|
+
resource.errors.include?(field_name.to_sym)
|
11
13
|
}
|
12
14
|
|
13
15
|
has_option :wrapper_class, 'Override the class of the wrapping div of a form component', default: 'field-wrapper'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
1
3
|
module ExpressTemplates
|
2
4
|
module Template
|
3
5
|
class Handler
|
@@ -6,10 +8,24 @@ module ExpressTemplates
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def call(template)
|
11
|
+
# call ripper stuff method
|
12
|
+
|
13
|
+
warn_contains_logic("(#{ExpressTemplates.compile(template)}).html_safe") # pass the source code
|
9
14
|
# returns a string to be eval'd
|
10
15
|
"(#{ExpressTemplates.compile(template)}).html_safe"
|
11
16
|
end
|
12
17
|
|
18
|
+
def warn_contains_logic(compiled_template)
|
19
|
+
keywords = %w(if until unless case for do loop while) # array of conditional keywords
|
20
|
+
tokens = []
|
21
|
+
if Ripper.lex(compiled_template).select do |element| # since it outputs an array [[line, col], type, token]
|
22
|
+
element[1]==:on_kw # type must match ':on_kw' type (type is keyword)
|
23
|
+
end.each { |match| tokens.push(match) if keywords.include? match[2] } # check if token is in given /keyword/ array, then push to new array match
|
24
|
+
tokens.each do |first|
|
25
|
+
warn "PAGE TEMPLATE INCLUDES #{first[2]} STATEMENT AT LINE #{first[0][0]}: #{first}\n#{compiled_template}" # warn on first occurence of conditional logic
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
13
29
|
end
|
14
30
|
end
|
15
|
-
end
|
31
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'active_model'
|
2
3
|
|
3
4
|
class BasicFieldsTest < ActiveSupport::TestCase
|
4
5
|
|
@@ -89,4 +90,61 @@ class BasicFieldsTest < ActiveSupport::TestCase
|
|
89
90
|
assert_match /<input class="hidden form-field" value="ninja" type="hidden" name="foo\[bar\]" id="foo_bar"/, html
|
90
91
|
end
|
91
92
|
|
93
|
+
def resource_with_errors
|
94
|
+
mock_resource = resource
|
95
|
+
class << mock_resource
|
96
|
+
def errors
|
97
|
+
errors = ActiveModel::Errors.new(self)
|
98
|
+
errors.add(:name, "Can't be Foo")
|
99
|
+
errors
|
100
|
+
end
|
101
|
+
end
|
102
|
+
mock_resource
|
103
|
+
end
|
104
|
+
|
105
|
+
def has_error_class
|
106
|
+
/div[^>]*class="[^"]*error[^"]*"/
|
107
|
+
end
|
108
|
+
|
109
|
+
def has_error_class_on(field, html)
|
110
|
+
md = html.match(/(<div[^>]*id="[^"]*#{field}_wrapper[^"]*"[^>]*>)/)
|
111
|
+
assert md, "field has no wrapper"
|
112
|
+
return !!md[1].match(has_error_class)
|
113
|
+
end
|
114
|
+
|
115
|
+
test "adds error class if there are errors on a field with no input attributes" do
|
116
|
+
html_with_error = arbre(resource: resource_with_errors) {
|
117
|
+
express_form(:foo) {
|
118
|
+
text :name
|
119
|
+
text :body
|
120
|
+
}
|
121
|
+
}
|
122
|
+
assert resource_with_errors.errors.any?
|
123
|
+
assert assigns[:resource].errors.any?
|
124
|
+
assert has_error_class_on(:name, html_with_error), "name field has no error when expected"
|
125
|
+
refute has_error_class_on(:body, html_with_error), "body field has error class when it should not"
|
126
|
+
end
|
127
|
+
|
128
|
+
test "adds error class if there are errors on a field with no class set" do
|
129
|
+
html_with_error = arbre(resource: resource_with_errors) {
|
130
|
+
express_form(:foo) {
|
131
|
+
text :name, value: 'ninja'
|
132
|
+
}
|
133
|
+
}
|
134
|
+
assert resource_with_errors.errors.any?
|
135
|
+
assert assigns[:resource].errors.any?
|
136
|
+
assert_match has_error_class, html_with_error
|
137
|
+
end
|
138
|
+
|
139
|
+
test "adds error to class if there are errors on a field with existing class" do
|
140
|
+
html_with_error = arbre(resource: resource_with_errors) {
|
141
|
+
express_form(:foo) {
|
142
|
+
text :name, value: 'ninja', class: 'slug'
|
143
|
+
}
|
144
|
+
}
|
145
|
+
assert resource_with_errors.errors.any?
|
146
|
+
assert assigns[:resource].errors.any?
|
147
|
+
assert_match has_error_class, html_with_error
|
148
|
+
end
|
149
|
+
|
92
150
|
end
|
@@ -2,11 +2,6 @@ require 'test_helper'
|
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
4
|
class TreeForTest < ActiveSupport::TestCase
|
5
|
-
class Context
|
6
|
-
def initialize(roles)
|
7
|
-
@roles = roles
|
8
|
-
end
|
9
|
-
end
|
10
5
|
|
11
6
|
class Role
|
12
7
|
attr :name, :children
|
@@ -17,7 +12,7 @@ class TreeForTest < ActiveSupport::TestCase
|
|
17
12
|
end
|
18
13
|
|
19
14
|
def roles
|
20
|
-
[Role.new('SuperAdmin', children:
|
15
|
+
@roles ||= [Role.new('SuperAdmin', children:
|
21
16
|
[Role.new('Admin', children:
|
22
17
|
[Role.new('Publisher', children:
|
23
18
|
[Role.new('Author')]),
|
@@ -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
|