effective_developer 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +0 -8
  4. data/app/models/effective/code_writer.rb +8 -0
  5. data/app/models/effective/csv_importer.rb +46 -1
  6. data/lib/effective_developer.rb +0 -7
  7. data/lib/effective_developer/version.rb +1 -1
  8. data/lib/generators/effective/form_generator.rb +12 -6
  9. data/lib/generators/effective/menu_generator.rb +31 -23
  10. data/lib/generators/effective/route_generator.rb +3 -3
  11. data/lib/generators/effective/scaffold_controller_generator.rb +3 -3
  12. data/lib/generators/effective/scaffold_generator.rb +3 -3
  13. data/lib/scaffolds/controllers/controller.rb +10 -1
  14. data/lib/scaffolds/datatables/datatable.rb +2 -2
  15. data/lib/scaffolds/forms/default/_form.html.haml +2 -9
  16. data/lib/scaffolds/forms/fields/_field_belongs_to.html.haml +1 -1
  17. data/lib/scaffolds/forms/fields/_field_boolean.html.haml +1 -1
  18. data/lib/scaffolds/forms/fields/_field_date.html.haml +1 -1
  19. data/lib/scaffolds/forms/fields/_field_datetime.html.haml +1 -1
  20. data/lib/scaffolds/forms/fields/_field_decimal.html.haml +1 -1
  21. data/lib/scaffolds/forms/fields/_field_inet.html.haml +1 -1
  22. data/lib/scaffolds/forms/fields/_field_integer.html.haml +1 -1
  23. data/lib/scaffolds/forms/fields/_field_select.html.haml +1 -0
  24. data/lib/scaffolds/forms/fields/_field_string.html.haml +1 -1
  25. data/lib/scaffolds/forms/fields/_field_text.html.haml +1 -1
  26. data/lib/scaffolds/forms/fields/_nested_resource_fields.html.haml +3 -3
  27. data/lib/scaffolds/importers/csv_importer.rb +1 -1
  28. data/lib/scaffolds/simple_form/default/_form.html.haml +16 -0
  29. data/lib/scaffolds/simple_form/fields/_field_belongs_to.html.haml +1 -0
  30. data/lib/scaffolds/simple_form/fields/_field_boolean.html.haml +1 -0
  31. data/lib/scaffolds/simple_form/fields/_field_date.html.haml +1 -0
  32. data/lib/scaffolds/simple_form/fields/_field_datetime.html.haml +1 -0
  33. data/lib/scaffolds/simple_form/fields/_field_decimal.html.haml +1 -0
  34. data/lib/scaffolds/simple_form/fields/_field_inet.html.haml +1 -0
  35. data/lib/scaffolds/simple_form/fields/_field_integer.html.haml +1 -0
  36. data/lib/scaffolds/simple_form/fields/_field_nested_resource.html.haml +11 -0
  37. data/lib/scaffolds/simple_form/fields/_field_string.html.haml +1 -0
  38. data/lib/scaffolds/simple_form/fields/_field_text.html.haml +1 -0
  39. data/lib/scaffolds/simple_form/fields/_nested_resource_fields.html.haml +12 -0
  40. data/lib/scaffolds/simple_form/tabpanel/_form.html.haml +33 -0
  41. data/lib/scaffolds/simple_form/tabpanel/_tab_fields.html.haml +6 -0
  42. data/lib/scaffolds/simple_form/tabpanel/_tab_nested_resource.html.haml +3 -0
  43. metadata +18 -3
  44. data/app/models/effective/access_denied.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b77679e9f8c77843070e3935e2e8b135203700a
4
- data.tar.gz: d1a2090b68044a236f141c722d805a9ee43e73c1
3
+ metadata.gz: 4de366561d47f1314e5ee2960a0a81bc96bc916d
4
+ data.tar.gz: 90d9f4857b678ea4b12d6809f772666af1673604
5
5
  SHA512:
