effective_developer 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/effective/code_writer.rb +5 -0
  3. data/config/effective_developer.rb +3 -0
  4. data/lib/effective_developer/engine.rb +7 -0
  5. data/lib/effective_developer/version.rb +1 -1
  6. data/lib/effective_developer.rb +1 -0
  7. data/lib/generators/effective/controller_generator.rb +1 -21
  8. data/lib/generators/effective/form_generator.rb +26 -25
  9. data/lib/generators/effective/helpers.rb +8 -4
  10. data/lib/generators/effective/migration_generator.rb +2 -2
  11. data/lib/generators/effective/model_generator.rb +2 -6
  12. data/lib/generators/effective/scaffold_controller_generator.rb +1 -1
  13. data/lib/generators/effective/views_generator.rb +0 -14
  14. data/lib/scaffolds/controllers/controller.rb +0 -152
  15. data/lib/scaffolds/datatables/datatable.rb +7 -15
  16. data/lib/scaffolds/forms/fields/_field_boolean.html.haml +1 -1
  17. data/lib/scaffolds/forms/fields/_field_date.html.haml +1 -1
  18. data/lib/scaffolds/forms/fields/_field_datetime.html.haml +1 -1
  19. data/lib/scaffolds/forms/fields/_field_decimal.html.haml +1 -1
  20. data/lib/scaffolds/forms/fields/_field_email.html.haml +1 -0
  21. data/lib/scaffolds/forms/fields/_field_float.html.haml +1 -0
  22. data/lib/scaffolds/forms/fields/_field_hstore.html.haml +1 -0
  23. data/lib/scaffolds/forms/fields/_field_inet.html.haml +1 -1
  24. data/lib/scaffolds/forms/fields/_field_integer.html.haml +1 -1
  25. data/lib/scaffolds/forms/fields/_field_phone.html.haml +1 -0
  26. data/lib/scaffolds/forms/fields/_field_price.html.haml +1 -0
  27. data/lib/scaffolds/forms/fields/_field_string.html.haml +1 -1
  28. data/lib/scaffolds/forms/fields/_field_text.html.haml +1 -1
  29. data/lib/scaffolds/forms/{default → flat}/_form.html.haml +0 -0
  30. data/lib/scaffolds/forms/tabbed/_form.html.haml +15 -0
  31. data/lib/scaffolds/forms/tabbed/_form_resource.html.haml +9 -0
  32. data/lib/scaffolds/models/model.rb +12 -34
  33. data/lib/scaffolds/views/_resource.html.haml +3 -3
  34. metadata +11 -26
  35. data/lib/scaffolds/forms/tabpanel/_form.html.haml +0 -33
  36. data/lib/scaffolds/forms/tabpanel/_tab_fields.html.haml +0 -6
  37. data/lib/scaffolds/forms/tabpanel/_tab_nested_resource.html.haml +0 -3
  38. data/lib/scaffolds/simple_form/default/_form.html.haml +0 -16
  39. data/lib/scaffolds/simple_form/fields/_field_belongs_to.html.haml +0 -1
  40. data/lib/scaffolds/simple_form/fields/_field_boolean.html.haml +0 -1
  41. data/lib/scaffolds/simple_form/fields/_field_date.html.haml +0 -1
  42. data/lib/scaffolds/simple_form/fields/_field_datetime.html.haml +0 -1
  43. data/lib/scaffolds/simple_form/fields/_field_decimal.html.haml +0 -1
  44. data/lib/scaffolds/simple_form/fields/_field_inet.html.haml +0 -1
  45. data/lib/scaffolds/simple_form/fields/_field_integer.html.haml +0 -1
  46. data/lib/scaffolds/simple_form/fields/_field_nested_resource.html.haml +0 -11
  47. data/lib/scaffolds/simple_form/fields/_field_string.html.haml +0 -1
  48. data/lib/scaffolds/simple_form/fields/_field_text.html.haml +0 -1
  49. data/lib/scaffolds/simple_form/fields/_nested_resource_fields.html.haml +0 -12
  50. data/lib/scaffolds/simple_form/tabpanel/_form.html.haml +0 -33
  51. data/lib/scaffolds/simple_form/tabpanel/_tab_fields.html.haml +0 -6
  52. data/lib/scaffolds/simple_form/tabpanel/_tab_nested_resource.html.haml +0 -3
  53. data/lib/scaffolds/views/edit.html.haml +0 -12
  54. data/lib/scaffolds/views/index.html.haml +0 -15
  55. data/lib/scaffolds/views/new.html.haml +0 -3
  56. data/lib/scaffolds/views/show.html.haml +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf305c231784d1c6bce30322420dc57cf142f28a
