bootbox_crud 0.1.1

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +31 -0
  3. data/MIT.license +20 -0
  4. data/README.md +301 -0
  5. data/app/views/layouts/_bb_alert.html.haml +2 -0
  6. data/app/views/layouts/_show_link_to.html.haml +5 -0
  7. data/app/views/layouts/_show_link_to_array.html.haml +6 -0
  8. data/app/views/layouts/_show_value.html.haml +4 -0
  9. data/app/views/modals/_alert.js.erb +5 -0
  10. data/app/views/modals/_create.js.erb +1 -0
  11. data/app/views/modals/_destroy.js.erb +1 -0
  12. data/app/views/modals/_form.js.erb +16 -0
  13. data/app/views/modals/_update.js.erb +1 -0
  14. data/bootbox_crud.gemspec +28 -0
  15. data/lib/bootbox_crud.rb +7 -0
  16. data/lib/bootbox_crud/action_view/helpers.rb +37 -0
  17. data/lib/bootbox_crud/engine.rb +23 -0
  18. data/lib/bootbox_crud/version.rb +5 -0
  19. data/lib/generators/bootbox_crud/install_generator.rb +16 -0
  20. data/lib/generators/bootbox_crud/templates/README +6 -0
  21. data/lib/generators/bootbox_crud/templates/app/assets/javascripts/models.js +7 -0
  22. data/lib/generators/bootbox_crud/templates/config/initializers/simple_form.rb +142 -0
  23. data/lib/generators/bootbox_crud/templates/config/initializers/simple_form_bootstrap.rb +163 -0
  24. data/lib/generators/rails/haml_modal_crud/USAGE +15 -0
  25. data/lib/generators/rails/haml_modal_crud/haml_modal_crud_generator.rb +30 -0
  26. data/lib/generators/rails/haml_modal_crud/templates/create.js.erb +2 -0
  27. data/lib/generators/rails/haml_modal_crud/templates/destroy.js.erb +1 -0
  28. data/lib/generators/rails/haml_modal_crud/templates/update.js.erb +1 -0
  29. data/lib/generators/rails/modal_crud_route/USAGE +9 -0
  30. data/lib/generators/rails/modal_crud_route/modal_crud_route_generator.rb +21 -0
  31. data/lib/generators/rails/modal_crud_route/templates/models.js +7 -0
  32. data/lib/templates/haml/scaffold/_form.html.haml +12 -0
  33. data/lib/templates/haml/scaffold/edit.html.haml +2 -0
  34. data/lib/templates/haml/scaffold/index.html.haml +51 -0
  35. data/lib/templates/haml/scaffold/new.html.haml +2 -0
  36. data/lib/templates/haml/scaffold/show.html.haml +7 -0
  37. data/lib/templates/rails/scaffold_controller/controller.rb +102 -0
  38. data/vendor/assets/javascripts/bootbox_crud_main.js +6 -0
  39. data/vendor/assets/javascripts/bootbox_crud_modals.js +206 -0
  40. data/vendor/assets/javascripts/sortable.js +177 -0
  41. data/vendor/assets/stylesheets/bootbox_crud.css.scss +25 -0
  42. data/vendor/assets/stylesheets/bootbox_crud_main.css.scss +2 -0
  43. data/vendor/assets/stylesheets/sortable-theme-minimal.css +47 -0
  44. metadata +255 -0
