templet_rails 0.1.0
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 +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +1059 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/templet/controller/USAGE +13 -0
- data/lib/generators/templet/controller/controller_generator.rb +106 -0
- data/lib/generators/templet/core/USAGE +23 -0
- data/lib/generators/templet/core/core_generator.rb +128 -0
- data/lib/generators/templet/core_rspec/USAGE +16 -0
- data/lib/generators/templet/core_rspec/core_rspec_generator.rb +65 -0
- data/lib/generators/templet/destroy/USAGE +19 -0
- data/lib/generators/templet/destroy/destroy_generator.rb +126 -0
- data/lib/generators/templet/routes/USAGE +14 -0
- data/lib/generators/templet/routes/routes_generator.rb +64 -0
- data/lib/generators/templet/rspec/USAGE +10 -0
- data/lib/generators/templet/rspec/rspec_generator.rb +124 -0
- data/lib/generators/templet/scaffold/USAGE +22 -0
- data/lib/generators/templet/scaffold/scaffold_generator.rb +75 -0
- data/lib/generators/templet/shared/actions_option.rb +24 -0
- data/lib/generators/templet/shared/add_routes_option.rb +19 -0
- data/lib/generators/templet/shared/child_option.rb +23 -0
- data/lib/generators/templet/shared/comment_tests_option.rb +19 -0
- data/lib/generators/templet/shared/core_helpers.rb +48 -0
- data/lib/generators/templet/shared/grand_parent_option.rb +20 -0
- data/lib/generators/templet/shared/model_fields.rb +55 -0
- data/lib/generators/templet/shared/model_option.rb +25 -0
- data/lib/generators/templet/shared/parent_option.rb +20 -0
- data/lib/generators/templet/templates/controller.rb.erb +108 -0
- data/lib/generators/templet/templates/core/app/base_viewer.rb +7 -0
- data/lib/generators/templet/templates/core/app/link_sets/navbar.rb +12 -0
- data/lib/generators/templet/templates/core/app/panel/flash_messages.rb +33 -0
- data/lib/generators/templet/templates/core/app/panel/layout_base.rb +40 -0
- data/lib/generators/templet/templates/core/app/panel/layout_header.rb +22 -0
- data/lib/generators/templet/templates/core/app/panel/layout_header_sidebar.rb +18 -0
- data/lib/generators/templet/templates/core/app/panel/nav.rb +55 -0
- data/lib/generators/templet/templates/core/app/panel/nav_args_option.rb +30 -0
- data/lib/generators/templet/templates/core/app/panel/options_config.rb +19 -0
- data/lib/generators/templet/templates/core/app/panel/show_parents_option.rb +22 -0
- data/lib/generators/templet/templates/core/app/panel/sidebar_links_option.rb +24 -0
- data/lib/generators/templet/templates/core/controllers/.keep +0 -0
- data/lib/generators/templet/templates/core/controllers/json_rendering_helpers.rb +12 -0
- data/lib/generators/templet/templates/core/controllers/rendering_helpers.rb +53 -0
- data/lib/generators/templet/templates/core/controllers/viewer_call_string.rb +144 -0
- data/lib/generators/templet/templates/core/controllers/viewer_call_string_class.rb +65 -0
- data/lib/generators/templet/templates/core/controllers/viewer_responders.rb +121 -0
- data/lib/generators/templet/templates/core/helpers/app.rb +4 -0
- data/lib/generators/templet/templates/core/helpers/templet_helper.rb +10 -0
- data/lib/generators/templet/templates/core/spec/support/apis/api_helper.rb +13 -0
- data/lib/generators/templet/templates/core/spec/support/apis/shared_examples_a_json_controller.rb +196 -0
- data/lib/generators/templet/templates/core/spec/support/core/model_parent_helpers.rb +36 -0
- data/lib/generators/templet/templates/core/spec/support/core/rest_link_procs_assignments.rb +43 -0
- data/lib/generators/templet/templates/core/spec/support/core/rest_link_procs_helpers.rb +15 -0
- data/lib/generators/templet/templates/core/spec/support/viewer/partial_test_helpers.rb +32 -0
- data/lib/generators/templet/templates/core/spec/support/viewer/shared_examples_a_viewer.rb +105 -0
- data/lib/generators/templet/templates/core/spec/templet/forms/bs_form_errors_spec.rb +18 -0
- data/lib/generators/templet/templates/core/spec/templet/forms/bs_form_spec.rb +58 -0
- data/lib/generators/templet/templates/core/spec/templet/layout/html_rails_spec.rb +64 -0
- data/lib/generators/templet/templates/core/spec/templet/links/bs_link_set_collection_spec.rb +79 -0
- data/lib/generators/templet/templates/core/spec/templet/links/rest_link_procs_params_spec.rb +68 -0
- data/lib/generators/templet/templates/core/spec/templet/links/rest_link_procs_parents_spec.rb +78 -0
- data/lib/generators/templet/templates/core/spec/templet/links/rest_link_procs_spec.rb +140 -0
- data/lib/generators/templet/templates/core/templet/constants.rb +54 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form.rb +73 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form_errors.rb +38 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form_field.rb +114 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form_group.rb +115 -0
- data/lib/generators/templet/templates/core/templet/layouts/html_rails.rb +36 -0
- data/lib/generators/templet/templates/core/templet/links.rb +28 -0
- data/lib/generators/templet/templates/core/templet/links/bs_btn_class.rb +61 -0
- data/lib/generators/templet/templates/core/templet/links/bs_link_set_base.rb +168 -0
- data/lib/generators/templet/templates/core/templet/links/bs_link_set_collection.rb +21 -0
- data/lib/generators/templet/templates/core/templet/links/bs_link_set_navigation.rb +62 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_procs.rb +163 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_procs_parent.rb +39 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_procs_sets.rb +30 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_text.rb +102 -0
- data/lib/generators/templet/templates/core/templet/links/rest_path.rb +90 -0
- data/lib/generators/templet/templates/core/templet/mixins.rb +9 -0
- data/lib/generators/templet/templates/core/templet/mixins/bs.rb +11 -0
- data/lib/generators/templet/templates/core/templet/mixins/bs/grid.rb +53 -0
- data/lib/generators/templet/templates/core/templet/mixins/bs/lists.rb +77 -0
- data/lib/generators/templet/templates/core/templet/mixins/field_procs.rb +140 -0
- data/lib/generators/templet/templates/core/templet/mixins/html_presenters.rb +82 -0
- data/lib/generators/templet/templates/core/templet/require_all.rb +45 -0
- data/lib/generators/templet/templates/core/templet/utils/html_search_form.rb +53 -0
- data/lib/generators/templet/templates/core/templet/utils/link_set_factory.rb +46 -0
- data/lib/generators/templet/templates/core/templet/utils/link_set_factory_wrapper.rb +53 -0
- data/lib/generators/templet/templates/core/templet/utils/list_model_parents.rb +27 -0
- data/lib/generators/templet/templates/core/templet/utils/navbar_form.rb +26 -0
- data/lib/generators/templet/templates/core/templet/utils/selected_wrapper.rb +40 -0
- data/lib/generators/templet/templates/core/templet/viewer.rb +11 -0
- data/lib/generators/templet/templates/core/templet/viewer/meta_model.rb +66 -0
- data/lib/generators/templet/templates/core/templet/viewer/meta_model_defaults.rb +56 -0
- data/lib/generators/templet/templates/core/templet/viewer/presenters.rb +44 -0
- data/lib/generators/templet/templates/core/templet/viewer/rest_actions.rb +24 -0
- data/lib/generators/templet/templates/core/templet/viewer_base.rb +111 -0
- data/lib/generators/templet/templates/core/templet/viewer_rest.rb +144 -0
- data/lib/generators/templet/viewer/USAGE +10 -0
- data/lib/generators/templet/viewer/viewer_generator.rb +86 -0
- data/lib/templet_rails.rb +5 -0
- data/lib/templet_rails/version.rb +3 -0
- data/templet_rails.gemspec +36 -0
- metadata +178 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Mixins
|
4
|
+
# Helper methods for rendering HTML tables, forms and lists
|
5
|
+
module HtmlPresenters
|
6
|
+
include Constants
|
7
|
+
|
8
|
+
# Html table
|
9
|
+
|
10
|
+
# +controls+:: Is a Hash of field name by Proc which is passed a record
|
11
|
+
def html_table(renderer, controls, records, **options)
|
12
|
+
unless options.key? :html_class
|
13
|
+
options[:html_class] = default_table_class
|
14
|
+
end
|
15
|
+
|
16
|
+
Templet::Html::Table.new(renderer).(controls, records, **options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_table_class
|
20
|
+
BS_TABLE
|
21
|
+
end
|
22
|
+
|
23
|
+
# Renders the outside of an HTML form.
|
24
|
+
# Usually you feed it a block to specify the various fields.
|
25
|
+
def html_form(renderer, form_opts, **group_opts)
|
26
|
+
if not form_opts.key?(:remote) and respond_to?(:remote?) and remote?
|
27
|
+
form_opts[:remote] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
height = form_opts.delete(:height) || group_opts[:height]
|
31
|
+
group_opts[:height] = height
|
32
|
+
|
33
|
+
Forms::BsForm.new(renderer).(**form_opts) do |renderer|
|
34
|
+
field, group = Forms::BsForm.(renderer, model, **group_opts)
|
35
|
+
|
36
|
+
if block_given?
|
37
|
+
yield field, group
|
38
|
+
else
|
39
|
+
form_inputs(field, group) << field.submit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Html lists
|
45
|
+
|
46
|
+
# +controls+:: A Hash of field name by Proc which is paassed a model
|
47
|
+
def html_definition_list(renderer, controls, record=nil)
|
48
|
+
Templet::Html::DefinitionList.new(renderer)
|
49
|
+
.(controls, record, html_class: 'dl-horizontal')
|
50
|
+
end
|
51
|
+
|
52
|
+
# +items+ is an Array of (literal) list elements
|
53
|
+
def html_list(renderer, items, html_class: nil, item_class: nil)
|
54
|
+
html_class = get_list_class(html_class)
|
55
|
+
|
56
|
+
Templet::Html::List.new(renderer).(items, html_class: html_class,
|
57
|
+
item_class: item_class)
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_list_class(html_class)
|
61
|
+
case html_class
|
62
|
+
when nil, :default, :inline
|
63
|
+
default_list_class
|
64
|
+
when true, :stacked
|
65
|
+
stacked_list_class
|
66
|
+
when false, :none
|
67
|
+
else
|
68
|
+
html_class
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def default_list_class
|
73
|
+
BS_LIST_INLINE
|
74
|
+
end
|
75
|
+
|
76
|
+
def stacked_list_class
|
77
|
+
BS_LIST_UNSTYLED
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
# Requires the whole framework - in case the framework is placed outside of
|
3
|
+
# the Rails autoload paths, e.g. under the directory lib/
|
4
|
+
=begin
|
5
|
+
require 'templet'
|
6
|
+
#require 'templet/component'
|
7
|
+
#require 'templet/html'
|
8
|
+
|
9
|
+
require 'templet/viewer_base'
|
10
|
+
require 'templet/viewer_rest'
|
11
|
+
require 'templet/constants'
|
12
|
+
|
13
|
+
require 'templet/forms/bs_form_errors'
|
14
|
+
require 'templet/forms/bs_form_field'
|
15
|
+
require 'templet/forms/bs_form_group'
|
16
|
+
require 'templet/forms/bs_form'
|
17
|
+
|
18
|
+
require 'templet/links/rest_link_text'
|
19
|
+
require 'templet/links/bs_btn_class'
|
20
|
+
require 'templet/links/rest_link_procs_sets'
|
21
|
+
require 'templet/links/rest_link_procs_parent'
|
22
|
+
require 'templet/links/rest_link_procs'
|
23
|
+
require 'templet/links/bs_link_set_base'
|
24
|
+
require 'templet/links/bs_link_set_collection'
|
25
|
+
require 'templet/links/bs_link_set_navigation'
|
26
|
+
require 'templet/links/bs_btn_class'
|
27
|
+
require 'templet/links/rest_link_text'
|
28
|
+
|
29
|
+
require 'templet/mixins'
|
30
|
+
require 'templet/mixins/bs'
|
31
|
+
require 'templet/mixins/html_presenters'
|
32
|
+
require 'templet/mixins/bs/lists'
|
33
|
+
require 'templet/mixins/bs/grid'
|
34
|
+
|
35
|
+
require 'templet/utils/html_search_form'
|
36
|
+
require 'templet/utils/list_model_parents'
|
37
|
+
|
38
|
+
require 'templet/viewer'
|
39
|
+
require 'templet/viewer/presenters'
|
40
|
+
require 'templet/viewer/rest_actions'
|
41
|
+
require 'templet/viewer/meta_model_defaults'
|
42
|
+
require 'templet/viewer/meta_model'
|
43
|
+
require 'templet/viewer/rest_actions'
|
44
|
+
=end
|
45
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Utils
|
4
|
+
# Renders a form (inline) for string searches, primarily for index actions.
|
5
|
+
class HtmlSearchForm < Templet::Component::Partial
|
6
|
+
include Constants
|
7
|
+
|
8
|
+
include Mixins::Bs
|
9
|
+
|
10
|
+
def call(url, field_name: 'q', submit_text: 'Search',
|
11
|
+
label: nil, remote: false)
|
12
|
+
label ||= submit_text.underscore
|
13
|
+
|
14
|
+
super() do
|
15
|
+
Forms::BsForm.new(renderer).(**form_opts(url, remote)) do |renderer|
|
16
|
+
group = Forms::BsFormGroup.(renderer)
|
17
|
+
|
18
|
+
btn_class = "#{BS_BUTTON_SUBMIT_SEARCH} #{BS_BUTTON}-#{group.height}"
|
19
|
+
submit = button(submit_text, btn_class, type: 'submit')
|
20
|
+
|
21
|
+
[
|
22
|
+
group.(field_name, label_name: label) do |renderer, record_name|
|
23
|
+
renderer.call do
|
24
|
+
text_field record_name, field_name, value: params[field_name],
|
25
|
+
class: group.field_class
|
26
|
+
end
|
27
|
+
end,
|
28
|
+
submit
|
29
|
+
]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.call(renderer, model, parent=nil, scope: nil,
|
35
|
+
action: nil,
|
36
|
+
remote: nil)
|
37
|
+
rest_path = Links::RestPath.new(model, parent, scope: scope)
|
38
|
+
|
39
|
+
path = action ? rest_path.action(action) : rest_path.index
|
40
|
+
|
41
|
+
new(renderer).(path, remote: remote)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def form_opts(url, remote=nil)
|
47
|
+
{ url: url, inline: true, method: 'get' }.tap do |options|
|
48
|
+
options.merge!(remote: true) if remote
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Utils
|
4
|
+
# Creates lists of HTML links for REST actions
|
5
|
+
class LinkSetFactory < Struct.new(:renderer, :action, :klass, :options)
|
6
|
+
def call(**extra_options)
|
7
|
+
create extra_options
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def create(**extra_options)
|
13
|
+
get_class.new(*link_set_args(extra_options)).(action)
|
14
|
+
end
|
15
|
+
|
16
|
+
def link_set_args(**extra_options)
|
17
|
+
renderer.link_set_args_proc.(renderer, get_options(extra_options))
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_class
|
21
|
+
case klass
|
22
|
+
when Class
|
23
|
+
klass
|
24
|
+
when String
|
25
|
+
klass.constantize
|
26
|
+
when :navigation, :nav
|
27
|
+
Templet::Links::BsLinkSetNavigation
|
28
|
+
else
|
29
|
+
Templet::Links::BsLinkSetCollection
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_options(**extra_options)
|
34
|
+
{ html_class: %i(default md) }
|
35
|
+
.merge(options || {})
|
36
|
+
.merge(extra_options)
|
37
|
+
end
|
38
|
+
|
39
|
+
=begin
|
40
|
+
def class_name_defined?(class_name)
|
41
|
+
class_name.constantize rescue false
|
42
|
+
end
|
43
|
+
=end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Utils
|
4
|
+
# Creates HTML links for REST actions in Bootstrap containers
|
5
|
+
class LinkSetFactoryWrapper < LinkSetFactory
|
6
|
+
include Mixins::Bs::Lists
|
7
|
+
|
8
|
+
def call(type=nil, **options)
|
9
|
+
stacked = options.delete(:stacked) || false
|
10
|
+
|
11
|
+
wrap type, create(link_set_options(type).merge options), stacked: stacked
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def link_set_options(type)
|
17
|
+
case type
|
18
|
+
when :pills, :tabs
|
19
|
+
{ html_class: '', wrapper: nav_li_wrapper }
|
20
|
+
when :buttons, :toolbar
|
21
|
+
{ html_class: %i(default md) }
|
22
|
+
when :links
|
23
|
+
{ html_class: %i(link sm), selected: 'disabled' }
|
24
|
+
else
|
25
|
+
{ html_class: :item }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def wrap(type, links, stacked: false)
|
30
|
+
case type
|
31
|
+
when :pills
|
32
|
+
in_nav renderer, links.flatten, stacked: stacked
|
33
|
+
when :tabs
|
34
|
+
in_nav renderer, links.flatten, tabs: true, stacked: stacked
|
35
|
+
when :buttons
|
36
|
+
in_button_group renderer, links.flatten, stacked: stacked
|
37
|
+
when :toolbar
|
38
|
+
in_button_toolbar renderer, links, stacked: stacked
|
39
|
+
when :links
|
40
|
+
in_list_group_links renderer, links.flatten
|
41
|
+
else
|
42
|
+
in_list_group_buttons renderer, links.flatten
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def nav_li_wrapper
|
47
|
+
{ regular: '<li role="presentation">%s</li>',
|
48
|
+
selected: '<li role="presentation" class="active">%s</li>' }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Utils
|
4
|
+
# To list info on a model's parents, and optionally in HTML.
|
5
|
+
class ListModelParents
|
6
|
+
def call(model, parent_names, out=[])
|
7
|
+
if model
|
8
|
+
if parent_name = parent_names&.shift
|
9
|
+
parent = model.send(parent_name)
|
10
|
+
|
11
|
+
call(parent, parent_names, out)
|
12
|
+
end
|
13
|
+
|
14
|
+
out << [ model.model_name.to_s, model.to_s ]
|
15
|
+
end
|
16
|
+
|
17
|
+
out
|
18
|
+
end
|
19
|
+
|
20
|
+
def in_html(*args)
|
21
|
+
call(*args).map do |(name, value)|
|
22
|
+
"<b>#{name}</b>: <em class='small'>#{value[0, 25]}</em>"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Utils
|
4
|
+
# Renders a Bootstrap navbar form for string searches.
|
5
|
+
class NavbarForm < Templet::Component::Partial
|
6
|
+
include Constants
|
7
|
+
|
8
|
+
include Mixins::Bs
|
9
|
+
|
10
|
+
def call(url, field_name: 'q', submit_text: 'Search', remote: false)
|
11
|
+
super() do
|
12
|
+
form action: url, class: "navbar-form navbar-left", role: "search" do
|
13
|
+
div class: "form-group" do
|
14
|
+
[ input(name: field_name, type: "text", value: params[field_name],
|
15
|
+
class: "form-control", placeholder: "Name"),
|
16
|
+
button(submit_text, type: "submit", class: "btn btn-default") ]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Utils
|
4
|
+
# Wraps (in a tag) some given content according to a condition.
|
5
|
+
class SelectedWrapper
|
6
|
+
attr_accessor :wrapper, :selected_class
|
7
|
+
|
8
|
+
def initialize(wrapper, selected_class)
|
9
|
+
self.selected_class = selected_class
|
10
|
+
|
11
|
+
self.wrapper = get_wrapper wrapper
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(content, is_selected=false)
|
15
|
+
if wrapper
|
16
|
+
wrapper[is_selected ? :selected : :regular] % content
|
17
|
+
else
|
18
|
+
content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_wrapper(wrapper)
|
25
|
+
if wrapper
|
26
|
+
if Hash === wrapper
|
27
|
+
wrapper
|
28
|
+
else
|
29
|
+
{ regular: tag(wrapper),
|
30
|
+
selected: tag(wrapper, " class='#{selected_class}'") }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def tag(name, atts_string='')
|
36
|
+
"<#{name}#{atts_string}>%s</#{name}>"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Viewer
|
4
|
+
# Model introspection
|
5
|
+
class MetaModel < Struct.new(:model_proto)
|
6
|
+
def names
|
7
|
+
#dictionary {|column| column.name.to_sym }
|
8
|
+
field_info.map(&:name).map(&:to_sym)
|
9
|
+
end
|
10
|
+
|
11
|
+
def listing_names
|
12
|
+
names.reject do |name|
|
13
|
+
%i(id created_at updated_at).include?(name) or name.to_s =~ /_id$/
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def input_names
|
18
|
+
listing_names
|
19
|
+
end
|
20
|
+
|
21
|
+
def type(name)
|
22
|
+
(@types ||= types)[name]
|
23
|
+
end
|
24
|
+
|
25
|
+
def types
|
26
|
+
dictionary &:type
|
27
|
+
end
|
28
|
+
|
29
|
+
def input(name)
|
30
|
+
type = type(name)
|
31
|
+
|
32
|
+
inputs[type] or type
|
33
|
+
end
|
34
|
+
|
35
|
+
def inputs
|
36
|
+
{ string: :text, text: :text_area, boolean: :check_box, integer: :text }
|
37
|
+
end
|
38
|
+
|
39
|
+
def field_info
|
40
|
+
model_class.content_columns
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def dictionary
|
46
|
+
field_info.inject Hash.new do |acc, column|
|
47
|
+
acc[column.name.to_sym] = yield column
|
48
|
+
|
49
|
+
acc
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def model_class
|
54
|
+
case model_proto
|
55
|
+
when Class
|
56
|
+
model_proto
|
57
|
+
when String, Symbol
|
58
|
+
model_proto.to_s.classify.constantize
|
59
|
+
else
|
60
|
+
model_proto.class
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|