4
- data.tar.gz: d65e5ccd3796a73b487cffd2d6b76e28fa028371
3
+ metadata.gz: 5a6c65c15c6025e2d82b06fd85be1dedf34a3b23
4
+ data.tar.gz: 9fad65447322c44cac74cfa244304877b2dd468d
5
5
  SHA512:
6
- metadata.gz: f429b820f1e2efac22656c02cb4efee990c2df168d8d8a65621eb9cb4bb294aa14c6170e3cc16266b8efa8032d9ddbb68dc59db79e41cc2a47408739fe1f5f65
7
- data.tar.gz: 11bb3454c678fb367542478eaa4d946a22f5d3f29f8d80201b1d4a011ea20d3afe0c44a6debedd9c6042a5fd834ea454a9a37231b0f3d937d49607d26e93f893
6
+ metadata.gz: db915fe8e34c03a300ce5e5d12f917793415df03305d885743eb8b88080de5125b3f010f049f7ab6852dacc7bf54c5fa58a51d1a77e630139c7af40080a80ffb
7
+ data.tar.gz: 5d8004e9236644ac16e6e80b699f2e9e1e735101552f783d996694b0c0caa461dc59ead50b2f2980f6789481c09bfdd0327eabceae6f869cff9d4a6ce770e231
@@ -1,3 +1,8 @@
1
+ # Effective::CodeWriter.new('Gemfile') do |w|
2
+ # @use_effective_resources = w.find { |line| line.include?('effective_resources') }.present?
3
+ # end
4
+ # end
5
+
1
6
  module Effective
2
7
  class CodeWriter
3
8
 
@@ -1,2 +1,5 @@
1
1
  EffectiveDeveloper.setup do |config|
2
+
3
+ # This doesn't do anything. Yet.
4
+ config.live = true
2
5
  end
@@ -7,5 +7,12 @@ module EffectiveDeveloper
7
7
  # Set up our defaults, as per our initializer template
8
8
  eval File.read("#{config.root}/config/effective_developer.rb")
9
9
  end
10
+
11
+ # Include acts_as_addressable concern and allow any ActiveRecord object to call it
12
+ initializer 'effective_developer.effective_resources' do |app|
13
+ ActiveSupport.on_load :effective_resource do
14
+ end
15
+ end
16
+
10
17
  end
11
18
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -4,6 +4,7 @@ require 'effective_developer/engine'
4
4
  require 'effective_developer/version'
5
5
 
6
6
  module EffectiveDeveloper
7
+ mattr_accessor :live
7
8
 
8
9
  def self.setup
9
10
  yield self
@@ -22,7 +22,7 @@ module Effective
22
22
  end
23
23
 
24
24
  def assign_attributes
25
- @attributes = invoked_attributes.presence || (resource.belong_tos_attributes + resource_attributes)
25
+ @attributes = invoked_attributes.presence || resource.belong_tos_attributes.merge(resource_attributes)
26
26
  self.class.send(:attr_reader, :attributes)
27
27
  end
28
28
 
@@ -30,30 +30,10 @@ module Effective
30
30
  say_status :invoke, :controller, :white
31
31
  end
32
32
 
33
- # Find if effective_resources is in the app's Gemfile
34
- def enable_effective_resources
35
- self.class.send(:attr_reader, :use_effective_resources)
36
-
37
- Effective::CodeWriter.new('Gemfile') do |w|
38
- @use_effective_resources = w.find { |line| line.include?('effective_resources') }.present?
39
- end
40
- end
41
-
42
33
  def create_controller
43
34
  template 'controllers/controller.rb', resource.controller_file
44
35
  end
45
36
 
46
- protected
47
-
48
- def permitted_param_for(attribute_name)
49
- case attribute_name
50
- when 'roles'
51
- 'roles: EffectiveRoles.permitted_params'
52
- else
53
- ':' + attribute_name
54
- end
55
- end
56
-
57
37
  end
58
38
  end
59
39
  end
@@ -6,6 +6,8 @@
6
6
  # rails generate effective:form Thing
7
7
  # rails generate effective:form Thing name:string description:text
8
8
 
9
+ # rails generate effective:form Thing --tabbed false
10
+
9
11
  module Effective
10
12
  module Generators
11
13
  class FormGenerator < Rails::Generators::NamedBase
@@ -16,6 +18,7 @@ module Effective
16
18
  desc 'Creates a _form.html.haml in your app/views/model/ folder.'
17
19
 
18
20
  argument :attributes, type: :array, default: [], banner: 'field[:type] field[:type]'
21
+ class_option :tabbed, type: :string, default: 'true'
19
22
 
