agilidee_commons 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Rakefile +37 -0
  2. data/app/assets/stylesheets/agilidee_commons/context.sass +44 -0
  3. data/app/helpers/agilidee_commons/context_helper.rb +33 -0
  4. data/app/helpers/agilidee_commons/form_helper.rb +26 -0
  5. data/app/views/agilidee_commons/_actions.html.slim +22 -0
  6. data/app/views/agilidee_commons/_contextual.html.slim +5 -0
  7. data/config/cucumber.yml +8 -0
  8. data/config/routes.rb +2 -0
  9. data/lib/agilidee_commons.rb +4 -0
  10. data/lib/agilidee_commons/engine.rb +4 -0
  11. data/lib/agilidee_commons/polymorphic_id.rb +38 -0
  12. data/lib/agilidee_commons/simple_form.rb +166 -0
  13. data/lib/agilidee_commons/simple_form_bootstrap.rb +136 -0
  14. data/lib/agilidee_commons/version.rb +3 -0
  15. data/lib/tasks/agilidee_commons_tasks.rake +4 -0
  16. data/lib/tasks/cucumber.rake +65 -0
  17. data/spec/dummy/README.rdoc +28 -0
  18. data/spec/dummy/Rakefile +6 -0
  19. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  20. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  22. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  23. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  24. data/spec/dummy/bin/bundle +3 -0
  25. data/spec/dummy/bin/rails +4 -0
  26. data/spec/dummy/bin/rake +4 -0
  27. data/spec/dummy/bin/setup +29 -0
  28. data/spec/dummy/config.ru +4 -0
  29. data/spec/dummy/config/application.rb +26 -0
  30. data/spec/dummy/config/boot.rb +5 -0
  31. data/spec/dummy/config/database.yml +25 -0
  32. data/spec/dummy/config/environment.rb +5 -0
  33. data/spec/dummy/config/environments/development.rb +41 -0
  34. data/spec/dummy/config/environments/production.rb +79 -0
  35. data/spec/dummy/config/environments/test.rb +42 -0
  36. data/spec/dummy/config/initializers/assets.rb +11 -0
  37. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  38. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  39. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/spec/dummy/config/initializers/inflections.rb +16 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  42. data/spec/dummy/config/initializers/session_store.rb +3 -0
  43. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/spec/dummy/config/locales/en.yml +23 -0
  45. data/spec/dummy/config/routes.rb +56 -0
  46. data/spec/dummy/config/secrets.yml +22 -0
  47. data/spec/dummy/public/404.html +67 -0
  48. data/spec/dummy/public/422.html +67 -0
  49. data/spec/dummy/public/500.html +66 -0
  50. data/spec/dummy/public/favicon.ico +0 -0
  51. data/spec/rails_helper.rb +50 -0
  52. data/spec/spec_helper.rb +87 -0
  53. metadata +203 -0
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'AgilideeCommons'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,44 @@
1
+ .context
2
+ @extend .cadre
3
+ text-align: center
4
+ position: relative
5
+ margin-bottom: 15px !important
6
+
7
+ .fa
8
+ @extend .fa-fw
9
+
10
+ > .fa
11
+ font-size: 400%
12
+ color: black
13
+ padding: 10px
14
+ margin: auto
15
+ display: block
16
+
17
+ strong, h2
18
+ @extend .text-muted
19
+
20
+ h2
21
+ margin: 10px
22
+ font-size: 150%
23
+ font-weight: bold
24
+
25
+ p.infos
26
+ margin: 5px
27
+ text-align: left
28
+
29
+ strong
30
+ display: inline-block
31
+ width: 50%
32
+
33
+ .btn-group
34
+ position: absolute
35
+ top: 0
36
+ right: 0
37
+
38
+ .btn
39
+ border-top: 0
40
+ border-right: 0
41
+ border-radius: 0 0 0 3px
42
+
43
+ img
44
+ max-width: 100%
@@ -0,0 +1,33 @@
1
+ module AgilideeCommons
2
+ module ContextHelper
3
+ def context_icon(id)
4
+ icon(id)
5
+ end
6
+
7
+ def context_title(title)
8
+ content_tag(:h2){ title }
9
+ end
10
+
11
+ def context_info(name, info)
12
+ return if info.blank?
13
+ %(<p class="infos"><strong>#{name} : </strong>#{info}</p>).html_safe
14
+ end
15
+
16
+ def actions_for(obj, opts={})
17
+ url = opts[:url]
18
+ edit_url = opts[:edit_url]
19
+ delete_url = opts[:delete_url]
20
+
21
+ url = polymorphic_path(obj) if url.nil?
22
+ edit_url = url + "/edit" if edit_url.nil?
23
+ delete_url = url if delete_url.nil?
24
+
25
+ render partial: "agilidee_commons/actions", locals: {
26
+ :obj => obj,
27
+ :url => url,
28
+ :edit_url => edit_url,
29
+ :delete_url => delete_url,
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ module AgilideeCommons
2
+ module FormHelper
3
+ def form_buttons(opts = {})
4
+ back_url = opts[:back_url]
5
+ back_url = url_for(:back).html_safe if back_url.nil?
6
+
7
+ content_tag("div", class: "actions cdiv") do
8
+ submit = tag("input", type: "submit", class: "btn btn-success btn-sm", value: "Valider", id: "submit")
9
+ cancel = content_tag("a", href: back_url, class: "btn btn-primary btn-sm"){ "Annuler" }
10
+ cancel = "" if back_url == false
11
+ submit + cancel
12
+ end
13
+ end
14
+
15
+ def horizontal_form_for(obj, opts={}, &block)
16
+ opts = {
17
+ :wrapper => "horizontal_form",
18
+ :html => {
19
+ :class => "form-horizontal"
20
+ }
21
+ }.deep_merge(opts)
22
+
23
+ simple_form_for(obj, opts, &block)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ .btn-group
2
+ button.btn.btn-default.btn-sm.dropdown-toggle.actions data-toggle="dropdown"
3
+ = "Actions "
4
+ = icon :"caret-down"
5
+ ul.dropdown-menu
6
+ - if url && url != request.path_info
7
+ li
8
+ a.link_edit href=url
9
+ = icon :"file-o"
10
+ = " Afficher"
11
+
12
+ - if edit_url && edit_url != request.path_info
13
+ li
14
+ a.link_edit href=edit_url
15
+ = icon :pencil
16
+ = " Editer"
17
+
18
+ - if delete_url
19
+ li
20
+ a.link_delete href=delete_url data-method="delete" data-confirm="Confirmer ?"
21
+ = icon :trash
22
+ = " Supprimer"
@@ -0,0 +1,5 @@
1
+ .row
2
+ aside.col-sm-4.col-xs-12
3
+ = yield :context
4
+ .col-sm-8.col-xs-12
5
+ = yield :main
@@ -0,0 +1,8 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5
+ %>
6
+ default: <%= std_opts %> features
7
+ wip: --tags @wip:3 --wip features
8
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ require "agilidee_commons/engine"
2
+
3
+ module AgilideeCommons
4
+ end
@@ -0,0 +1,4 @@
1
+ module AgilideeCommons
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ module AgilideeCommons
2
+ module PolymorphicId
3
+ module ClassMethods
4
+ def polymorphic_id_for(relation_name)
5
+ module_src = File.read(__FILE__).split("__END__").last
6
+ module_src = module_src.gsub("relation", relation_name.to_s)
7
+ send :include, eval(module_src)
8
+ end
9
+ end
10
+
11
+ def self.included(model)
12
+ model.send(:extend, AgilideeCommons::PolymorphicId::ClassMethods)
13
+ end
14
+
15
+ def guid
16
+ return nil if new_record?
17
+
18
+ "#{self.class}-#{self.id}"
19
+ end
20
+ end
21
+ end
22
+
23
+ # __END__
24
+
25
+ Module.new do
26
+ def relation_guid
27
+ return nil if relation_type.blank? || relation_id.blank?
28
+
29
+ "#{relation_type}-#{relation_id}"
30
+ end
31
+
32
+ def relation_guid=(guid)
33
+ return self.relation = nil if guid.blank?
34
+
35
+ type, id = guid.split("-")
36
+ self.relation = type.constantize.find(id)
37
+ end
38
+ end
@@ -0,0 +1,166 @@
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 => true`
26
+ # to the input. If so, they will retrieve the values from the model
27
+ # if any exists. If you want to enable 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
+
47
+ ## full_messages_for
48
+ # If you want to display the full error message for the attribute, you can
49
+ # use the component :full_error, like:
50
+ #
51
+ # b.use :full_error, wrap_with: { tag: :span, class: :error }
52
+ end
53
+
54
+ # The default wrapper to be used by the FormBuilder.
55
+ config.default_wrapper = :default
56
+
57
+ # Define the way to render check boxes / radio buttons with labels.
58
+ # Defaults to :nested for bootstrap config.
59
+ # inline: input + label
60
+ # nested: label > input
61
+ config.boolean_style = :nested
62
+
63
+ # Default class for buttons
64
+ config.button_class = 'btn'
65
+
66
+ # Method used to tidy up errors. Specify any Rails Array method.
67
+ # :first lists the first message for each field.
68
+ # Use :to_sentence to list all errors for each field.
69
+ # config.error_method = :first
70
+
71
+ # Default tag used for error notification helper.
72
+ config.error_notification_tag = :div
73
+
74
+ # CSS class to add for error notification helper.
75
+ config.error_notification_class = 'error_notification'
76
+
77
+ # ID to add for error notification helper.
78
+ # config.error_notification_id = nil
79
+
80
+ # Series of attempts to detect a default label method for collection.
81
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
82
+
83
+ # Series of attempts to detect a default value method for collection.
84
+ # config.collection_value_methods = [ :id, :to_s ]
85
+
86
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
87
+ # config.collection_wrapper_tag = nil
88
+
89
+ # You can define the class to use on all collection wrappers. Defaulting to none.
90
+ # config.collection_wrapper_class = nil
91
+
92
+ # You can wrap each item in a collection of radio/check boxes with a tag,
93
+ # defaulting to :span. Please note that when using :boolean_style = :nested,
94
+ # SimpleForm will force this option to be a label.
95
+ # config.item_wrapper_tag = :span
96
+
97
+ # You can define a class to use in all item wrappers. Defaulting to none.
98
+ # config.item_wrapper_class = nil
99
+
100
+ # How the label text should be generated altogether with the required text.
101
+ # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
102
+
103
+ # You can define the class to use on all labels. Default is nil.
104
+ # config.label_class = nil
105
+
106
+ # You can define the default class to be used on forms. Can be overriden
107
+ # with `html: { :class }`. Defaulting to none.
108
+ # config.default_form_class = nil
109
+
110
+ # You can define which elements should obtain additional classes
111
+ # config.generate_additional_classes_for = [:wrapper, :label, :input]
112
+
113
+ # Whether attributes are required by default (or not). Default is true.
114
+ # config.required_by_default = true
115
+
116
+ # Tell browsers whether to use the native HTML5 validations (novalidate form option).
117
+ # These validations are enabled in SimpleForm's internal config but disabled by default
118
+ # in this configuration, which is recommended due to some quirks from different browsers.
119
+ # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
120
+ # change this configuration to true.
121
+ config.browser_validations = false
122
+
123
+ # Collection of methods to detect if a file type was given.
124
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
125
+
126
+ # Custom mappings for input types. This should be a hash containing a regexp
127
+ # to match as key, and the input type that will be used when the field name
128
+ # matches the regexp as value.
129
+ # config.input_mappings = { /count/ => :integer }
130
+
131
+ # Custom wrappers for input types. This should be a hash containing an input
132
+ # type as key and the wrapper that will be used for all inputs with specified type.
133
+ # config.wrapper_mappings = { string: :prepend }
134
+
135
+ # Namespaces where SimpleForm should look for custom input classes that
136
+ # override default inputs.
137
+ # config.custom_inputs_namespaces << "CustomInputs"
138
+
139
+ # Default priority for time_zone inputs.
140
+ # config.time_zone_priority = nil
141
+
142
+ # Default priority for country inputs.
143
+ # config.country_priority = nil
144
+
145
+ # When false, do not use translations for labels.
146
+ # config.translate_labels = true
147
+
148
+ # Automatically discover new inputs in Rails' autoload path.
149
+ # config.inputs_discovery = true
150
+
151
+ # Cache SimpleForm inputs discovery
152
+ # config.cache_discovery = !Rails.env.development?
153
+
154
+ # Default class for inputs
155
+ # config.input_class = nil
156
+
157
+ # Define the default class of the input wrapper of the boolean input.
158
+ config.boolean_label_class = 'checkbox'
159
+
160
+ # Defines if the default input wrapper class should be included in radio
161
+ # collection wrappers.
162
+ # config.include_default_input_wrapper_class = true
163
+
164
+ # Defines which i18n scope will be used in Simple Form.
165
+ # config.i18n_scope = 'simple_form'
166
+ end
@@ -0,0 +1,136 @@
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-default'
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-3 control-label'
62
+
63
+ b.wrapper tag: 'div', class: 'col-sm-9' 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-3 control-label'
76
+
77
+ b.wrapper tag: 'div', class: 'col-sm-9' 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.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
89
+ wr.wrapper tag: 'div', class: 'checkbox' do |ba|
90
+ ba.use :label_input, class: 'col-sm-9'
91
+ end
92
+
93
+ wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
94
+ wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
95
+ end
96
+ end
97
+
98
+ config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
99
+ b.use :html5
100
+ b.optional :readonly
101
+
102
+ b.use :label, class: 'col-sm-3 control-label'
103
+
104
+ b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
105
+ ba.use :input
106
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
107
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
108
+ end
109
+ end
110
+
111
+ config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
112
+ b.use :html5
113
+ b.use :placeholder
114
+ b.optional :maxlength
115
+ b.optional :pattern
116
+ b.optional :min_max
117
+ b.optional :readonly
118
+ b.use :label, class: 'sr-only'
119
+
120
+ b.use :input, class: 'form-control'
121
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
122
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
123
+ end
124
+
125
+ # Wrappers for forms and inputs using the Bootstrap toolkit.
126
+ # Check the Bootstrap docs (http://getbootstrap.com)
127
+ # to learn about the different styles for forms and inputs,
128
+ # buttons and other elements.
129
+ config.default_wrapper = :vertical_form
130
+ config.wrapper_mappings = {
131
+ check_boxes: :vertical_radio_and_checkboxes,
132
+ radio_buttons: :vertical_radio_and_checkboxes,
133
+ file: :vertical_file_input,
134
+ boolean: :vertical_boolean,
135
+ }
136
+ end