@@ -0,0 +1,7 @@
1
+ module BootboxCrud
2
+ module Rails
3
+ require 'bootbox_crud/version'
4
+ require 'bootbox_crud/action_view/helpers'
5
+ require 'bootbox_crud/engine'
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ module BootboxCrud
2
+ module ActionView
3
+ module Helpers
4
+ def show_value(label, value)
5
+ render :partial => 'layouts/show_value', :locals => { :label => label, :value => value }
6
+ end
7
+
8
+ def show_link_to(label, object, link_text)
9
+ render :partial => 'layouts/show_link_to', :locals => { :label => label, :link_to_text => link_text, :link_to_object => object }
10
+ end
11
+
12
+ def show_link_to_array(label, objects, name_object_field)
13
+ render :partial => 'layouts/show_link_to_array', :locals => { :label => label, :objects => objects, :field => name_object_field }
14
+ end
15
+
16
+ def bb_alert
17
+ render :partial => 'layouts/bb_alert'
18
+ end
19
+
20
+ def form_options
21
+ { html: { class: 'form-horizontal' },
22
+ wrapper: :horizontal_form,
23
+ wrapper_mappings: {
24
+ check_boxes: :horizontal_radio_and_checkboxes,
25
+ radio_buttons: :horizontal_radio_and_checkboxes,
26
+ file: :horizontal_file_input,
27
+ boolean: :horizontal_boolean
28
+ }
29
+ }
30
+ end
31
+
32
+ def remote_form_options
33
+ { remote: true }.merge(form_options)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ module BootboxCrud
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ require 'bootbox-rails'
5
+ require 'haml-rails'
6
+ require 'simple_form'
7
+ require 'jquery-rails'
8
+ require 'turbolinks'
9
+ require 'jquery-turbolinks'
10
+ require 'remotipart'
11
+
12
+ initializer "bootbox_crud.configure_view" do |app|
13
+ ActiveSupport.on_load :action_view do
14
+ include BootboxCrud::ActionView::Helpers
15
+ end
16
+ end
17
+
18
+ config.app_generators do |g|
19
+ g.templates.unshift File::expand_path('../../templates', __FILE__)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module BootboxCrud
2
+ module Rails
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class BootboxCrud::InstallGenerator < ::Rails::Generators::Base
2
+ desc "Copies BootboxCrud default files"
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_config
6
+ template "config/initializers/simple_form.rb"
7
+ template "config/initializers/simple_form_bootstrap.rb"
8
+ template "app/assets/javascripts/models.js"
9
+ end
10
+
11
+ def show_readme
12
+ if behavior == :invoke
13
+ readme "README"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ ===============================================================================
2
+
3
+ Be sure to have a copy of the Bootstrap stylesheet available on your
4
+ application, you can get it on http://getbootstrap.com/.
5
+
6
+ ===============================================================================
@@ -0,0 +1,7 @@
1
+ // Put custom actions below this line
2
+ // e.g. BBCrud.Models.addAction('Event', '/events/', 'event', 'close');
3
+
4
+
5
+ //!!! Generator adds after this line, do not delete it !!!
6
+ // e.g. BBCrud.Models.add('Customer', '/customers/', 'customer');
7
+
@@ -0,0 +1,142 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ # Wrappers are used by the form builder to generate a
4
+ # complete input. You can remove any component from the
5
+ # wrapper, change the order or even add your own to the
6
+ # stack. The options given below are used to wrap the
7
+ # whole input.
8
+ config.wrappers :default, :class => :input,
9
+ :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
10
+ ## Extensions enabled by default
11
+ # Any of these extensions can be disabled for a
12
+ # given input by passing: `f.input EXTENSION_NAME => false`.
13
+ # You can make any of these extensions optional by
14
+ # renaming `b.use` to `b.optional`.
15
+
16
+ # Determines whether to use HTML5 (:email, :url, ...)
17
+ # and required attributes
18
+ b.use :html5
19
+
20
+ # Calculates placeholders automatically from I18n
21
+ # You can also pass a string as f.input :placeholder => "Placeholder"
22
+ b.use :placeholder
23
+
24
+ ## Optional extensions
25
+ # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
26
+ # to the input. If so, they will retrieve the values from the model
27
+ # if any exists. If you want to enable the lookup for any of those
28
+ # extensions by default, you can change `b.optional` to `b.use`.
29
+
30
+ # Calculates maxlength from length validations for string inputs
31
+ b.optional :maxlength
32
+
33
+ # Calculates pattern from format validations for string inputs
34
+ b.optional :pattern
35
+
36
+ # Calculates min and max from length validations for numeric inputs
37
+ b.optional :min_max
38
+
39
+ # Calculates readonly automatically from readonly attributes
40
+ b.optional :readonly
41
+
42
+ ## Inputs
43
+ b.use :label_input
44
+ b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
45
+ b.use :error, :wrap_with => { :tag => :span, :class => :error }
46
+ end
47
+
48
+ # The default wrapper to be used by the FormBuilder.
49
+ config.default_wrapper = :default
50
+
51
+ # Define the way to render check boxes / radio buttons with labels.
52
+ # Defaults to :nested for bootstrap config.
53
+ # :inline => input + label
54
+ # :nested => label > input
55
+ config.boolean_style = :nested
56
+
57
+ # Default class for buttons
58
+ config.button_class = 'btn'
59
+
60
+ # Method used to tidy up errors. Specify any Rails Array method.
61
+ # :first lists the first message for each field.
62
+ # Use :to_sentence to list all errors for each field.
63
+ # config.error_method = :first
64
+
65
+ # Default tag used for error notification helper.
66
+ config.error_notification_tag = :div
67
+
68
+ # CSS class to add for error notification helper.
69
+ config.error_notification_class = 'alert alert-error'
70
+
71
+ # ID to add for error notification helper.
72
+ # config.error_notification_id = nil
73
+
74
+ # Series of attempts to detect a default label method for collection.
75
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
76
+
77
+ # Series of attempts to detect a default value method for collection.
78
+ # config.collection_value_methods = [ :id, :to_s ]
79
+
80
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
81
+ # config.collection_wrapper_tag = nil
82
+
83
+ # You can define the class to use on all collection wrappers. Defaulting to none.
84
+ # config.collection_wrapper_class = nil
85
+
86
+ # You can wrap each item in a collection of radio/check boxes with a tag,
87
+ # defaulting to :span. Please note that when using :boolean_style = :nested,
88
+ # SimpleForm will force this option to be a label.
89
+ # config.item_wrapper_tag = :span
90
+
91
+ # You can define a class to use in all item wrappers. Defaulting to none.
92
+ # config.item_wrapper_class = nil
93
+
94
+ # How the label text should be generated altogether with the required text.
95
+ # config.label_text = lambda { |label, required| "#{required} #{label}" }
96
+
97
+ # You can define the class to use on all labels. Default is nil.
98
+ config.label_class = 'control-label'
99
+
100
+ # You can define the class to use on all forms. Default is simple_form.
101
+ # config.form_class = :simple_form
102
+
103
+ # You can define which elements should obtain additional classes
104
+ # config.generate_additional_classes_for = [:wrapper, :label, :input]
105
+
106
+ # Whether attributes are required by default (or not). Default is true.
107
+ # config.required_by_default = true
108
+
109
+ # Tell browsers whether to use default HTML5 validations (novalidate option).
110
+ # Default is enabled.
111
+ config.browser_validations = false
112
+
113
+ # Collection of methods to detect if a file type was given.
114
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
115
+
116
+ # Custom mappings for input types. This should be a hash containing a regexp
117
+ # to match as key, and the input type that will be used when the field name
118
+ # matches the regexp as value.
119
+ # config.input_mappings = { /count/ => :integer }
120
+
121
+ # Custom wrappers for input types. This should be a hash containing an input
122
+ # type as key and the wrapper that will be used for all inputs with specified type.
123
+ # config.wrapper_mappings = { :string => :prepend }
124
+
125
+ # Default priority for time_zone inputs.
126
+ # config.time_zone_priority = nil
127
+
128
+ # Default priority for country inputs.
129
+ # config.country_priority = nil
130
+
131
+ # Default size for text inputs.
132
+ # config.default_input_size = 50
133
+
134
+ # When false, do not use translations for labels.
135
+ # config.translate_labels = true
136
+
137
+ # Automatically discover new inputs in Rails' autoload path.
138
+ # config.inputs_discovery = true
139
+
140
+ # Cache SimpleForm inputs discovery
141
+ # config.cache_discovery = !Rails.env.development?
142
+ end
@@ -0,0 +1,163 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ config.error_notification_class = 'alert alert-danger'
4
+ config.button_class = 'btn btn-success'
5
+ config.boolean_label_class = nil
6
+
7
+ config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
8
+ b.use :html5
9
+ b.use :placeholder
10
+ b.optional :maxlength
11
+ b.optional :pattern
12
+ b.optional :min_max
13
+ b.optional :readonly
14
+ b.use :label, class: 'control-label'
15
+
16
+ b.use :input, class: 'form-control'
17
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
18
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
19
+ end
20
+
21
+ config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
22
+ b.use :html5
23
+ b.use :placeholder
24
+ b.optional :maxlength
25
+ b.optional :readonly
26
+ b.use :label, class: 'control-label'
27
+
28
+ b.use :input
29
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
30
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
31
+ end
32
+
33
+ config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
34
+ b.use :html5
35
+ b.optional :readonly
36
+
37
+ b.wrapper tag: 'div', class: 'checkbox' do |ba|
38
+ ba.use :label_input
39
+ end
40
+
41
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
42
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
43
+ end
44
+
45
+ config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
46
+ b.use :html5
47
+ b.optional :readonly
48
+ b.use :label, class: 'control-label'
49
+ b.use :input
50
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
51
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
52
+ end
53
+
54
+ config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
55
+ b.use :html5
56
+ b.use :placeholder
57
+ b.optional :maxlength
58
+ b.optional :pattern
59
+ b.optional :min_max
60
+ b.optional :readonly
61
+ b.use :label, class: 'col-sm-5 control-label'
62
+
63
+ b.wrapper tag: 'div', class: 'col-sm-6' do |ba|
64
+ ba.use :input, class: 'form-control'
65
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
66
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
67
+ end
68
+ end
69
+
70
+ config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
71
+ b.use :html5
72
+ b.use :placeholder
73
+ b.optional :maxlength
74
+ b.optional :readonly
75
+ b.use :label, class: 'col-sm-5 control-label'
76
+
77
+ b.wrapper tag: 'div', class: 'col-sm-7' do |ba|
78
+ ba.use :input
79
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
80
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
81
+ end
82
+ end
83
+
84
+ config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
85
+ b.use :html5
86
+ b.optional :readonly
87
+
88
+ b.use :label, class: 'col-sm-5 control-label'
89
+
90
+ b.wrapper tag: 'div', class: 'col-sm-7' do |ba|
91
+ ba.use :input
92
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
93
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
94
+ end
95
+ end
96
+
97
+ config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
98
+ b.use :html5
99
+ b.optional :readonly
100
+
101
+ b.use :label, class: 'col-sm-5 control-label'
102
+
103
+ b.wrapper tag: 'div', class: 'col-sm-7' do |ba|
104
+ ba.use :input
105
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
106
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
107
+ end
108
+ end
109
+
110
+ config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
111
+ b.use :html5
112
+ b.use :placeholder
113
+ b.optional :maxlength
114
+ b.optional :pattern
115
+ b.optional :min_max
116
+ b.optional :readonly
117
+ b.use :label, class: 'sr-only'
118
+
119
+ b.use :input, class: 'form-control'
120
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
121
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
122
+ end
123
+
124
+ config.wrappers :vertical_input_group, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
125
+ b.use :html5
126
+ b.use :placeholder
127
+ b.use :label, class: 'control-label'
128
+
129
+ b.wrapper tag: 'div' do |ba|
130
+ ba.wrapper tag: 'div', class: 'input-group col-sm-12' do |append|
131
+ append.use :input, class: 'form-control'
132
+ end
133
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
134
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
135
+ end
136
+ end
137
+
138
+ config.wrappers :horizontal_input_group, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
139
+ b.use :html5
140
+ b.use :placeholder
141
+ b.use :label, class: 'col-sm-3 control-label'
142
+
143
+ b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
144
+ ba.wrapper tag: 'div', class: 'input-group col-sm-12' do |append|
145
+ append.use :input, class: 'form-control'
146
+ end
147
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
148
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
149
+ end
150
+ end
151
+
152
+ # Wrappers for forms and inputs using the Bootstrap toolkit.
153
+ # Check the Bootstrap docs (http://getbootstrap.com)
154
+ # to learn about the different styles for forms and inputs,
155
+ # buttons and other elements.
156
+ config.default_wrapper = :vertical_form
157
+ config.wrapper_mappings = {
158
+ check_boxes: :vertical_radio_and_checkboxes,
159
+ radio_buttons: :vertical_radio_and_checkboxes,
160
+ file: :vertical_file_input,
161
+ boolean: :vertical_boolean,
162
+ }
163
+ end
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Creates js.erb view files necessary for modal CRUD to work and invokes haml:scaffold generator.
3
+
4
+ Example:
5
+ rails generate haml_modal_crud Thing name size:integer
6
+
7
+ This will create:
8
+ app/views/<model>/create.js.erb
9
+ app/views/<model>/destroy.js.erb
10
+ app/views/<model>/update.js.erb
11
+ app/views/<model>/_form.html.haml
12
+ app/views/<model>/edit.html.haml
13
+ app/views/<model>/index.html.haml
14
+ app/views/<model>/new.html.haml
15
+ app/views/<model>/show.html.haml
@@ -0,0 +1,30 @@
1
+ require 'rails/generators/erb'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ class Rails::HamlModalCrudGenerator < Rails::Generators::NamedBase
5
+ include Rails::Generators::ResourceHelpers
6
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def copy_view_files
10
+ available_actions.each do |view|
11
+ template "#{view}.js.erb", File.join("app/views", controller_file_path, "#{view}.js.erb")
12
+ end
13
+ run_haml
14
+ end
15
+
16
+ protected
17
+
18
+ def available_actions
19
+ %w(create update destroy)
20
+ end
21
+
22
+ def handler
23
+ :erb
24
+ end
25
+
26
+ def run_haml
27
+ attrs = attributes.collect {|a| "#{a.name}:#{a.type}" }
28
+ generate 'haml:scaffold', name, *attrs
29
+ end
30
+ end