20
23
  def assign_attributes
21
24
  @attributes = invoked_attributes.presence || resource_attributes
@@ -26,35 +29,21 @@ module Effective
26
29
  say_status :invoke, :form, :white
27
30
  end
28
31
 
29
- def create_default_form
30
- if resource.nested_resources.blank?
31
- template "#{forms_path}/default/_form.html.haml", resource.view_file('form', partial: true)
32
+ def create_flat_form
33
+ if options[:tabbed] == 'false'
34
+ template 'forms/flat/_form.html.haml', resource.view_file('form', partial: true)
32
35
  end
33
36
  end
34
37
 
35
- def create_tabpanel_form
36
- if resource.nested_resources.present?
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
- end
40
-
41
- class_eval { attr_accessor :nested_resource }
42
-
43
- resource.nested_resources.each do |nested_resource|
44
- @nested_resource = nested_resource
45
- template "#{forms_path}/tabpanel/_tab_nested_resource.html.haml", resource.view_file("form_#{nested_resource.plural_name}", partial: true)
46
-
47
- @nested_resource = Effective::Resource.new(nested_resource)
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')
38
+ def create_tabbed_form
39
+ if options[:tabbed] == 'true'
40
+ template 'forms/tabbed/_form.html.haml', resource.view_file('form', partial: true)
41
+ template 'forms/tabbed/_form_resource.html.haml', resource.flat_view_file("form_#{resource.name}", partial: true)
49
42
  end
50
43
  end
51
44
 
52
45
  protected
53
46
 
54
- def forms_path
55
- @forms_path ||= (defined?(EffectiveBootstrap) ? 'forms' : 'simple_form')
56
- end
57
-
58
47
  def form_for
59
48
  if resource.namespaces.blank?
60
49
  resource.name
@@ -78,13 +67,25 @@ module Effective
78
67
  when Effective::Resource
79
68
  b.local_variable_set(:nested_resource, attribute)
80
69
  'nested_resource'
81
- else
82
- b.local_variable_set(:attribute, attribute)
83
- (attribute.type || :string).to_s
70
+ else # [:name, [:string]]
71
+ name = attribute.first.to_s
72
+ datatype = ((attribute.last || []).first || :string).to_s
73
+
74
+ b.local_variable_set(:attribute, name)
75
+
76
+ if name.include?('price')
77
+ 'price'
78
+ elsif name.include?('_url')
79
+ 'url'
80
+ elsif name.include?('email')
81
+ 'email'
82
+ else
83
+ datatype
84
+ end
84
85
  end
85
86
 
86
87
  html = ERB.new(
87
- File.read("#{File.dirname(__FILE__)}/../../scaffolds/#{forms_path}/fields/_field_#{partial}.html.haml")
88
+ File.read("#{File.dirname(__FILE__)}/../../scaffolds/forms/fields/_field_#{partial}.html.haml")
88
89
  ).result(b).split("\n").map { |line| (' ' * depth) + line }
89
90
 
90
91
  html.length > 1 ? (html.join("\n") + "\n") : html.join
@@ -33,11 +33,15 @@ module Effective
33
33
  end
34
34
 
35
35
  # As per the command line invoked actions. These are Rails Generated Attributes
36
+ # { :name => [:string], ... }
36
37
  def invoked_attributes
37
38
  if respond_to?(:attributes)
38
- attributes
39
+ attributes.inject({}) { |h, att| h[att.name.to_sym] = [att.type]; h }
39
40
  else
40
- Array(options.attributes).compact.map { |att| Rails::Generators::GeneratedAttribute.parse(att) }
41
+ Array(options.attributes).compact.inject({}) do |h, att|
42
+ (name, type) = att.split(':')
43
+ h[name.to_sym] = [type.to_sym] if name && type; h
44
+ end
41
45
  end
42
46
  end
43
47
 
@@ -47,7 +51,7 @@ module Effective
47
51
 
48
52
  # Turns the GeneratedAttribute or Effective::Attribute into an array of strings
49
53
  def invokable(attributes)
50
- attributes.map { |att| "#{att.name}:#{att.type}" }
54
+ attributes.map { |name, (type, _)| "#{name}:#{type}" }
51
55
  end
52
56
 
53
57
  def resource_attributes(all: false)
@@ -69,7 +73,7 @@ module Effective
69
73
  klass_attributes = resource.klass_attributes(all: all)
70
74
  end
71
75
 
72
- klass_attributes.presence || resource.written_attributes
76
+ klass_attributes.presence || resource.model_attributes
73
77
  end
74
78
 
75
79
  end