6
- metadata.gz: 64d2639f6e25c17cbca8a9ca634716175ea3fbc37404230b5de37938430d766affbe8704b8e1d4db4a9adbe47e468eba91e427350c9ed37b56d608875a984100
7
- data.tar.gz: 0ef9f0d3bfc14fd540c87c7ee10d734d9bc7d55369a86514bb17837fb3a03186170f7ccb77f4eb84137c8e671f3a5cadce2aa8cb6df5b61b06ac81526004b8a8
6
+ metadata.gz: e8b1e735918100416799925391228dff6949c85773aa395335c07a03ac56aedc281ac982682f30501eed99e8dc4a4ba29ee5872a89a5065282f454763d07d34f
7
+ data.tar.gz: 2bfbfa79274c05ed5727ec2536b06b775eee927e91dd2c35a8f76e46459baa49a2a10297526852058afed538f7fa0c7d79c10ce69611120484196ca6154222e4
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017 Code and Effect Inc.
1
+ Copyright 2018 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -131,14 +131,6 @@ A command line script to delete any git branch that has already been merged into
131
131
  > gitsweep
132
132
  ```
133
133
 
134
- ## BFG Repo-Cleaner
135
-
136
- A command line script that calls [BFG Repo-Cleaner](https://rtyley.github.io/bfg-repo-cleaner/) to remove sensitive data from the git repository history.
137
-
138
- ```console
139
- > bfg --delete-files id_rsa.pub
140
- ```
141
-
142
134
  # Rake scripts
143
135
 
144
136
  ## csv:export
@@ -22,6 +22,14 @@ module Effective
22
22
  end
23
23
  end
24
24
 
25
+ # Returns true if the insert happened, nil if no insert
26
+ def insert_after_first(content, depth: nil, content_depth: nil, &block)
27
+ index = first(&block)
28
+ return nil unless index
29
+
30
+ insert(content, index, depth: depth, content_depth: content_depth)
31
+ end
32
+
25
33
  # Returns true if the insert happened, nil if no insert
26
34
  def insert_after_last(content, depth: nil, content_depth: nil, &block)
27
35
  index = last(&block)
@@ -81,7 +81,7 @@ module Effective
81
81
  value = value.to_s
82
82
 
83
83
  if column.ends_with?('?') # Boolean
84
- ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
84
+ truthy?(value)
85
85
  elsif column.ends_with?('_at') # DateTime
86
86
  parse_datetime(column, value)
87
87
  elsif column.ends_with?('_on') # Date
@@ -126,6 +126,43 @@ module Effective
126
126
  obj
127
127
  end
128
128
 
129
+ def assign_valid_email(user, at: 'example.com')
130
+ raise 'expected an object that responds to email=' unless user.respond_to?('email=')
131
+
132
+ user.email = user.email.to_s.strip.downcase.presence
133
+
134
+ if user.email.blank?
135
+ if user.respond_to?(:first_name) && user.respond_to?(:last_name)
136
+ user.email ||= [user.first_name.to_s.parameterize.presence, user.last_name.to_s.parameterize.presence].compact.join('.').presence
137
+ end
138
+
139
+ if user.respond_to?(:full_name)
140
+ user.email ||= user.full_name.to_s.parameterize.presence
141
+ end
142
+
143
+ if user.respond_to?(:name)
144
+ user.email ||= user.name.to_s.parameterize.presence
145
+ end
146
+
147
+ user.email ||= user.object_id
148
+
149
+ user.email = "#{user.email}@#{at.sub('@', '')}"
150
+ end
151
+
152
+ # Check for uniqueness
153
+ unique = 0
154
+ email = user.email
155
+
156
+ while user.class.where(email: email).present?
157
+ pieces = user.email.split('@')
158
+ email = pieces.first + "+#{(unique += 1)}@" + pieces.last
159
+ end
160
+
161
+ user.email = email
162
+
163
+ user
164
+ end
165
+
129
166
  def log(message)
130
167
  puts "\n#{message}";
131
168
  end
@@ -227,6 +264,14 @@ module Effective
227
264
  end
228
265
  end
229
266
 
267
+ def truthy?(value)
268
+ if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails <5
269
+ ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
270
+ else
271
+ ::ActiveRecord::Type::Boolean.new.cast(value)
272
+ end
273
+ end
274
+
230
275
  private
231
276
 
232
277
  def default_csv_files
@@ -9,11 +9,4 @@ module EffectiveDeveloper
9
9
  yield self
10
10
  end
11
11
 
12
- def self.authorized?(controller, action, resource)
13
- if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
14
- raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
15
- end
16
- true
17
- end
18
-
19
12
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.2.12'.freeze
2
+ VERSION = '0.2.13'.freeze
3
3
  end
@@ -28,29 +28,33 @@ module Effective
28
28
 
29
29
  def create_default_form
30
30
  if resource.nested_resources.blank?
31
- template 'forms/default/_form.html.haml', resource.view_file('form', partial: true)
31
+ template "#{forms_path}/default/_form.html.haml", resource.view_file('form', partial: true)
32
32
  end
33
33
  end
34
34
 
35
35
  def create_tabpanel_form
36
36
  if resource.nested_resources.present?
37
- template 'forms/tabpanel/_form.html.haml', resource.view_file('form', partial: true)
38
- template 'forms/tabpanel/_tab_fields.html.haml', resource.view_file("form_#{resource.name}", partial: true)
37
+ template "#{forms_path}/tabpanel/_form.html.haml", resource.view_file('form', partial: true)
38
+ template "#{forms_path}/tabpanel/_tab_fields.html.haml", resource.view_file("form_#{resource.name}", partial: true)
39
39
  end
40
40
 
41
41
  class_eval { attr_accessor :nested_resource }
42
42
 
43
43
  resource.nested_resources.each do |nested_resource|
44
44
  @nested_resource = nested_resource
45
- template 'forms/tabpanel/_tab_nested_resource.html.haml', resource.view_file("form_#{nested_resource.plural_name}", partial: true)
45
+ template "#{forms_path}/tabpanel/_tab_nested_resource.html.haml", resource.view_file("form_#{nested_resource.plural_name}", partial: true)
46
46
 
47
47
  @nested_resource = Effective::Resource.new(nested_resource)
48
- template 'forms/fields/_nested_resource_fields.html.haml', File.join('app/views', resource.namespace.to_s, (resource.namespace.present? ? '' : resource.class_path), nested_resource.name.to_s.underscore.pluralize, '_fields.html.haml')
48
+ template "#{forms_path}/fields/_nested_resource_fields.html.haml", File.join('app/views', resource.namespace.to_s, (resource.namespace.present? ? '' : resource.class_path), nested_resource.name.to_s.underscore.pluralize, '_fields.html.haml')
49
49
  end
50
50
  end
51
51
 
52
52
  protected
53
53
 
54
+ def forms_path
55
+ @forms_path ||= (defined?(EffectiveBootstrap) ? 'forms' : 'simple_form')
56
+ end
57
+
54
58
  def form_for
55
59
  if resource.namespaces.blank?
56
60
  resource.name
@@ -62,6 +66,8 @@ module Effective
62
66
  def render_field(attribute, depth: 0)
63
67
  b = binding
64
68
 
69
+ b.local_variable_set(:resource, resource)
70
+
65
71
  partial = case attribute
66
72
  when (ActiveRecord::Reflection::BelongsToReflection rescue false)
67
73
  b.local_variable_set(:reference, attribute)
@@ -78,7 +84,7 @@ module Effective
78
84
  end
79
85
 
80
86
  html = ERB.new(
81
- File.read("#{File.dirname(__FILE__)}/../../scaffolds/forms/fields/_field_#{partial}.html.haml")
87
+ File.read("#{File.dirname(__FILE__)}/../../scaffolds/#{forms_path}/fields/_field_#{partial}.html.haml")
82
88
  ).result(b).split("\n").map { |line| (' ' * depth) + line }
83
89
 
84
90
  html.length > 1 ? (html.join("\n") + "\n") : html.join
@@ -1,6 +1,7 @@
1
1
  # rails generate effective:menu NAME
2
2
 
3
3
  # Adds a menu to namespace/_navbar if present
4
+ # Adds a menu to namespace/_navbar_admin if present
4
5
  # rails generate effective:menu Thing
5
6
 
6
7
  module Effective
@@ -16,20 +17,20 @@ module Effective
16
17
  say_status :invoke, :menu, :white
17
18
  end
18
19
 
20
+ # layouts/_navbar.html.haml
19
21
  def create_menu
22
+ return unless resource.namespaces.blank?
23
+
20
24
  begin
21
- Effective::CodeWriter.new((['app/views'] + resource.namespaces + ['_navbar.html.haml']).join('/')) do |w|
25
+ Effective::CodeWriter.new('app/views/layouts/_navbar.html.haml') do |w|
22
26
  if w.find { |line, _| line == menu_content.last.strip }
23
- say_status :identical, resource.action_path(:index), :blue
27
+ say_status :identical, menu_path, :blue
24
28
  else
25
- index = w.last { |line, _| line.start_with?('- if can?') }
26
-
27
- if index.blank?
28
- say_status(:skipped, :menu, :yellow) and return
29
+ if (w.insert_after_first(menu_content) { |line, _| line.start_with?('= nav_link_to') })
30
+ say_status :menu, menu_path, :green
31
+ else
32
+ say_status(:skipped, :menu, :yellow)
29
33
  end
30
-
31
- w.insert_raw(menu_content, index+1, w.depth_at(index))
32
- say_status :menu, resource.action_path(:index), :green
33
34
  end
34
35
  end
35
36
  rescue Errno::ENOENT
@@ -38,41 +39,48 @@ module Effective
38
39
  end
39
40
  end
40
41
 
41
- def create_effective_menus
42
+ # layouts/_navbar_admin.html.haml
43
+ def create_admin_menu
44
+ return unless resource.namespaces == ['admin']
45
+
42
46
  begin
43
- Effective::CodeWriter.new('lib/tasks/generate/effective_menus.rake') do |w|
44
- if w.find { |line, _| line == effective_menus_content }
45
- say_status :identical, resource.action_path(:index), :blue
47
+ Effective::CodeWriter.new('app/views/layouts/_navbar_admin.html.haml') do |w|
48
+ if w.find { |line, _| line == admin_menu_content.last.strip }
49
+ say_status :identical, menu_path, :blue
46
50
  else
47
- index = w.first { |line, _| line.start_with?('item') }
48
-
49
- w.insert(effective_menus_content, index)
51
+ index = w.last { |line, _| line.start_with?('- if can?') }
50
52
 
51
- system('rake generate:effective_menus')
53
+ if index.blank?
54
+ say_status(:skipped, :menu, :yellow) and return
55
+ end
52
56
 
53
- say_status :effective_menus, resource.plural_name + '_path', :green
57
+ w.insert_raw(admin_menu_content, index+1, w.depth_at(index))
58
+ say_status(:menu, menu_path, :green)
54
59
  end
55
60
  end
56
61
  rescue Errno::ENOENT
57
62
  # This will raise an error if the navbar file isn't present
58
- say_status :skipped, :effective_menus, :yellow
63
+ say_status :skipped, :menu, :yellow
59
64
  end
60
65
  end
61
66
 
62
67
  private
63
68
 
64
69
  def menu_content
70
+ ["= nav_link_to '#{resource.plural_name.titleize}', #{menu_path}"]
71
+ end
72
+
73
+ def admin_menu_content
65
74
  [
66
75
  "\n",
67
76
  "- if can? :manage, #{resource.class_name}",
68
- " %li= link_to '#{resource.plural_name.titleize}', #{resource.action_path(:index)}"
77
+ " = nav_link_to '#{resource.plural_name.titleize}', #{menu_path}"
69
78
  ]
70
79
  end
71
80
 
72
- def effective_menus_content
73
- "item '#{resource.plural_name.titleize}', :#{resource.action_path(:index)}"
81
+ def menu_path
82
+ [resource.namespace, resource.plural_name, 'path'].compact * '_'
74
83
  end
75
-
76
84
  end
77
85
  end
78
86
  end
@@ -40,9 +40,9 @@ module Effective
40
40
  if content.length == 1 && w.find { |line, depth| depth == 1 && line == content.first }
41
41
  say_status :identical, content.first, :blue
42
42
  else
43
- w.insert_after_last(content, content_depth: blocks.length) { |line, depth| depth == 1 && line.start_with?('resources') } ||
44
- w.insert_before_last(content, content_depth: blocks.length) { |line, depth| depth == 1 && line.start_with?('root') } ||
45
- w.insert_before_last(content, content_depth: blocks.length) { |line, depth| line == 'end' }
43
+ w.insert_after_last(content, content_depth: 0) { |line, depth| depth == 1 && line.start_with?('resources') } ||
44
+ w.insert_before_last(content, content_depth: 0) { |line, depth| depth == 1 && line.start_with?('root') } ||
45
+ w.insert_before_last(content, content_depth: 0) { |line, depth| line == 'end' }
46
46
 
47
47
  say_status :route, content.join("\n\t\t")
48
48
  end
@@ -30,9 +30,9 @@ module Effective
30
30
  Rails::Generators.invoke('effective:ability', [name] + invoked_actions)
31
31
  end
32
32
 
33
- # def invoke_menu
34
- # Rails::Generators.invoke('effective:menu', [name])
35
- # end
33
+ def invoke_menu
34
+ Rails::Generators.invoke('effective:menu', [name])
35
+ end
36
36
 
37
37
  def invoke_datatable
38
38
  unless invoked_actions.include?('index')
@@ -41,9 +41,9 @@ module Effective
41
41
  Rails::Generators.invoke('effective:ability', [name] + invoked_actions)
42
42
  end
43
43
 
44
- # def invoke_menu
45
- # Rails::Generators.invoke('effective:menu', [name])
46
- # end
44
+ def invoke_menu
45
+ Rails::Generators.invoke('effective:menu', [name])
46
+ end
47
47
 
48
48
  def invoke_datatable
49
49
  unless invoked_actions.include?('index')
@@ -1,7 +1,9 @@
1
1
  class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.namespace.try(:classify).presence, ApplicationController].compact.join('::') %>
2
+ <% unless resource.namespace == 'admin' -%>
2
3
  before_action :authenticate_user! # Devise enforce user is present
3
-
4
+ <% end -%>
4
5
  <% if use_effective_resources -%>
6
+
5
7
  include Effective::CrudController
6
8
 
7
9
  <% end -%>
@@ -116,6 +118,12 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
116
118
  <% end -%>
117
119
  protected
118
120
 
121
+ <% if resource.namespace == 'admin' -%>
122
+ def <%= resource.name %>_params
123
+ params.require(:<%= resource.name %>).permit!
124
+ end
125
+ <% end -%>
126
+ <% if resource.namespace != 'admin' -%>
119
127
  def <%= resource.name %>_params
120
128
  params.require(:<%= resource.name %>).permit(:id,
121
129
  <% attributes.each_slice(8).with_index do |slice, index| -%>
@@ -127,6 +135,7 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
127
135
  <% end -%>
128
136
  )
129
137
  end
138
+ <% end -%>
130
139
 
131
140
  <% if !use_effective_resources -%>
132
141
  def redirect_path
@@ -26,7 +26,7 @@ class <%= resource.namespaced_class_name.pluralize %>Datatable < Effective::Data
26
26
  <% if non_crud_actions.present? -%>
27
27
  actions_col do |<%= singular_name %>|
28
28
  <% non_crud_actions.each_with_index do |action, index| -%>
29
- glyphicon_to('ok', <%= resource.action_path_helper(action, at: false) %>, title: '<%= action.titleize %>')<%= ' +' if (index+1) < (invoked_actions - crud_actions).length %>
29
+ icon_to('ok', <%= resource.action_path_helper(action, at: false) %>, title: '<%= action.titleize %>')<%= ' +' if (index+1) < (invoked_actions - crud_actions).length %>
30
30
  <% end -%>
31
31
  end
32
32
  <% else -%>
@@ -35,7 +35,7 @@ class <%= resource.namespaced_class_name.pluralize %>Datatable < Effective::Data
35
35
  end
36
36
 
37
37
  collection do
38
- <%= resource.class_name %>.all
38
+ <%= resource.class_name %>.deep.all
39
39
  end
40
40
 
41
41
  end
@@ -1,4 +1,4 @@
1
- = simple_form_for(<%= form_for %>) do |f|
1
+ = effective_form_with(model: <%= form_for %>) do |f|
2
2
  <% resource.belong_tos.each do |reference| -%>
3
3
  <%= render_field(reference, depth: 1) %>
4
4
  <% end -%>
@@ -6,11 +6,4 @@
6
6
  <%= render_field(attribute, depth: 1) %>
7
7
  <% end -%>
8
8
 
9
- <% if defined?(EffectiveResources) -%>
10
- = simple_form_submit(f)
11
- <% else -%>
12
- .form-actions
13
- = f.button :submit, 'Save', data: { disable_with: 'Saving...' }
14
- = f.button :submit, 'Save and Continue', data: { disable_with: 'Saving...' }
15
- = f.button :submit, 'Save and Add New', data: { disable_with: 'Saving...' }
16
- <% end -%>
9
+ = effective_submit(f)
@@ -1 +1 @@
1
- = f.input :<%= reference.foreign_key.presence || (reference.name.to_s + '_id') %>, as: :effective_select, collection: <%= reference.name.to_s.classify %>.all
1
+ = f.select :<%= reference.foreign_key.presence || (reference.name.to_s + '_id') %>, <%= reference.name.to_s.classify %>.sorted.all
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>, as: :boolean
1
+ = f.check_box :<%= attribute.name %>
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>, as: :effective_date_picker
1
+ = f.date_field :<%= attribute.name %>
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>, as: :effective_date_time_picker
1
+ = f.datetime_field :<%= attribute.name %>
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>
1
+ = f.number_field :<%= attribute.name %>
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>
1
+ = f.text_field :<%= attribute.name %>
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>
1
+ = f.number_field :<%= attribute.name %>
@@ -0,0 +1 @@
1
+ = f.select :<%= reference.foreign_key.presence || (reference.name.to_s + '_id') %>, <%= reference.name.to_s.classify %>.sorted.all
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>
1
+ = f.text_field :<%= attribute.name %>
@@ -1 +1 @@
1
- = f.input :<%= attribute.name %>, as: :text
1
+ = f.text_area :<%= attribute.name %>
@@ -1,12 +1,12 @@
1
1
  .row.nested-fields
2
2
  <% nested_resource.belong_tos_attributes.each do |attribute| -%>
3
- .col-sm-2<%= render_field(attribute, depth: 1).sub(' ', '') -%>
3
+ .col-md-2<%= render_field(attribute, depth: 1).sub(' ', '') -%>
4
4
 
5
5
  <% end -%>
6
6
  <% nested_resource.attributes.each do |attribute| -%>
7
- .col-sm-2<%= render_field(attribute, depth: 1).sub(' ', '') -%>
7
+ .col-md-2<%= render_field(attribute, depth: 1).sub(' ', '') -%>
8
8
 
9
9
  <% end -%>
10
- .col-sm-1
10
+ .col-md-1
11
11
  = link_to_remove_association(f, data: { confirm: 'Really remove?'}) do
12
12
  %span.glyphicon.glyphicon-trash
@@ -2,7 +2,7 @@ module CsvImporters
2
2
  class <%= klass %>Importer < Effective::CSVImporter
3
3
  def columns
4
4
  {<% columns.each_with_index do |column, index| %>
5
- <%= column.to_s.underscore.gsub(' ', '_').to_sym %>: <%= (letters[index] || index) %><%= ',' unless (index+1) == columns.length %><% end %>
5
+ <%= column.to_s.underscore.tap { |name| [' ', '/', '(', ')', '__'].each { |str| name.gsub!(str, '_') } }.to_sym %>: <%= (letters[index] || index) %><%= ',' unless (index+1) == columns.length %><% end %>
6
6
  }
7
7
  end
8
8
 
@@ -0,0 +1,16 @@
1
+ = simple_form_for(<%= form_for %>) do |f|
2
+ <% resource.belong_tos.each do |reference| -%>
3
+ <%= render_field(reference, depth: 1) %>
4
+ <% end -%>
5
+ <% attributes.each do |attribute| -%>
6
+ <%= render_field(attribute, depth: 1) %>
7
+ <% end -%>
8
+
9
+ <% if defined?(EffectiveResources) -%>
10
+ = simple_form_submit(f)
11
+ <% else -%>
12
+ .form-actions
13
+ = f.button :submit, 'Save', data: { disable_with: 'Saving...' }
14
+ = f.button :submit, 'Save and Continue', data: { disable_with: 'Saving...' }
15
+ = f.button :submit, 'Save and Add New', data: { disable_with: 'Saving...' }
16
+ <% end -%>
@@ -0,0 +1 @@
1
+ = f.input :<%= reference.foreign_key.presence || (reference.name.to_s + '_id') %>, as: :effective_select, collection: <%= reference.name.to_s.classify %>.all
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>, as: :boolean
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>, as: :effective_date_picker
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>, as: :effective_date_time_picker
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>
@@ -0,0 +1,11 @@
1
+ #<%= nested_resource.plural_name %>
2
+ = f.simple_fields_for :<%= nested_resource.plural_name %>, f.object.<%= nested_resource.plural_name %> do |fields|
3
+ = render '<%= [resource.namespace.presence, nested_resource.plural_name].compact.join('/') %>/fields', f: fields
4
+
5
+ - if can? :update, f.object
6
+ = f.error :<%= nested_resource.plural_name %>, class: 'alert alert-danger'
7
+ .links
8
+ = link_to_add_association(f, :<%= nested_resource.plural_name %>, partial: '<%= [resource.namespace.presence, nested_resource.plural_name].compact.join('/') %>/fields') do
9
+ %button.btn.btn-success
10
+ %span.glyphicon.glyphicon-plus-sign
11
+ Add another <%= nested_resource.name.to_s.titleize.downcase %>
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>
@@ -0,0 +1 @@
1
+ = f.input :<%= attribute.name %>, as: :text
@@ -0,0 +1,12 @@
1
+ .row.nested-fields
2
+ <% nested_resource.belong_tos_attributes.each do |attribute| -%>
3
+ .col-sm-2<%= render_field(attribute, depth: 1).sub(' ', '') -%>
4
+
5
+ <% end -%>
6
+ <% nested_resource.attributes.each do |attribute| -%>
7
+ .col-sm-2<%= render_field(attribute, depth: 1).sub(' ', '') -%>
8
+
9
+ <% end -%>
10
+ .col-sm-1
11
+ = link_to_remove_association(f, data: { confirm: 'Really remove?'}) do
12
+ %span.glyphicon.glyphicon-trash
@@ -0,0 +1,33 @@
1
+ = simple_form_for(<%= form_for %>) do |f|
2
+ %div{role: 'tabpanel'}
3
+ %ul.nav.nav-tabs{role: 'tablist'}
4
+ %li.active{role: 'presentation'}
5
+ %a{'data-toggle': 'tab', role: 'tab', 'aria-controls': '<%= resource.name %>-tab', href: '#<%= resource.name %>-tab'}
6
+ <%= resource.human_name.titleize %>
7
+
8
+ <% resource.nested_resources.each do |nested_resource| -%>
9
+ %li{role: 'presentation'}
10
+ %a{'data-toggle': 'tab', role: 'tab', 'aria-controls': '<%= nested_resource.plural_name %>-tab', href: '#<%= nested_resource.plural_name %>-tab'}
11
+ <%= nested_resource.plural_name.titleize %>
12
+
13
+ <% end -%>
14
+ %br
15
+ .tab-content
16
+ #<%= resource.name %>-tab.tab-pane.active{role: 'tabpanel'}
17
+ = render 'form_<%= resource.name %>', f: f
18
+
19
+ <% resource.nested_resources.each do |nested_resource| -%>
20
+ #<%= nested_resource.plural_name %>-tab.tab-pane{role: 'tabpanel'}
21
+ = render 'form_<%= nested_resource.plural_name %>', f: f
22
+ <% end -%>
23
+
24
+ %hr
25
+
26
+ .form-actions
27
+ <% if defined?(EffectiveResources) -%>
28
+ = simple_form_submit(f)
29
+ <% else -%>
30
+ = f.button :submit, 'Save', data: { disable_with: 'Saving...' }
31
+ = f.button :submit, 'Save and Continue', data: { disable_with: 'Saving...' }
32
+ = f.button :submit, 'Save and Add New', data: { disable_with: 'Saving...' }
33
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ <% resource.belong_tos.each do |reference| -%>
2
+ <%= render_field(reference) %>
3
+ <% end -%>
4
+ <% attributes.each do |attribute| -%>
5
+ <%= render_field(attribute) %>
6
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ %p There are #{pluralize(f.object.<%= nested_resource.plural_name %>.length, '<%= nested_resource.name.to_s.titleize.downcase %>')}.
2
+
3
+ <%= render_field(nested_resource) %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_developer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-23 00:00:00.000000000 Z
11
+ date: 2018-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -48,7 +48,6 @@ files:
48
48
  - MIT-LICENSE
49
49
  - README.md
50
50
  - Rakefile
51
- - app/models/effective/access_denied.rb
52
51
  - app/models/effective/code_writer.rb
53
52
  - app/models/effective/csv_importer.rb
54
53
  - config/effective_developer.rb
@@ -79,6 +78,7 @@ files:
79
78
  - lib/scaffolds/forms/fields/_field_inet.html.haml
80
79
  - lib/scaffolds/forms/fields/_field_integer.html.haml
81
80
  - lib/scaffolds/forms/fields/_field_nested_resource.html.haml
81
+ - lib/scaffolds/forms/fields/_field_select.html.haml
82
82
  - lib/scaffolds/forms/fields/_field_string.html.haml
83
83
  - lib/scaffolds/forms/fields/_field_text.html.haml
84
84
  - lib/scaffolds/forms/fields/_nested_resource_fields.html.haml
@@ -87,6 +87,21 @@ files:
87
87
  - lib/scaffolds/forms/tabpanel/_tab_nested_resource.html.haml
88
88
  - lib/scaffolds/importers/csv_importer.rb
89
89
  - lib/scaffolds/models/model.rb
90
+ - lib/scaffolds/simple_form/default/_form.html.haml
91
+ - lib/scaffolds/simple_form/fields/_field_belongs_to.html.haml
92
+ - lib/scaffolds/simple_form/fields/_field_boolean.html.haml
93
+ - lib/scaffolds/simple_form/fields/_field_date.html.haml
94
+ - lib/scaffolds/simple_form/fields/_field_datetime.html.haml
95
+ - lib/scaffolds/simple_form/fields/_field_decimal.html.haml
96
+ - lib/scaffolds/simple_form/fields/_field_inet.html.haml
97
+ - lib/scaffolds/simple_form/fields/_field_integer.html.haml
98
+ - lib/scaffolds/simple_form/fields/_field_nested_resource.html.haml
99
+ - lib/scaffolds/simple_form/fields/_field_string.html.haml
100
+ - lib/scaffolds/simple_form/fields/_field_text.html.haml
101
+ - lib/scaffolds/simple_form/fields/_nested_resource_fields.html.haml
102
+ - lib/scaffolds/simple_form/tabpanel/_form.html.haml
103
+ - lib/scaffolds/simple_form/tabpanel/_tab_fields.html.haml
104
+ - lib/scaffolds/simple_form/tabpanel/_tab_nested_resource.html.haml
90
105
  - lib/scaffolds/views/_resource.html.haml
91
106
  - lib/scaffolds/views/edit.html.haml
92
107
  - lib/scaffolds/views/index.html.haml
@@ -1,17 +0,0 @@
1
- unless defined?(Effective::AccessDenied)
2
- module Effective
3
- class AccessDenied < StandardError
4
- attr_reader :action, :subject
5
-
6
- def initialize(message = nil, action = nil, subject = nil)
7
- @message = message
8
- @action = action
9
- @subject = subject
10
- end
11
-
12
- def to_s
13
- @message || I18n.t(:'unauthorized.default', :default => 'Access Denied')
14
- end
15
- end
16
- end
17
- end