express_admin 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/express_admin.js +2 -0
- data/app/assets/javascripts/express_admin/admin.js +2 -0
- data/app/assets/stylesheets/express_admin.css +0 -5
- data/app/assets/stylesheets/express_admin/components/_definition.sass +8 -0
- data/app/assets/stylesheets/express_admin/components/_pane.sass +2 -2
- data/app/assets/stylesheets/express_admin/components/_sub_menu.sass +2 -2
- data/app/assets/stylesheets/express_admin/components/_widget_box.sass +4 -4
- data/app/assets/stylesheets/express_admin/globals/_foundation_overrides.sass +2 -1
- data/app/assets/stylesheets/express_admin/globals/_mixins.sass +0 -2
- data/app/assets/stylesheets/express_admin/plugins/_select2.sass +475 -68
- data/app/assets/stylesheets/express_admin/plugins/_tinymce.sass +2 -0
- data/app/assets/stylesheets/express_admin/screen.sass +6 -1
- data/app/assets/stylesheets/express_admin/sections/_header.sass +1 -0
- data/app/assets/stylesheets/express_admin/sections/_main_content.sass +6 -2
- data/app/assets/stylesheets/express_admin/sections/_main_region.sass +10 -7
- data/app/assets/stylesheets/express_admin/sections/_page_body.sass +6 -3
- data/app/assets/stylesheets/express_admin/sections/_page_sidebar.sass +6 -2
- data/app/assets/stylesheets/express_admin/sections/_sidebar_region.sass +4 -3
- data/app/assets/stylesheets/express_admin/shared/_buttons.sass +0 -1
- data/app/assets/stylesheets/express_admin/shared/_forms.sass +14 -2
- data/app/assets/stylesheets/express_admin/shared/_trees.sass +7 -3
- data/app/assets/stylesheets/ionicons/{ionicons.css.sass → ionicons.sass} +0 -0
- data/app/components/express_admin/addon_sidebar_component.rb +23 -34
- data/app/components/express_admin/definition_list.rb +38 -0
- data/app/components/express_admin/definition_table.rb +51 -0
- data/app/components/express_admin/flash_message_component.rb +5 -11
- data/app/components/express_admin/layout_component.rb +2 -9
- data/app/components/express_admin/main_region.rb +4 -4
- data/app/components/express_admin/mega_menu_component.rb +40 -34
- data/app/components/express_admin/page_header_component.rb +8 -18
- data/app/components/express_admin/pane.rb +13 -10
- data/app/components/express_admin/setting_form.rb +23 -20
- data/app/components/express_admin/sidebar_region.rb +6 -4
- data/app/components/express_admin/smart_form.rb +21 -18
- data/app/components/express_admin/smart_table.rb +44 -40
- data/app/components/express_admin/widget_box.rb +8 -8
- data/app/helpers/express_admin/admin_helper.rb +1 -1
- data/app/views/devise/sessions/new.html.et +63 -0
- data/app/views/layouts/express_admin/admin.html.et +8 -9
- data/app/views/shared/express_admin/_navigation_bar.html.et +6 -5
- data/config/tinymce.yml +29 -0
- data/lib/core_extensions/string_promptify.rb +9 -0
- data/lib/express_admin.rb +1 -0
- data/lib/express_admin/engine.rb +11 -9
- data/lib/express_admin/version.rb +1 -1
- data/lib/generators/express_admin/install/install_generator.rb +7 -0
- data/lib/generators/express_admin/install/templates/views/devise/sessions/new.html.et +1 -0
- data/test/dummy/app/views/demo/sign_in.html.et +6 -6
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +11361 -0
- data/test/dummy/test/components/smart_form_test.rb +57 -34
- data/test/dummy/test/components/smart_table_test.rb +35 -35
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/1EoyfDwFVtgMAOjo7HPkor8TQbVaioOFx9hildx_DTQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/4OPIkynisipUm8vKo57HUhBMWFSHBno_IH6OdpK29IA.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/4hK1AdPGHbXGkebvk-nSvhxtCdOSlMYNWvA43CvQKhI.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/6c0H20s6oHf45XogeDELaojxa0PX1NmirTTWV1ClcRw.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/9QvwPXfTSVmgQX6tdK9GuCn0--MZ8Z8eJJbHpUEq1p8.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/BoKdGhgi5NHfGTc42p9nltpEIYj_BBUxVdv7YhpBmmA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/GJGMlSyTg1AvPCV_6PaLOTVEKbHeVKY1jhCoaKuRlxM.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/H0aD5KRj-4fhORkqWcWZfKPOQfu_ggvt4OmYOl4S5mw.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/IBLgVNsKBbJxN8NQnh6zTc3bC_OG-8BhtA3xCNDV6ks.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Po8q4NrWy9Kymnz_HbOk-WbdGY_KuuXc6urGogTHe7U.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/V1aP9G-CVtOLR5PTnHleid8WC9TSfFAT1DzAygp_5CQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/WhePtBvZPmF1Jhdcc4glsjhxBJQo9Qw0CDgy_F8lClY.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/dVokuKbK8HbOtvPIksKGBAYE8x44l372dQ0gEISqbdo.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/oN1zSGeSEz4KhkAuUF_yFDsCVPkulfFjomEAjFzGdPc.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/qIeSoker4TjM7JYRQTOjgRd4nN0WeHnNY1GMK7Zpe8M.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/tTFLM1bjKSeg4nyH7GWbTY6JVvuYhNKFFvsOMS9h8O0.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/tzX-HHF4F70o-aSB9Z_duoPxFGDv3auYnrpko9SYafU.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/vMbWbI1SO5bEaiu2pRvV8NDmms_j5flYoRvCSJavhdU.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/ypZCDLo54Pz2ZoUxrxSEUjT5FYMAq8Ozp8OTOYDRdAE.cache +0 -0
- data/test/fixtures/categories.yml +8 -0
- data/test/test_helper.rb +34 -0
- data/vendor/gems/express_templates/CHANGELOG.md +12 -0
- data/vendor/gems/express_templates/Gemfile.lock +4 -1
- data/vendor/gems/express_templates/README.md +22 -41
- data/vendor/gems/express_templates/express_templates.gemspec +1 -0
- data/vendor/gems/express_templates/lib/arbre/patches.rb +50 -0
- data/vendor/gems/express_templates/lib/core_extensions/proc.rb +1 -0
- data/vendor/gems/express_templates/lib/express_templates.rb +2 -3
- data/vendor/gems/express_templates/lib/express_templates/compiler.rb +2 -7
- data/vendor/gems/express_templates/lib/express_templates/components.rb +1 -9
- data/vendor/gems/express_templates/lib/express_templates/components/base.rb +33 -37
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb +30 -18
- data/vendor/gems/express_templates/lib/express_templates/components/configurable.rb +41 -0
- data/vendor/gems/express_templates/lib/express_templates/components/form_rails_support.rb +5 -6
- data/vendor/gems/express_templates/lib/express_templates/components/forms.rb +0 -1
- data/vendor/gems/express_templates/lib/express_templates/components/forms/basic_fields.rb +3 -6
- data/vendor/gems/express_templates/lib/express_templates/components/forms/checkbox.rb +1 -1
- data/vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb +15 -25
- data/vendor/gems/express_templates/lib/express_templates/components/forms/form_component.rb +20 -11
- data/vendor/gems/express_templates/lib/express_templates/components/forms/option_support.rb +2 -2
- data/vendor/gems/express_templates/lib/express_templates/components/forms/radio.rb +7 -8
- data/vendor/gems/express_templates/lib/express_templates/components/forms/select.rb +61 -37
- data/vendor/gems/express_templates/lib/express_templates/components/forms/select_collection.rb +2 -8
- data/vendor/gems/express_templates/lib/express_templates/components/forms/submit.rb +7 -6
- data/vendor/gems/express_templates/lib/express_templates/components/tree_for.rb +26 -42
- data/vendor/gems/express_templates/lib/express_templates/version.rb +1 -1
- data/vendor/gems/express_templates/test/components/base_test.rb +17 -15
- data/vendor/gems/express_templates/test/components/capabilities/resourceful_test.rb +3 -3
- data/vendor/gems/express_templates/test/components/configurable_test.rb +27 -21
- data/vendor/gems/express_templates/test/components/forms/basic_fields_test.rb +57 -17
- data/vendor/gems/express_templates/test/components/forms/checkbox_test.rb +16 -22
- data/vendor/gems/express_templates/test/components/forms/express_form_test.rb +23 -76
- data/vendor/gems/express_templates/test/components/forms/radio_test.rb +31 -27
- data/vendor/gems/express_templates/test/components/forms/select_test.rb +46 -71
- data/vendor/gems/express_templates/test/components/forms/submit_test.rb +10 -5
- data/vendor/gems/express_templates/test/components/tree_for_test.rb +24 -52
- data/vendor/gems/express_templates/test/dummy/app/views/hello/show.html.et +4 -3
- data/vendor/gems/express_templates/test/dummy/app/views/layouts/application.html.et +1 -1
- data/vendor/gems/express_templates/test/dummy/log/test.log +4296 -0
- data/vendor/gems/express_templates/test/express_templates_test.rb +5 -1
- data/vendor/gems/express_templates/test/handler_test.rb +19 -17
- data/vendor/gems/express_templates/test/performance_test.rb +11 -7
- data/vendor/gems/express_templates/test/test_helper.rb +162 -1
- metadata +58 -47
- data/app/assets/stylesheets/express_admin/components/_megadropdown.sass +0 -66
- data/vendor/gems/express_templates/diagrams/diagram.graffle +0 -2404
- data/vendor/gems/express_templates/diagrams/diagram_express_templates.png +0 -0
- data/vendor/gems/express_templates/diagrams/diagram_haml_erb.png +0 -0
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/adoptable.rb +0 -20
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/building.rb +0 -14
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/conditionality.rb +0 -54
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/configurable.rb +0 -90
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/iterating.rb +0 -75
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/parenting.rb +0 -72
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/rendering.rb +0 -30
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/templating.rb +0 -198
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/wrapping.rb +0 -84
- data/vendor/gems/express_templates/lib/express_templates/components/column.rb +0 -13
- data/vendor/gems/express_templates/lib/express_templates/components/container.rb +0 -7
- data/vendor/gems/express_templates/lib/express_templates/components/content_for.rb +0 -42
- data/vendor/gems/express_templates/lib/express_templates/components/for_each.rb +0 -30
- data/vendor/gems/express_templates/lib/express_templates/components/forms/form_support.rb +0 -13
- data/vendor/gems/express_templates/lib/express_templates/components/null_wrap.rb +0 -41
- data/vendor/gems/express_templates/lib/express_templates/components/row.rb +0 -28
- data/vendor/gems/express_templates/lib/express_templates/components/table_for.rb +0 -163
- data/vendor/gems/express_templates/lib/express_templates/components/unless_block.rb +0 -40
- data/vendor/gems/express_templates/lib/express_templates/expander.rb +0 -140
- data/vendor/gems/express_templates/lib/express_templates/macro.rb +0 -45
- data/vendor/gems/express_templates/lib/express_templates/markup.rb +0 -9
- data/vendor/gems/express_templates/lib/express_templates/markup/html_tag.rb +0 -62
- data/vendor/gems/express_templates/lib/express_templates/markup/tag.rb +0 -150
- data/vendor/gems/express_templates/lib/express_templates/markup/wrapper.rb +0 -94
- data/vendor/gems/express_templates/lib/express_templates/markup/yielder.rb +0 -21
- data/vendor/gems/express_templates/test/components/column_test.rb +0 -11
- data/vendor/gems/express_templates/test/components/conditionality_test.rb +0 -37
- data/vendor/gems/express_templates/test/components/container_test.rb +0 -66
- data/vendor/gems/express_templates/test/components/content_for_test.rb +0 -60
- data/vendor/gems/express_templates/test/components/iterating_test.rb +0 -127
- data/vendor/gems/express_templates/test/components/null_wrap_test.rb +0 -28
- data/vendor/gems/express_templates/test/components/row_test.rb +0 -16
- data/vendor/gems/express_templates/test/components/table_for_test.rb +0 -211
- data/vendor/gems/express_templates/test/expander_stack_test.rb +0 -41
- data/vendor/gems/express_templates/test/expander_test.rb +0 -99
- data/vendor/gems/express_templates/test/markup/tag_test.rb +0 -149
- data/vendor/gems/express_templates/test/markup/wrapper_test.rb +0 -42
- data/vendor/gems/express_templates/test/markup/yielder_test.rb +0 -9
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.add_dependency "activesupport", "~> 4.2" # strictly speaking we only depend on active support
|
21
21
|
s.add_dependency "parslet", "~> 1.6"
|
22
|
+
s.add_dependency "arbre"
|
22
23
|
s.add_development_dependency "rails", "~> 4.2"
|
23
24
|
s.add_development_dependency "pry", "~> 0"
|
24
25
|
s.add_development_dependency "erubis", "~> 2.7"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Arbre
|
2
|
+
class Context
|
3
|
+
def resource
|
4
|
+
helpers.resource
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Element
|
9
|
+
|
10
|
+
module BuilderMethods
|
11
|
+
|
12
|
+
# we do not want to check the arity of the
|
13
|
+
# block in express templates because components
|
14
|
+
# are expected to be able to contain other components or template code
|
15
|
+
# without use of a builder style syntax
|
16
|
+
def build_tag(klass, *args, &block)
|
17
|
+
tag = klass.new(arbre_context)
|
18
|
+
tag.parent = current_arbre_element
|
19
|
+
|
20
|
+
with_current_arbre_element tag do
|
21
|
+
tag.build(*args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
tag
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Implements the method lookup chain. When you call a method that
|
29
|
+
# doesn't exist, we:
|
30
|
+
#
|
31
|
+
# 1. Try to call the method on the current DOM context
|
32
|
+
# 2. Return an assigned variable of the same name
|
33
|
+
# 3. Call the method on the helper object
|
34
|
+
# 4. Call super
|
35
|
+
#
|
36
|
+
def method_missing(name, *args, &block)
|
37
|
+
if current_arbre_element.respond_to?(name)
|
38
|
+
current_arbre_element.send name, *args, &block
|
39
|
+
elsif assigns && assigns.has_key?(name)
|
40
|
+
assigns[name]
|
41
|
+
elsif helpers.respond_to?(name)
|
42
|
+
current_arbre_element.add_child helpers.send(name, *args, &block)
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -24,6 +24,7 @@ class Proc
|
|
24
24
|
def source
|
25
25
|
@source ||= begin
|
26
26
|
file, line_no = source_location
|
27
|
+
raise "no file provided by source_location: #{self}" if file.nil?
|
27
28
|
raise "no line number provided for source_location: #{self}" if line_no.nil?
|
28
29
|
tokens = Ripper.lex File.read(file)
|
29
30
|
tokens_on_line = tokens.select {|pos, lbl, str| pos[0].eql?(line_no) }
|
@@ -1,13 +1,12 @@
|
|
1
1
|
module ExpressTemplates
|
2
|
+
require 'arbre'
|
3
|
+
require 'arbre/patches'
|
2
4
|
require 'core_extensions/proc'
|
3
5
|
require 'core_extensions/string'
|
4
6
|
require 'express_templates/indenter'
|
5
|
-
require 'express_templates/macro'
|
6
|
-
require 'express_templates/markup'
|
7
7
|
require 'express_templates/components'
|
8
8
|
require 'express_templates/template/handler'
|
9
9
|
require 'express_templates/renderer'
|
10
|
-
require 'express_templates/expander'
|
11
10
|
require 'express_templates/compiler'
|
12
11
|
require 'express_templates/interpolator'
|
13
12
|
extend Renderer
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ostruct'
|
1
2
|
module ExpressTemplates
|
2
3
|
module Compiler
|
3
4
|
def compile(template_or_src=nil, &block)
|
@@ -12,13 +13,7 @@ module ExpressTemplates
|
|
12
13
|
|
13
14
|
template, src = _normalize(template_or_src)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
compiled = expander.expand(src, &block).map(&:compile)
|
18
|
-
|
19
|
-
return Interpolator.transform(compiled.join("+").gsub('"+"', '')).tap do |s|
|
20
|
-
puts("\n"+template.inspect+"\nSource:\n#{template.try(:source)}\nInterpolated:\n#{s}\n") if ENV['DEBUG'].eql?('true')
|
21
|
-
end
|
16
|
+
%Q[Arbre::Context.new(assigns.merge(template_virtual_path: @virtual_path), self) { #{src || block.source_body} }.to_s]
|
22
17
|
end
|
23
18
|
|
24
19
|
private
|
@@ -3,16 +3,8 @@ module ExpressTemplates
|
|
3
3
|
end
|
4
4
|
end
|
5
5
|
|
6
|
-
require 'express_templates/expander'
|
7
6
|
require 'express_templates/components/base'
|
8
|
-
require 'express_templates/components/
|
9
|
-
require 'express_templates/components/null_wrap'
|
10
|
-
require 'express_templates/components/for_each'
|
11
|
-
require 'express_templates/components/unless_block'
|
12
|
-
require 'express_templates/components/row'
|
13
|
-
require 'express_templates/components/column'
|
7
|
+
require 'express_templates/components/configurable'
|
14
8
|
require 'express_templates/components/form_rails_support'
|
15
|
-
require 'express_templates/components/content_for'
|
16
|
-
require 'express_templates/components/table_for'
|
17
9
|
require 'express_templates/components/tree_for'
|
18
10
|
require 'express_templates/components/forms'
|
@@ -5,50 +5,46 @@ module ExpressTemplates
|
|
5
5
|
# Components provide self-contained reusable view code meant to be shared
|
6
6
|
# within a project or across many projects through a library of components
|
7
7
|
#
|
8
|
-
# Components gain their functionality through inclusion of Capabilities.
|
9
|
-
#
|
10
|
-
# Most Components are descendents of Components::Base.
|
11
|
-
#
|
12
8
|
module Components
|
13
9
|
|
14
10
|
# Components::Base is the base class for ExpressTemplates view components.
|
15
11
|
#
|
16
|
-
# View components are available as macros in ExpressTemplates and may be
|
17
|
-
# used to encapsulate common view patterns, behavior and functionality in
|
18
|
-
# reusable classes that can be shared within and across projects.
|
19
|
-
#
|
20
|
-
# Components intended to provide a base framework for a library of reusable
|
21
|
-
# components to cut development time across a multitude of projects.
|
22
|
-
#
|
23
|
-
# Components gain their functionality through including Capabilities.
|
24
|
-
#
|
25
|
-
# Example capabilities include:
|
26
|
-
#
|
27
|
-
# * Managing related ExpressTemplate fragments
|
28
|
-
# * Compiling template fragments for evaluation in a View Context
|
29
|
-
# * Specifying rendering logic to be executed in the View Context
|
30
|
-
# * Potentially referencing external assets that may be required
|
31
|
-
# for the component to work.
|
32
12
|
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
include Capabilities::Templating
|
43
|
-
include Capabilities::Rendering
|
44
|
-
include Capabilities::Wrapping
|
45
|
-
include Capabilities::Iterating
|
46
|
-
|
47
|
-
def self.inherited(klass)
|
48
|
-
ExpressTemplates::Expander.register_macros_for klass
|
13
|
+
class Base < Arbre::Component
|
14
|
+
|
15
|
+
def self.builder_method_and_class(method_name, klass)
|
16
|
+
Arbre::Element::BuilderMethods.class_eval <<-EOF, __FILE__, __LINE__
|
17
|
+
def #{method_name}(*args, &block)
|
18
|
+
insert_tag ::#{klass.name}, *args, &block
|
19
|
+
end
|
20
|
+
EOF
|
21
|
+
# puts "added #{method_name} -> #{klass.name}"
|
49
22
|
end
|
50
23
|
|
51
|
-
|
24
|
+
def self.emits(proc = nil, &block)
|
25
|
+
define_method(:build, &(proc || block))
|
26
|
+
end
|
52
27
|
|
28
|
+
def build(*args, block)
|
29
|
+
raise "#build method must be overridden"
|
30
|
+
end
|
31
|
+
|
32
|
+
def resource
|
33
|
+
helpers.resource
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.inherited(subclass)
|
37
|
+
builder_method_and_class subclass.to_s.demodulize.underscore, subclass
|
38
|
+
end
|
39
|
+
|
40
|
+
def indent_level
|
41
|
+
parent_indent_level = parent.try(:indent_level) || 0
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
children.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
53
49
|
end
|
54
50
|
end
|
data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb
CHANGED
@@ -4,15 +4,15 @@ module ExpressTemplates
|
|
4
4
|
|
5
5
|
module Resourceful
|
6
6
|
def namespace
|
7
|
-
|
7
|
+
config[:namespace] || infer_namespace
|
8
8
|
end
|
9
9
|
|
10
10
|
def path_prefix
|
11
|
-
|
11
|
+
config[:path_prefix] || infer_path_prefix
|
12
12
|
end
|
13
13
|
|
14
14
|
def resource_class
|
15
|
-
resource_class =
|
15
|
+
resource_class = config[:resource_class] || _namespaced_resource_class
|
16
16
|
resource_class.constantize
|
17
17
|
end
|
18
18
|
|
@@ -26,10 +26,17 @@ module ExpressTemplates
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def template_virtual_path
|
30
|
+
begin
|
31
|
+
super
|
32
|
+
rescue
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
def infer_namespace
|
30
|
-
|
31
|
-
|
32
|
-
path_parts = expander.template.virtual_path.split('/')
|
38
|
+
if template_virtual_path
|
39
|
+
path_parts = template_virtual_path.split('/')
|
33
40
|
|
34
41
|
case
|
35
42
|
when path_parts.size == 4
|
@@ -50,9 +57,8 @@ module ExpressTemplates
|
|
50
57
|
end
|
51
58
|
|
52
59
|
def infer_path_prefix
|
53
|
-
|
54
|
-
|
55
|
-
path_parts = expander.template.virtual_path.split('/')
|
60
|
+
if template_virtual_path
|
61
|
+
path_parts = template_virtual_path.split('/')
|
56
62
|
|
57
63
|
case
|
58
64
|
when path_parts.size == 4
|
@@ -75,7 +81,7 @@ module ExpressTemplates
|
|
75
81
|
# TODO: this can now be inferred from the template.virtual_path
|
76
82
|
# if not supplied...
|
77
83
|
def resource_name
|
78
|
-
|
84
|
+
config[:id].to_s.singularize
|
79
85
|
end
|
80
86
|
|
81
87
|
def collection_member_name
|
@@ -91,14 +97,15 @@ module ExpressTemplates
|
|
91
97
|
end
|
92
98
|
|
93
99
|
def collection
|
94
|
-
|
100
|
+
config[:collection] || helpers.collection
|
95
101
|
end
|
96
102
|
|
97
103
|
def collection_path
|
98
|
-
if
|
99
|
-
|
104
|
+
if config[:collection_path]
|
105
|
+
config[:collection_path]
|
100
106
|
else
|
101
|
-
|
107
|
+
#super
|
108
|
+
helpers.instance_eval "#{collection_name_with_prefix}_path"
|
102
109
|
end
|
103
110
|
end
|
104
111
|
|
@@ -110,11 +117,16 @@ module ExpressTemplates
|
|
110
117
|
end
|
111
118
|
end
|
112
119
|
|
120
|
+
def resource_path_helper
|
121
|
+
"#{resource_name_with_path_prefix}_path"
|
122
|
+
end
|
123
|
+
|
113
124
|
def resource_path(ivar=false)
|
114
|
-
if
|
115
|
-
|
125
|
+
if config[:resource_path]
|
126
|
+
config[:resource_path]
|
116
127
|
else
|
117
|
-
|
128
|
+
# super
|
129
|
+
helpers.instance_eval("#{resource_path_helper}(#{ivar ? '@' : ''}#{resource_name})")
|
118
130
|
end
|
119
131
|
end
|
120
132
|
|
@@ -126,7 +138,7 @@ module ExpressTemplates
|
|
126
138
|
end
|
127
139
|
end
|
128
140
|
|
129
|
-
def
|
141
|
+
def resource_attributes
|
130
142
|
resource_class.columns
|
131
143
|
end
|
132
144
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ExpressTemplates
|
2
|
+
module Components
|
3
|
+
class Configurable < Base
|
4
|
+
|
5
|
+
def self.emits(proc = nil, &block)
|
6
|
+
define_method(:markup, &(proc || block))
|
7
|
+
end
|
8
|
+
|
9
|
+
def build(*args, &block)
|
10
|
+
_process_args!(args)
|
11
|
+
if method(:markup).arity > 0
|
12
|
+
markup(block)
|
13
|
+
else
|
14
|
+
markup(&block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
@config ||= {}
|
20
|
+
end
|
21
|
+
|
22
|
+
alias :my :config
|
23
|
+
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def _process_args!(args)
|
28
|
+
if args.first.kind_of?(Symbol)
|
29
|
+
config.merge!(id: args.shift)
|
30
|
+
attributes[:id] = config[:id]
|
31
|
+
end
|
32
|
+
args.each do |arg|
|
33
|
+
if arg.kind_of?(Hash)
|
34
|
+
config.merge!(arg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -5,16 +5,15 @@ module ExpressTemplates
|
|
5
5
|
# would be provided by Rails' form helpers.
|
6
6
|
#
|
7
7
|
# An optional method may be speficied. Defaults to 'post'.
|
8
|
-
class FormRailsSupport <
|
9
|
-
|
10
|
-
emits -> {
|
8
|
+
class FormRailsSupport < Configurable
|
9
|
+
emits -> (ctx) {
|
11
10
|
div(style: 'display:none') {
|
12
|
-
utf8_enforcer_tag
|
11
|
+
add_child helpers.utf8_enforcer_tag
|
13
12
|
# NOTE: This should be moved into the forms module and made a FormComponent
|
14
13
|
# to have access to the resource_name as this code assumes existence of
|
15
14
|
# a resource method which may not exist
|
16
|
-
method_tag(
|
17
|
-
token_tag
|
15
|
+
add_child helpers.send(:method_tag, (config[:id] || ((resource.persisted? ? :put : :post) rescue :post)))
|
16
|
+
helpers.send(:token_tag)
|
18
17
|
}
|
19
18
|
}
|
20
19
|
end
|
@@ -5,7 +5,6 @@ module ExpressTemplates
|
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
require 'express_templates/components/forms/form_support'
|
9
8
|
require 'express_templates/components/forms/express_form'
|
10
9
|
require 'express_templates/components/forms/form_component'
|
11
10
|
require 'express_templates/components/forms/option_support'
|
@@ -12,7 +12,7 @@ module ExpressTemplates
|
|
12
12
|
emits -> {
|
13
13
|
div(class: field_wrapper_class) {
|
14
14
|
label_tag(label_name, label_text)
|
15
|
-
#{type}_field resource_var, field_name.to_sym
|
15
|
+
#{type}_field resource_var, field_name.to_sym, html_options
|
16
16
|
}
|
17
17
|
}
|
18
18
|
end
|
@@ -35,19 +35,16 @@ RUBY
|
|
35
35
|
emits -> {
|
36
36
|
div(class: field_wrapper_class) {
|
37
37
|
label_tag(label_name, label_text)
|
38
|
-
text_area resource_var, field_name.to_sym
|
38
|
+
text_area resource_var, field_name.to_sym, html_options
|
39
39
|
}
|
40
40
|
}
|
41
41
|
end
|
42
42
|
|
43
43
|
class Hidden < FormComponent
|
44
44
|
emits -> {
|
45
|
-
hidden_field resource_var, field_name.to_sym
|
45
|
+
hidden_field resource_var, field_name.to_sym, html_options
|
46
46
|
}
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
53
|
-
|
@@ -1,55 +1,45 @@
|
|
1
1
|
module ExpressTemplates
|
2
2
|
module Components
|
3
3
|
module Forms
|
4
|
-
class ExpressForm <
|
5
|
-
include Capabilities::
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
emits -> {
|
11
|
-
form( form_args ) {
|
4
|
+
class ExpressForm < Configurable
|
5
|
+
include ExpressTemplates::Components::Capabilities::Resourceful
|
6
|
+
|
7
|
+
emits -> (block) {
|
8
|
+
form(form_tag_options ) {
|
12
9
|
form_rails_support form_method
|
13
|
-
|
10
|
+
block.call(self) if block
|
14
11
|
}
|
15
12
|
}
|
16
13
|
|
17
14
|
def form_id
|
18
|
-
"#{resource_name}_{
|
15
|
+
"#{resource_name}_#{resource.id}"
|
19
16
|
end
|
20
17
|
|
21
18
|
def form_method
|
22
|
-
|
19
|
+
config[:method].to_s.upcase || 'POST'
|
23
20
|
end
|
24
21
|
|
22
|
+
def form_action
|
23
|
+
config[:action] || (resource.try(:persisted?) ? resource_path(ivar: true) : collection_path)
|
24
|
+
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
# need to find a better way to do this: id/action can be overridden but method
|
29
|
-
# should always be :post IN THE FORM TAG
|
30
|
-
args = {id: form_id, action: form_action}.merge!(@config).merge!(method: :post)
|
26
|
+
def form_tag_options
|
27
|
+
args = {id: form_id, action: form_action}.merge!(config).merge!(method: 'POST')
|
31
28
|
|
32
29
|
if html_options = args.delete(:html_options)
|
33
30
|
args.merge!(html_options)
|
34
31
|
end
|
35
|
-
args[:method] = args[:method].to_s.upcase
|
36
32
|
args
|
37
33
|
end
|
38
34
|
|
39
35
|
def resource_name_for_path
|
40
|
-
|
36
|
+
config[:id].to_s
|
41
37
|
end
|
42
38
|
|
43
39
|
def resource_name
|
44
|
-
(
|
40
|
+
(config[:resource_name] || config[:id]).to_s
|
45
41
|
end
|
46
42
|
|
47
|
-
private
|
48
|
-
|
49
|
-
def _modifying_resource?
|
50
|
-
[:put, :patch].include? form_method
|
51
|
-
end
|
52
|
-
|
53
43
|
end
|
54
44
|
end
|
55
45
|
end
|