@@ -26,8 +26,8 @@ module Effective
26
26
  Rails::Generators.invoke('migration', ["create_#{plural_name}"] + (invokable(invoked_attributes) | timestamps))
27
27
  elsif resource.klass_attributes.present?
28
28
  raise 'klass_attributes already exist. We cant migrate (yet). Exiting.'
29
- elsif resource.written_attributes.present?
30
- Rails::Generators.invoke('migration', ["create_#{plural_name}"] + invokable(resource.belong_tos_attributes) + (invokable(resource.written_attributes) | timestamps))
29
+ elsif resource.model_attributes.present?
30
+ Rails::Generators.invoke('migration', ["create_#{plural_name}"] + invokable(resource.belong_tos_attributes) + (invokable(resource.model_attributes) | timestamps))
31
31
  else
32
32
  raise 'You need to specify some attributes or have a model file present'
33
33
  end
@@ -30,15 +30,11 @@ module Effective
30
30
  end
31
31
 
32
32
  def to_s_attribute
33
- attributes.find { |att| ['display_name', 'name', 'title', 'subject'].include?(att.name) }
34
- end
35
-
36
- def archived_attribute
37
- attributes.find { |att| att.name == 'archived' && att.type == :boolean }
33
+ [:display_name, :name, :title, :subject].find { |att| invoked_attributes.key?(att) }
38
34
  end
39
35
 
40
36
  def max_attribute_name_length
41
- @max_attribute_name_length ||= (attributes.map { |att| att.name.length }.max || 0)
37
+ @max_attribute_name_length ||= (invoked_attributes.keys.map { |att| att.to_s.length }.max || 0)
42
38
  end
43
39
 
44
40
  end
@@ -51,7 +51,7 @@ module Effective
51
51
  say_status(:skipped, :form, :yellow) and return
52
52
  end
53
53
 
54
- Rails::Generators.invoke('effective:form', [name] + invoked_attributes)
54
+ Rails::Generators.invoke('effective:form', [name] + invoked_attributes_args)
55
55
  end
56
56
 
57
57
  end
@@ -26,25 +26,11 @@ module Effective
26
26
  end
27
27
 
28
28
  def create_views
29
- (invoked_actions & available_actions).each do |action|
30
- template "views/#{action}.html.haml", resource.view_file(action)
31
- end
32
-
33
29
  if invoked_actions.include?('show') || non_crud_actions.present?
34
30
  template 'views/_resource.html.haml', resource.view_file(resource.name, partial: true)
35
31
  end
36
32
  end
37
33
 
38
- private
39
-
40
- def available_actions
41
- if defined?(EffectiveResources) # We don't need any views!
42
- []
43
- else
44
- %w(index new show edit)
45
- end
46
- end
47
-
48
34
  end
49
35
  end
50
36
  end
@@ -1,155 +1,3 @@
1
1
  class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.namespace.try(:classify).presence, ApplicationController].compact.join('::') %>
2
- <% unless resource.namespace == 'admin' -%>
3
- before_action :authenticate_user! # Devise enforce user is present
4
- <% end -%>
5
- <% if use_effective_resources -%>
6
-
7
2
  include Effective::CrudController
