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,54 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
# Bootstrap 3.6 HTML classes
|
4
|
+
module Constants
|
5
|
+
BS_SELECTED = 'active'
|
6
|
+
|
7
|
+
BS_FORM = 'form-horizontal'
|
8
|
+
BS_FORM_INLINE = 'form form-inline'
|
9
|
+
|
10
|
+
#BS_FORM_HELP_BLOCK = 'help-block'
|
11
|
+
|
12
|
+
BS_LIST_UNSTYLED = 'list-unstyled'
|
13
|
+
BS_LIST_INLINE = 'list-inline'
|
14
|
+
|
15
|
+
BS_PANEL = 'panel panel-danger'
|
16
|
+
BS_PANEL_HEADING = 'panel-heading'
|
17
|
+
BS_PANEL_TITLE = 'panel-title'
|
18
|
+
BS_PANEL_BODY = 'panel-body'
|
19
|
+
|
20
|
+
BS_BUTTON = 'btn'
|
21
|
+
|
22
|
+
BS_BUTTON_SUBMIT = "#{BS_BUTTON} #{BS_BUTTON}-primary"
|
23
|
+
BS_BUTTON_SUBMIT_SEARCH = "#{BS_BUTTON} #{BS_BUTTON}-default"
|
24
|
+
|
25
|
+
BS_BUTTON_TYPE = 'default'
|
26
|
+
BS_BUTTON_SIZE = 'md'
|
27
|
+
|
28
|
+
BS_BUTTON_GROUP = "#{BS_BUTTON}-group"
|
29
|
+
BS_BUTTON_GROUP_VERTICAL = "#{BS_BUTTON_GROUP}-vertical"
|
30
|
+
BS_BUTTON_GROUP_JUSTIFIED = "#{BS_BUTTON_GROUP}-justified"
|
31
|
+
|
32
|
+
BS_TOOLBAR = "toolbar"
|
33
|
+
BS_BUTTON_TOOLBAR = "#{BS_BUTTON}-#{BS_TOOLBAR}"
|
34
|
+
|
35
|
+
BS_BUTTON_DROPDOWN = "dropdown-menu"
|
36
|
+
|
37
|
+
BS_BUTTON_BLOCK = 'btn btn-info btn-md btn-block'
|
38
|
+
|
39
|
+
BS_LIST_GROUP = "list-group"
|
40
|
+
BS_LIST_GROUP_ITEM = "list-group-item"
|
41
|
+
|
42
|
+
BS_NAV = "nav"
|
43
|
+
BS_NAV_PILLS = "#{BS_NAV} nav-pills"
|
44
|
+
BS_NAV_TABS = "#{BS_NAV} nav-tabs"
|
45
|
+
BS_NAV_PILLS_STACKED = "nav-stacked"
|
46
|
+
|
47
|
+
BS_TABLE = 'table table-responsive table-hover table-condensed table-striped'
|
48
|
+
|
49
|
+
# TODO:
|
50
|
+
BS_COL = 'col-md-'
|
51
|
+
BS_COL_OFFSET = 'col-md-offset-'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Forms
|
4
|
+
# Entry point for rendering forms
|
5
|
+
# It writes out the HTML form tag, error meesages and hidden fields
|
6
|
+
class BsForm < Templet::Component::Partial
|
7
|
+
include Constants
|
8
|
+
|
9
|
+
# Renders the outside of an HTML form
|
10
|
+
# it renders the <form> tag, the model's errors, and two hiiden fields
|
11
|
+
def call(url: nil,
|
12
|
+
remote: false,
|
13
|
+
html_class: nil,
|
14
|
+
inline: false,
|
15
|
+
method: nil)
|
16
|
+
super() do
|
17
|
+
url, model = url.for_form if url.respond_to?(:for_form)
|
18
|
+
|
19
|
+
url = url_for(url) if Array === url or ActiveRecord::Base === url
|
20
|
+
|
21
|
+
atts = form_atts(html_class, remote, inline, method)
|
22
|
+
|
23
|
+
method ||= http_method(model)
|
24
|
+
|
25
|
+
hidden_form_fields = if get?(method)
|
26
|
+
[]
|
27
|
+
else
|
28
|
+
[ hidden_field_tag(:authenticity_token, form_authenticity_token),
|
29
|
+
hidden_field_tag(:_method, method) ]
|
30
|
+
end
|
31
|
+
|
32
|
+
[ BsFormErrors.new(self).(model),
|
33
|
+
form(atts.merge action: url) { hidden_form_fields << yield(self) }
|
34
|
+
]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Shortcut method used in rendering a REST form with specified fields
|
39
|
+
def self.call(renderer, record, **form_group_options)
|
40
|
+
form_group = BsFormGroup.new(renderer, record, **form_group_options)
|
41
|
+
|
42
|
+
return BsFormField.new(form_group), form_group
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def get?(method)
|
48
|
+
method&.to_s =~ /get/i
|
49
|
+
end
|
50
|
+
|
51
|
+
def form_atts(html_class, remote, inline, method)
|
52
|
+
html_class ||= form_class(inline)
|
53
|
+
|
54
|
+
atts = { class: html_class, role: 'form' }
|
55
|
+
|
56
|
+
atts[:method] = get?(method) ? 'get' : 'post'
|
57
|
+
|
58
|
+
atts[:"data-remote"] = 'true' if remote
|
59
|
+
|
60
|
+
atts
|
61
|
+
end
|
62
|
+
|
63
|
+
def form_class(inline=false)
|
64
|
+
inline ? BS_FORM_INLINE : BS_FORM
|
65
|
+
end
|
66
|
+
|
67
|
+
def http_method(record)
|
68
|
+
record&.persisted? ? 'patch' : 'post'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Forms
|
4
|
+
# Shows error messages from validation failures
|
5
|
+
class BsFormErrors < Templet::Component::Partial
|
6
|
+
include Constants
|
7
|
+
|
8
|
+
def call(model)
|
9
|
+
if model and model.errors.any?
|
10
|
+
super() do
|
11
|
+
div id: "error_expl", class: BS_PANEL do
|
12
|
+
[ div(BS_PANEL_HEADING) { h3(error_title(model), BS_PANEL_TITLE) },
|
13
|
+
|
14
|
+
div(BS_PANEL_BODY) do
|
15
|
+
ul(BS_LIST_UNSTYLED) do
|
16
|
+
model.errors.full_messages.map {|msg| li msg }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def error_title(model)
|
28
|
+
compose do
|
29
|
+
error_count = model.errors.count
|
30
|
+
model_name = model.class.name.underscore
|
31
|
+
|
32
|
+
"#{pluralize error_count, "error"} on #{model_name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Forms
|
4
|
+
# Renders the different types of HTML input fields
|
5
|
+
class BsFormField < Struct.new(:form_group)
|
6
|
+
include Constants
|
7
|
+
|
8
|
+
def text(field_name, mandatory: false, help: nil)
|
9
|
+
field_class = field_class()
|
10
|
+
|
11
|
+
group_opts = { mandatory: mandatory, help: help }
|
12
|
+
|
13
|
+
form_group.(field_name, **group_opts) do |renderer, record_name|
|
14
|
+
renderer.call do
|
15
|
+
text_field record_name, field_name, class: field_class
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def text_area(field_name, rows: 2, mandatory: false, help: nil)
|
21
|
+
field_class = field_class()
|
22
|
+
|
23
|
+
group_opts = { mandatory: mandatory, help: help }
|
24
|
+
|
25
|
+
form_group.(field_name, **group_opts) do |renderer, record_name|
|
26
|
+
renderer.call do
|
27
|
+
text_area record_name, field_name, class: field_class, rows: rows
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_box(field_name, help: nil)
|
33
|
+
form_group.(field_name, help: help) do |renderer, record_name|
|
34
|
+
renderer.call do
|
35
|
+
check_box record_name, field_name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_box_inline(field_name, help: nil)
|
41
|
+
form_group.checkbox(field_name, help: help) do |renderer, record_name|
|
42
|
+
renderer.call do
|
43
|
+
check_box record_name, field_name
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def select(field_name, selections, select_id: :id,
|
49
|
+
select_name: :name,
|
50
|
+
include_blank: false,
|
51
|
+
size: nil,
|
52
|
+
help: nil)
|
53
|
+
html_options = { class: field_class }
|
54
|
+
|
55
|
+
group_opts = { input_size: size, help: help }
|
56
|
+
|
57
|
+
options = { include_blank: include_blank }
|
58
|
+
|
59
|
+
form_group.(field_name, **group_opts) do |renderer, record_name|
|
60
|
+
renderer.call do
|
61
|
+
collection_select record_name, field_name,
|
62
|
+
selections, select_id, select_name,
|
63
|
+
options, html_options
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
DATE_INLINE_STYLE = 'display: inline; width: auto; float: left;'
|
69
|
+
|
70
|
+
def date(field_name, include_blank: true, help: nil)
|
71
|
+
html_options = { class: field_class, style: DATE_INLINE_STYLE }
|
72
|
+
|
73
|
+
options = { include_blank: include_blank }
|
74
|
+
|
75
|
+
form_group.(field_name, help: help) do |renderer, record_name|
|
76
|
+
renderer.call do
|
77
|
+
date_select record_name, field_name, options, html_options
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def datetime(field_name, include_blank: true, help: nil)
|
83
|
+
html_options = { class: field_class, style: DATE_INLINE_STYLE }
|
84
|
+
|
85
|
+
options = { include_blank: include_blank,
|
86
|
+
datetime_separator: '', time_separator: '' }
|
87
|
+
|
88
|
+
form_group.(field_name, help: help) do |renderer, record_name|
|
89
|
+
renderer.call do
|
90
|
+
datetime_select record_name, field_name, options, html_options
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def submit(text: 'Submit', html_class: BS_BUTTON_SUBMIT,
|
96
|
+
offset: nil, height: form_group.height)
|
97
|
+
html_class += " btn-#{height}" if height
|
98
|
+
|
99
|
+
offset ||= form_group.label_cols
|
100
|
+
|
101
|
+
form_group.renderer.call do
|
102
|
+
submit_button = button(text, html_class, type: 'submit')
|
103
|
+
|
104
|
+
div(:form_group) { div submit_button, "#{BS_COL_OFFSET}#{offset}" }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def field_class
|
109
|
+
form_group.field_class
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Forms
|
4
|
+
# Renders the various tags that surround a Bootstrap form field
|
5
|
+
class BsFormGroup < Templet::Component::Partial
|
6
|
+
include Constants
|
7
|
+
|
8
|
+
MANDATORY_MARKER = ' *'
|
9
|
+
|
10
|
+
NBSP = ' '
|
11
|
+
|
12
|
+
attr_accessor :record, :record_name
|
13
|
+
|
14
|
+
attr_accessor :field_cols, :input_cols, :height
|
15
|
+
|
16
|
+
attr_accessor :label_cols, :hide_label
|
17
|
+
|
18
|
+
def initialize(renderer, record, record_name: record.model_name.singular,
|
19
|
+
field_cols: 12,
|
20
|
+
input_cols: 8,
|
21
|
+
label_cols: 2,
|
22
|
+
height: nil,
|
23
|
+
hide_label: false)
|
24
|
+
super(renderer)
|
25
|
+
|
26
|
+
self.record = record
|
27
|
+
|
28
|
+
self.record_name = record_name
|
29
|
+
|
30
|
+
self.field_cols = field_cols
|
31
|
+
self.input_cols = input_cols
|
32
|
+
|
33
|
+
self.height = height
|
34
|
+
|
35
|
+
self.label_cols = label_cols
|
36
|
+
|
37
|
+
self.hide_label = hide_label
|
38
|
+
end
|
39
|
+
|
40
|
+
# An alternative constructor for plain (usually inline) forms
|
41
|
+
def self.call(renderer, model=nil, hide_label: true, height: 'md')
|
42
|
+
new renderer, model, record_name: '',
|
43
|
+
field_cols: nil,
|
44
|
+
input_cols: nil,
|
45
|
+
label_cols: nil,
|
46
|
+
height: height,
|
47
|
+
hide_label: hide_label
|
48
|
+
end
|
49
|
+
|
50
|
+
def call(field_name, label_name: nil, field_size: nil,
|
51
|
+
input_size: nil, label_size: nil,
|
52
|
+
mandatory: false, help: nil)
|
53
|
+
label_name ||= field_name.to_s.sub(/_id$/, '').tr('_', ' ').capitalize
|
54
|
+
|
55
|
+
label_name += mandatory ? MANDATORY_MARKER : ''
|
56
|
+
|
57
|
+
field_class = "form-group #{col_class field_size || field_cols}"
|
58
|
+
|
59
|
+
if hide_label
|
60
|
+
label_class = "sr-only"
|
61
|
+
else
|
62
|
+
label_class = "control-label #{col_class label_size || label_cols}"
|
63
|
+
|
64
|
+
label_class += height ? " input-#{height}" : ''
|
65
|
+
end
|
66
|
+
|
67
|
+
input_class = col_class(input_size || input_cols)
|
68
|
+
|
69
|
+
inner_self = self
|
70
|
+
|
71
|
+
renderer.call do
|
72
|
+
div(field_class) do
|
73
|
+
[ label(record_name, field_name, label_name, class: label_class),
|
74
|
+
div(input_class) do
|
75
|
+
[ yield(self, record_name, inner_self), *help_block(help) ]
|
76
|
+
end
|
77
|
+
]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Checkboxes can be rendered with a different form-group layout
|
83
|
+
def checkbox(field_name, text=field_name.to_s.capitalize, help: nil)
|
84
|
+
inner_self = self
|
85
|
+
|
86
|
+
renderer.call do
|
87
|
+
div("form-group #{col_class field_cols}") do
|
88
|
+
div :checkbox do
|
89
|
+
_label col_class(label_cols, offset: true) do
|
90
|
+
[ NBSP,
|
91
|
+
yield(self, record_name, inner_self),
|
92
|
+
text,
|
93
|
+
help_block(help) || '<br><br>'
|
94
|
+
]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def help_block(help)
|
102
|
+
"<p class='help-block'>#{help}</p>" if help
|
103
|
+
end
|
104
|
+
|
105
|
+
def col_class(cols, offset=false)
|
106
|
+
"#{offset ? BS_COL_OFFSET : BS_COL}#{cols}" if cols
|
107
|
+
end
|
108
|
+
|
109
|
+
def field_class
|
110
|
+
'form-control' + (height ? " input-#{height}" : '')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
module Layouts
|
4
|
+
# Renders a standard HTML layout
|
5
|
+
# Basically, it's the same layout that Rails uses
|
6
|
+
class HtmlRails < Templet::Component::Layout
|
7
|
+
APP = 'application'
|
8
|
+
|
9
|
+
TURBOS = { 'data-turbolinks-track' => true }
|
10
|
+
|
11
|
+
SCALE = '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
|
12
|
+
|
13
|
+
DESC_TEMPLATE = '<meta name="description" content="%s">'
|
14
|
+
|
15
|
+
def call(title, description='', head_extras: nil)
|
16
|
+
super() do
|
17
|
+
header = [ SCALE,
|
18
|
+
(DESC_TEMPLATE % description),
|
19
|
+
_title(title),
|
20
|
+
stylesheet_link_tag(APP, TURBOS.merge(media: 'all')),
|
21
|
+
javascript_include_tag(APP, TURBOS),
|
22
|
+
csrf_meta_tags,
|
23
|
+
head_extras,
|
24
|
+
rear_head ]
|
25
|
+
|
26
|
+
html { [ head(header), body(yield renderer) ] }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def rear_head
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
module Templet
|
3
|
+
# Some shortcut methods for the main library classes
|
4
|
+
module Links
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def collection(*args)
|
8
|
+
BsLinkSetCollection.new *args
|
9
|
+
end
|
10
|
+
|
11
|
+
def navigation(*args)
|
12
|
+
BsLinkSetNavigation.new *args
|
13
|
+
end
|
14
|
+
|
15
|
+
def rest_link_procs(*args)
|
16
|
+
RestLinkProcs.new *args
|
17
|
+
end
|
18
|
+
|
19
|
+
def btn_class(*args)
|
20
|
+
BsBtnClass.new *args
|
21
|
+
end
|
22
|
+
|
23
|
+
def link_text(*args)
|
24
|
+
RestLinkText.new *args
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|