8
-
9
- <% end -%>
10
- <% if actions.delete('index') && !use_effective_resources -%>
11
- def index
12
- @page_title = '<%= resource.plural_name.titleize %>'
13
- authorize! :index, <%= resource.class_name %>
14
-
15
- @datatable = <%= resource.namespaced_class_name.pluralize %>Datatable.new(self)
16
- end
17
-
18
- <% end -%>
19
- <% if actions.delete('new') && !use_effective_resources -%>
20
- def new
21
- @<%= resource.name %> = <%= resource.class_name %>.new
22
-
23
- @page_title = 'New <%= resource.human_name %>'
24
- authorize! :new, @<%= resource.name %>
25
- end
26
-
27
- <% end -%>
28
- <% if actions.delete('create') && !use_effective_resources -%>
29
- def create
30
- @<%= resource.name %> = <%= resource.class_name %>.new(<%= resource.name %>_params)
31
-
32
- @page_title = 'New <%= resource.human_name %>'
33
- authorize! :create, @<%= resource.name %>
34
-
35
- if @<%= resource.name %>.save
36
- flash[:success] = 'Successfully created <%= resource.name %>'
37
- redirect_to(redirect_path)
38
- else
39
- flash.now[:danger] = "Unable to create <%= resource.name %>: #{@<%= resource.name %>.errors.full_messages.to_sentence}"
40
- render :new
41
- end
42
- end
43
-
44
- <% end -%>
45
- <% if actions.delete('show') && !use_effective_resources -%>
46
- def show
47
- @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
48
-
49
- @page_title = @<%= resource.name %>.to_s
50
- authorize! :show, @<%= resource.name %>
51
- end
52
-
53
- <% end -%>
54
- <% if actions.delete('edit') && !use_effective_resources -%>
55
- def edit
56
- @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
57
-
58
- @page_title = "Edit #{@<%= resource.name %>}"
59
- authorize! :edit, @<%= resource.name %>
60
- end
61
-
62
- <% end -%>
63
- <% if actions.delete('update') && !use_effective_resources -%>
64
- def update
65
- @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
66
-
67
- @page_title = "Edit #{@<%= resource.name %>}"
68
- authorize! :update, @<%= resource.name %>
69
-
70
- if @<%= resource.name %>.update_attributes(<%= resource.name %>_params)
71
- flash[:success] = 'Successfully updated <%= resource.name %>'
72
- redirect_to(redirect_path)
73
- else
74
- flash.now[:danger] = "Unable to update <%= resource.name %>: #{@<%= resource.name %>.errors.full_messages.to_sentence}"
75
- render :edit
76
- end
77
- end
78
-
79
- <% end -%>
80
- <% if actions.delete('destroy') && !use_effective_resources -%>
81
- def destroy
82
- @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
83
- authorize! :destroy, @<%= resource.name %>
84
-
85
- if @<%= resource.name %>.destroy
86
- flash[:success] = 'Successfully deleted <%= resource.name %>'
87
- else
88
- flash[:danger] = "Unable to delete <%= resource.name %>: #{@<%= resource.name %>.errors.full_messages.to_sentence}"
89
- end
90
-
91
- redirect_to <%= resource.index_path %>
92
- end
93
-
94
- <% end -%>
95
- <% if actions.delete('unarchive') -%>
96
- def unarchive
97
- @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
98
- authorize! :unarchive, @<%= resource.name %>
99
-
100
- if @<%= resource.name %>.unarchive
101
- flash[:success] = 'Successfully restored <%= resource.name %>'
102
- else
103
- flash.now[:danger] = "Unable to restore <%= resource.name %>: #{@<%= resource.name %>.errors.full_messages.to_sentence}"
104
- end
105
-
106
- redirect_to <%= resource.index_path %>
107
- end
108
-
109
- <% end -%>
110
- <% actions.each do |action| -%>
111
- def <%= action %>
112
- @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
113
-
114
- @page_title = "<%= action.titleize %> #{@<%= resource.name %>}"
115
- authorize! :<%= action %>, @<%= resource.name %>
116
- end
117
-
118
- <% end -%>
119
- protected
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' -%>
127
- def <%= resource.name %>_params
128
- params.require(:<%= resource.name %>).permit(:id,
129
- <% attributes.each_slice(8).with_index do |slice, index| -%>
130
- <%= slice.map { |att| permitted_param_for(att.name) }.join(', ') %><%= ',' if (((index+1) * 8) < attributes.length || resource.nested_resources.present?) %>
131
- <% end -%>
132
- <% resource.nested_resources.each_with_index do |nested_resource, index| -%>
133
- <% nested = Effective::Resource.new(nested_resource) -%>
134
- <%= nested.name %>_attributes: [:id, :_destroy, <%= (nested.belong_tos_attributes + nested.attributes).map { |att| ':' + att.name.to_s }.join(', ') %>]<%= ',' if index < resource.nested_resources.length-1 %>
135
- <% end -%>
136
- )
137
- end
138
- <% end -%>
139
-
140
- <% if !use_effective_resources -%>
141
- def redirect_path
142
- case params[:commit].to_s
143
- when 'Save'
144
- <%= resource.edit_path_helper %>
145
- when 'Save and Continue'
146
- <%= resource.index_path_helper %>
147
- when 'Save and Add New'
148
- <%= resource.new_path_helper %>
149
- else
150
- raise 'Unexpected redirect path'
151
- end
152
- end
153
-
154
- <% end -%>
155
3
  end
@@ -1,37 +1,29 @@
1
1
  class <%= resource.namespaced_class_name.pluralize %>Datatable < Effective::Datatable
2
2
 
3
3
  datatable do
4
- order :<%= (attributes.find { |att| att.name == 'updated_at' } || attributes.first).name %>
4
+ length 25
5
+ order :<%= (attributes[:updated_at] ? :updated_at : attributes.keys.first) %>
5
6
 
6
- <% if attributes.find { |att| att.name == 'updated_at' } -%>
7
+ <% if attributes[:updated_at] -%>
7
8
  col :updated_at, visible: false
8
9
  <% end -%>
9
- <% if attributes.find { |att| att.name == 'created_at' } -%>
10
+ <% if attributes[:created_at] -%>
10
11
  col :created_at, visible: false
11
12
  <% end -%>
12
- <% if attributes.find { |att| att.name == 'id' } -%>
13
13
  col :id, visible: false
14
14
 
15
- <% end -%>
16
15
  <% resource.belong_tos.each do |reference| -%>
17
16
  col :<%= reference.name %>
18
17
  <% end -%>
19
18
  <% resource.nested_resources.each do |reference| -%>
20
19
  col :<%= reference.name %>
21
20
  <% end -%>
22
- <% attributes.reject { |att| ['created_at', 'updated_at', 'id'].include?(att.name) }.each do |attribute| -%>
23
- col :<%= attribute.name %>
24
- <% end -%>
25
21
 
26
- <% if non_crud_actions.present? -%>
27
- actions_col do |<%= singular_name %>|
28
- <% non_crud_actions.each_with_index do |action, index| -%>
29
- icon_to('ok', <%= resource.action_path_helper(action, at: false) %>, title: '<%= action.titleize %>')<%= ' +' if (index+1) < (invoked_actions - crud_actions).length %>
22
+ <% attributes.except(:created_at, :updated_at, :id).each do |name, _| -%>
23
+ col :<%= name %>
30
24
  <% end -%>
31
- end
32
- <% else -%>
25
+
33
26
  actions_col
34
- <% end -%>
35
27
  end
36
28
 
37
29
  collection do
@@ -1 +1 @@
1
- = f.check_box :<%= attribute.name %>
1
+ = f.check_box :<%= attribute %>
@@ -1 +1 @@
1
- = f.date_field :<%= attribute.name %>
1
+ = f.date_field :<%= attribute %>
@@ -1 +1 @@
1
- = f.datetime_field :<%= attribute.name %>
1
+ = f.datetime_field :<%= attribute %>
@@ -1 +1 @@
1
- = f.number_field :<%= attribute.name %>
1
+ = f.number_field :<%= attribute %>
@@ -0,0 +1 @@
1
+ = f.email_field :<%= attribute %>
@@ -0,0 +1 @@
1
+ = f.number_field :<%= attribute %>
@@ -0,0 +1 @@
1
+ = f.text_field :<%= attribute %>
@@ -1 +1 @@
1
- = f.text_field :<%= attribute.name %>
1
+ = f.text_field :<%= attribute %>
@@ -1 +1 @@
1
- = f.number_field :<%= attribute.name %>
1
+ = f.number_field :<%= attribute %>
@@ -0,0 +1 @@
1
+ = f.phone_field :<%= attribute %>
@@ -0,0 +1 @@
1
+ = f.price_field :<%= attribute %>
@@ -1 +1 @@
1
- = f.text_field :<%= attribute.name %>
1
+ = f.text_field :<%= attribute %>
@@ -1 +1 @@
1
- = f.text_area :<%= attribute.name %>
1
+ = f.text_area :<%= attribute %>
@@ -0,0 +1,15 @@
1
+ = tabs do
2
+ = tab '<%= resource.human_name.titleize %>' do
3
+ = render '/<%= resource.plural_name %>/form_<%= resource.name %>', <%= resource.name %>: <%= resource.name %>, namespace: <%= resource.namespace ? ":#{resource.namespace}" : 'nil' %>
4
+
5
+ <%- if resource.nested_resources.present? || resource.instance.respond_to?(:log_changes_datatable) %>
6
+ - if <%= resource.name %>.persisted?
7
+ <%- resource.nested_resources.each do |nested_resource| -%>
8
+ = tab '<%= nested_resource.plural_name.titleize %>' do
9
+ = render_datatable(<%= nested_resource.klass.name %>Datatable.new(<%= resource.name %>_id: <%= resource.name %>.id))
10
+ <%- end -%>
11
+ <%- if resource.instance.respond_to?(:log_changes_datatable) -%>
12
+ = tab 'Logs' do
13
+ = render_datatable(<%= resource.name %>.log_changes_datatable)
14
+ <% end -%>
15
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ = effective_form_with(model: [(namespace if defined?(namespace)), <%= resource.name %>]) 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
+ = effective_submit(f)
@@ -1,50 +1,28 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= resource.class_name %> < <%= parent_class_name.classify %>
3
- <% attributes.select(&:reference?).each do |attribute| -%>
4
- belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
5
- <% end -%>
6
- <% if attributes.all? { |attribute| attribute.respond_to?(:token?) } -%>
7
- <% attributes.select(&:token?).each do |attribute| -%>
8
- has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
9
- <% end -%>
10
- <% end -%>
11
- <% if attributes.any? { |att| att.respond_to?(:password_digest?) && att.password_digest? } -%>
12
- has_secure_password
3
+ <% resource.belong_tos.each do || ass -%>
4
+ belongs_to :<%= ass.name %><%= ', polymorphic: true' if ass.polymorphic? %>
13
5
  <% end -%>
14
6
 
15
- # Attributes
16
- <% attributes.each do |attribute| -%>
17
- # <%= attribute.name.ljust(max_attribute_name_length) %> :<%= attribute.type %>
7
+ effective_resource do
8
+ <% invoked_attributes.each do |name, (type, _)| -%>
9
+ <%= name.to_s.ljust(max_attribute_name_length) %> :<%= type %>
18
10
  <% end -%>
19
- <% if archived_attribute.present? -%>
11
+ end
20
12
 
21
- scope :<%= plural_table_name %>, -> { where(archived: false) }
22
- scope :archived, -> { where(archived: true) }
23
- <% end -%>
13
+ scope :deep, -> { <%= resource.class_name %>.all }
24
14
 
25
- <% attributes.each do |attribute| -%>
26
- validates :<%= attribute.name %>, presence: true
15
+ <% invoked_attributes.each do |name, (type, _)| -%>
16
+ validates :<%= name %>, presence: true
27
17
  <% end -%>
28
18
 
29
- <% if to_s_attribute.present? -%>
30
- def to_s
31
- <%= to_s_attribute.name %> || 'New <%= resource.human_name %>'
32
- end
33
- <% else -%>
34
19
  def to_s
20
+ <% if to_s_attribute.present? -%>
21
+ <%= to_s_attribute %> || 'New <%= resource.human_name %>'
22
+ <% else %>
35
23
  '<%= resource.human_name %>'
36
- end
37
24
  <% end -%>
38
- <% if archived_attribute.present? -%>
39
-
40
- def destroy
41
- update_column(:archived, true) # This intentionally skips validation
42
25
  end
43
26
 
44
- def unarchive
45
- update_column(:archived, false) # This intentionally skips validation
46
- end
47
- <% end -%>
48
-
49
27
  end
50
28
  <% end -%>
@@ -5,8 +5,8 @@
5
5
  %th <%= reference.name.to_s.titleize %>
6
6
  %td= <%= resource.name %>.<%= reference.name %>
7
7
  <% end -%>
8
- <% attributes.each do |attribute| -%>
8
+ <% attributes.each do |name, (type, _)| -%>
9
9
  %tr
10
- %th <%= attribute.name.titleize %>
11
- %td= <%= resource.name %>.<%= attribute.name %>
10
+ %th <%= name.to_s.titleize %>
11
+ %td= <%= resource.name %>.<%= name %>
12
12
  <% end -%>
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.3.0
4
+ version: 0.4.0
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-07-12 00:00:00.000000000 Z
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -69,44 +69,29 @@ files:
69
69
  - lib/generators/effective_developer/install_generator.rb
70
70
  - lib/scaffolds/controllers/controller.rb
71
71
  - lib/scaffolds/datatables/datatable.rb
72
- - lib/scaffolds/forms/default/_form.html.haml
73
72
  - lib/scaffolds/forms/fields/_field_belongs_to.html.haml
74
73
  - lib/scaffolds/forms/fields/_field_boolean.html.haml
75
74
  - lib/scaffolds/forms/fields/_field_date.html.haml
76
75
  - lib/scaffolds/forms/fields/_field_datetime.html.haml
77
76
  - lib/scaffolds/forms/fields/_field_decimal.html.haml
77
+ - lib/scaffolds/forms/fields/_field_email.html.haml
78
+ - lib/scaffolds/forms/fields/_field_float.html.haml
79
+ - lib/scaffolds/forms/fields/_field_hstore.html.haml
78
80
  - lib/scaffolds/forms/fields/_field_inet.html.haml
79
81
  - lib/scaffolds/forms/fields/_field_integer.html.haml
80
82
  - lib/scaffolds/forms/fields/_field_nested_resource.html.haml
83
+ - lib/scaffolds/forms/fields/_field_phone.html.haml
84
+ - lib/scaffolds/forms/fields/_field_price.html.haml
81
85
  - lib/scaffolds/forms/fields/_field_select.html.haml
82
86
  - lib/scaffolds/forms/fields/_field_string.html.haml
83
87
  - lib/scaffolds/forms/fields/_field_text.html.haml
84
88
  - lib/scaffolds/forms/fields/_nested_resource_fields.html.haml
85
- - lib/scaffolds/forms/tabpanel/_form.html.haml
86
- - lib/scaffolds/forms/tabpanel/_tab_fields.html.haml
87
- - lib/scaffolds/forms/tabpanel/_tab_nested_resource.html.haml
89
+ - lib/scaffolds/forms/flat/_form.html.haml
90
+ - lib/scaffolds/forms/tabbed/_form.html.haml
91
+ - lib/scaffolds/forms/tabbed/_form_resource.html.haml
88
92
  - lib/scaffolds/importers/csv_importer.rb
89
93
  - 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
105
94
  - lib/scaffolds/views/_resource.html.haml
106
- - lib/scaffolds/views/edit.html.haml
107
- - lib/scaffolds/views/index.html.haml
108
- - lib/scaffolds/views/new.html.haml
109
- - lib/scaffolds/views/show.html.haml
110
95
  - lib/tasks/effective_csv_importer.rake
111
96
  - lib/tasks/pg_pull.rake
112
97
  - lib/tasks/rename_class.rake
@@ -132,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
117
  version: '0'
133
118
  requirements: []
134
119
  rubyforge_project:
135
- rubygems_version: 2.4.5.1
120
+ rubygems_version: 2.5.2.3
136
121
  signing_key:
137
122
  specification_version: 4
138
123
  summary: Provides some quality of life developer tools.
@@ -1,33 +0,0 @@
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 -%>
@@ -1,6 +0,0 @@
1
- <% resource.belong_tos.each do |reference| -%>
2
- <%= render_field(reference) %>
3
- <% end -%>
4
- <% attributes.each do |attribute| -%>
5
- <%= render_field(attribute) %>
6
- <% end -%>
@@ -1,3 +0,0 @@
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) %>
@@ -1,16 +0,0 @@
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 -%>
@@ -1 +0,0 @@
1
- = f.input :<%= reference.foreign_key.presence || (reference.name.to_s + '_id') %>, as: :effective_select, collection: <%= reference.name.to_s.classify %>.all
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>, as: :boolean
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>, as: :effective_date_picker
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>, as: :effective_date_time_picker
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>
@@ -1,11 +0,0 @@
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 %>
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>
@@ -1 +0,0 @@
1
- = f.input :<%= attribute.name %>, as: :text
@@ -1,12 +0,0 @@
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
@@ -1,33 +0,0 @@
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 -%>
@@ -1,6 +0,0 @@
1
- <% resource.belong_tos.each do |reference| -%>
2
- <%= render_field(reference) %>
3
- <% end -%>
4
- <% attributes.each do |attribute| -%>
5
- <%= render_field(attribute) %>
6
- <% end -%>
@@ -1,3 +0,0 @@
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) %>
@@ -1,12 +0,0 @@
1
- %h1= @page_title
2
-
3
- <% if non_crud_actions.present? -%>
4
- %p.text-right
5
- <% non_crud_actions.each do |action| -%>
6
- - if can?(:<%= action.to_s %>, @<%= resource.name %>)
7
- = link_to '<%= action.titleize %>', <%= resource.action_path_helper(action, at: true) %>, class: 'btn btn-primary',
8
- data: { confirm: 'Really <%= action.to_s.titleize %>?' }
9
-
10
- <% end -%>
11
- <% end -%>
12
- = render 'form', <%= resource.name %>: @<%= resource.name %>
@@ -1,15 +0,0 @@
1
- %h1= @page_title
2
-
3
- <% if actions.include?('new') -%>
4
- - if can?(:new, <%= resource.class_name %>)
5
- %p.text-right= link_to 'New <%= resource.human_name %>', <%= resource.action_path(:new) %>, class: 'btn btn-primary'
6
-
7
- <% end -%>
8
- <% if defined?(EffectiveDatatables) -%>
9
- - if @datatable.present?
10
- = render_datatable(@datatable)
11
- - else
12
- %p There are no <%= resource.plural_name %>.
13
- <% else %>
14
- = render @<%= resource.plural_name %>
15
- <% end %>
@@ -1,3 +0,0 @@
1
- %h1= @page_title
2
-
3
- = render 'form', <%= resource.name %>: @<%= resource.name %>
@@ -1,12 +0,0 @@
1
- %h1= @page_title
2
-
3
- <% if non_crud_actions.present? -%>
4
- %p.text-right
5
- <% non_crud_actions.each do |action| -%>
6
- - if can?(:<%= action.to_s %>, @<%= resource.name %>)
7
- = link_to '<%= action.titleize %>', <%= resource.action_path_helper(action, at: true) %>, class: 'btn btn-default',
8
- data: { confirm: 'Really <%= action.to_s.titleize %>?' }
9
-
10
- <% end -%>
11
- <% end -%>
12
- = render @<%= resource.name %>