scaffold_pico 0.2.10 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8640bef802335217959b5a97fb69f5239d11658
4
- data.tar.gz: fcb3862368a6f59f7ec06d03b0a0894f8178a6e6
3
+ metadata.gz: b0258251d6091e9d884d900d5bdde424615fdd66
4
+ data.tar.gz: 0d06a1145b44ba61cb4f842b4ffd3f20e4e35387
5
5
  SHA512:
6
- metadata.gz: 7f731fa61d4828a11ce767774971b63819988813cf27077001621476a9dcd9b1fc64e2c0ed0c4452fe04981182439173492f440369148211df74b3517fae9504
7
- data.tar.gz: 804af77d28f001c8b594244600eb3d1ff5c8dce10ac4aa4db100cb725fccf0cd192fb2b1adeaa9f7f57f03fd94def3633635568a4068c49804686d219cce6858
6
+ metadata.gz: 0a2c33e98a649be87ae0ce4348c6653b41c840e558b140b34f658c243cad092c237809b3bd72e6cc3b5df6e9f358c474480290dfabd597cdd63c6829550a4ada
7
+ data.tar.gz: 9663b5be29ad4c8adcfff9926dfa7dd8a1e95f034ddc0c43ae11b98ce00ef58d6cc2cc7f5a6eb65d6124894ab6af71ce35a051c48c0f03be8f47de12e94d0e6b
@@ -0,0 +1,120 @@
1
+ # scaffold_pico
2
+ ## Scaffolding done right
3
+ With this gem you can create your own pretty administration with a seconds.
4
+
5
+ No learning curve.
6
+
7
+ No need to learn DSLs or support 3rd party gems.
8
+
9
+
10
+ * Support namespaces for the model and the controllers
11
+ * Generate fabricators
12
+ * Supports different css frameworks - zurb / materializecss
13
+ * Can specify different fields for #index, #edit/new and search
14
+ * Can override every file per project
15
+ * You can specify includes/joins for the #index action
16
+ * Includes search
17
+
18
+ # SYNOPSIS
19
+
20
+ scaffold_pico.rb -m Admin::Vector -n administration -b AdminController \
21
+ --fields name: description:text featured:boolean license:belongs_to group_id:integer svg:file \
22
+ --index-fields id name imported featured \
23
+ --search-fields name aspect_ratio license created_at \
24
+ --fabrication \
25
+ --services_folder=services \
26
+ --debug --css_framework=materialize
27
+
28
+ # Install
29
+
30
+ There is no need to have it in your gem file.
31
+
32
+ gem install scaffold_pico
33
+
34
+ Set some default I18n options
35
+
36
+ en.yml:
37
+
38
+ scaffold:
39
+ confirm: 'Are you sure?'
40
+ notices:
41
+ success:
42
+ create: Was successfully created %{model}
43
+ update: Was successfully updated %{model}
44
+ destroy: Was successfully destroyed %{model}
45
+ failed:
46
+ create: Fail creating %{model}
47
+ update: Fail updating %{model}
48
+ destroy: Fail destroing %{model}
49
+ new:
50
+ title: "New %{model}"
51
+ show:
52
+ title: "%{model}"
53
+ edit:
54
+ title: "Edit %{model}"
55
+ index:
56
+ title: "%{model}"
57
+ edit: Edit
58
+ show: Show
59
+ destroy: Delete
60
+ actions: Action
61
+ search:
62
+ header: Search
63
+ button: Search
64
+ reset: New
65
+
66
+ actions:
67
+ index: List %{model}
68
+ actions: 'Actions'
69
+ new: New %{model}
70
+ edit: Edit %{model}
71
+
72
+ # Overriding
73
+ If you want to change something you can put it in
74
+
75
+
76
+ RAILS_ROOT/lib/templates/pico
77
+ /controller.rb
78
+ /search.rb
79
+ /fabricators
80
+ fabrication.rb.erb
81
+ /views
82
+ /materialize
83
+ _form.html.slim.erb
84
+ edit.html.slim.erb
85
+ index.html.slim.erb
86
+ new.html.slim.erb
87
+ show.html.slim.erb
88
+ /zurb
89
+ _form.html.slim.erb
90
+ edit.html.slim.erb
91
+ index.html.slim.erb
92
+ new.html.slim.erb
93
+ show.html.slim.erb
94
+
95
+ # Develop
96
+
97
+ Clone the repo in ~/scaffold_pico or whatever, then in some rails project run the binary like this
98
+
99
+ export SCAFFOLD_PICO_HOME=~/scaffold_pico
100
+ ruby -I $SCAFFOLD_PICO_HOME/lib $SCAFFOLD_PICO_HOME/bin/scaffold_pico \
101
+ --css_framework=materialize \
102
+ --template=slim \
103
+ -m User -n Admin -b AdminController \
104
+ --fields name:string
105
+
106
+ # Known Issues
107
+ Help please: For some of the generated models/views there are extra blank links. It would be great if someone knows how to parse the erb and skip the new lines
108
+
109
+ It would be great if someone wants to make a pull request for erb output
110
+
111
+ Overwrites the existing files without warnings!
112
+
113
+ You can't generate scaffolds for a mounted named engines. I don't know if we need this feature.
114
+
115
+ The Param class has become very messy because of all those variables, so it should be split in small helpers.
116
+
117
+
118
+ ## Copyright
119
+
120
+ Copyright (c) 2016 gudata. See LICENSE.txt for further details.
@@ -1,5 +1,8 @@
1
+ require 'readline'
2
+
1
3
  module Scaffold
2
4
  class BaseGenerator
5
+ @@aways_ovewrite = false
3
6
 
4
7
  def initialize params
5
8
  @params = params
@@ -14,9 +17,44 @@ module Scaffold
14
17
  Scaffold.root
15
18
  end
16
19
 
20
+ def project_root
21
+ Dir.pwd
22
+ end
23
+
24
+ # Check to see if it is overridden and use it
25
+ def find_root *segments
26
+ original = File.join(root, segments)
27
+ overridden = File.join(project_root, segments)
28
+ File.exists?(overridden) ? overridden : original
29
+ end
30
+
17
31
  # the root of the templates
18
32
  def templates
19
33
  'lib/templates/pico/'
20
34
  end
35
+
36
+ def ask(prompt="", newline=false)
37
+ prompt += "\n" if newline
38
+ Readline.readline(prompt, true).squeeze(" ").strip
39
+ end
40
+
41
+ def write_with_confirmation(target_file_path, content)
42
+ unless File.exists?(target_file_path)
43
+ IO.write(target_file_path, content)
44
+ return
45
+ end
46
+
47
+ answer = if @@aways_ovewrite
48
+ puts "#{target_file_path} exists, overwrite? [yaN] y"
49
+ 'y'
50
+ else
51
+ ask("#{target_file_path} exists, overwrite? [yaN]").downcase
52
+ end
53
+
54
+ @@aways_ovewrite = true if answer == 'a'
55
+
56
+ IO.write(target_file_path, content) if answer == 'y'
57
+ end
58
+
21
59
  end
22
60
  end
@@ -37,7 +37,7 @@ module Scaffold
37
37
 
38
38
  option :model, :required => true do
39
39
  short '-m'
40
- long '--model=model'
40
+ long '--model=SuperAdmin::User'
41
41
  desc 'The model. It could be with modules. Example: ModuleA::ModuleB::SomeClassName'
42
42
  validate /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/
43
43
  end
@@ -79,15 +79,17 @@ module Scaffold
79
79
  option :template do
80
80
  long '-t'
81
81
  long '--template template'
82
+ validate /\A(slim)\z/
82
83
  default 'slim'
83
84
  desc 'slim'
84
85
  end
85
86
 
86
87
  option :css_framework do
87
88
  long '-c'
88
- long '--css_framework css_framework'
89
- default 'zurb'
90
- desc 'zurb'
89
+ long '--css_framework materialize'
90
+ default 'materialize'
91
+ validate /\A(zurb|materialize)\z/
92
+ desc 'zurb or materialize'
91
93
  end
92
94
 
93
95
  option :services_folder do
@@ -4,14 +4,14 @@ module Scaffold
4
4
  def generate
5
5
  controller_file_path = create_path(@params.controller_file_name)
6
6
 
7
- puts "Creating #{controller_file_path}"
7
+ # puts "Creating #{controller_file_path}"
8
8
 
9
- filename = File.join(root, templates, 'controller.rb.erb')
10
- content = File.read(filename)
9
+ filepath = find_root(templates, 'controller.rb.erb')
10
+ content = File.read(filepath)
11
11
  # http://www.stuartellis.eu/articles/erb/
12
12
  content = ::ERB.new(content, nil, '-').result(@params.instance_eval{ binding })
13
13
  # puts content
14
- IO.write(controller_file_path, content)
14
+ write_with_confirmation(controller_file_path, content)
15
15
  end
16
16
 
17
17
  def create_path file_name
@@ -4,14 +4,15 @@ module Scaffold
4
4
  fabricators_path = create_fabricators_path
5
5
  source_file_name = "fabrication.rb.erb"
6
6
  target_file_name = "#{@params.resource_name}_fabricator.rb"
7
- source_file_path = File.join(root, templates, 'fabricators', source_file_name)
7
+ source_file_path = find_root(templates, 'fabricators', source_file_name)
8
8
  content = File.read(source_file_path)
9
9
 
10
10
  # http://www.stuartellis.eu/articles/erb/
11
11
  content = ::ERB.new(content, nil, '-').result(@params.instance_eval{ binding })#.gsub(/\s+\n$/, "")
12
12
 
13
13
  target_file_path = File.join(fabricators_path, target_file_name)
14
- IO.write(target_file_path, content)
14
+
15
+ write_with_confirmation(target_file_path, content)
15
16
  end
16
17
 
17
18
  def create_fabricators_path
@@ -2,21 +2,43 @@ module Scaffold
2
2
  class ModelsGenerator < Scaffold::BaseGenerator
3
3
  def generate
4
4
  searches_path = create_searches_path
5
- puts "Don't forget to add '#{@params.services_folder}' in your autoload_paths (application.rb)"
5
+ puts "Add '#{@params.services_folder}' folder in your autoload_paths (application.rb)"
6
6
  create_search_object searches_path
7
+ create_model
8
+ end
9
+
10
+ def create_model
11
+ source_file_name = "model.rb.erb"
12
+ target_file_name = "#{@params.resource_name}.rb"
13
+
14
+ source_file_path = find_root(templates, source_file_name)
15
+ content = File.read(source_file_path)
16
+
17
+ content = ::ERB.new(content, nil, '-').result(@params.instance_eval{ binding })
18
+
19
+ if @params.modules.blank?
20
+ model_path = File.join(Dir.pwd, 'app', 'models')
21
+ else
22
+ model_path = File.join(Dir.pwd, 'app', 'models', @params.modules.map(&:underscore))
23
+ FileUtils.mkdir_p model_path
24
+ end
25
+
26
+ target_file_path = File.join(model_path, target_file_name)
27
+
28
+ write_with_confirmation(target_file_path, content)
7
29
  end
8
30
 
9
31
  def create_search_object searches_path
10
32
  source_file_name = "search.rb.erb"
11
33
  target_file_name = "#{@params.resource_name.pluralize}_search.rb"
12
34
 
13
- source_file_path = File.join(root, templates, source_file_name)
35
+ source_file_path = find_root(templates, source_file_name)
14
36
  content = File.read(source_file_path)
15
37
 
16
38
  content = ::ERB.new(content, nil, '-').result(@params.instance_eval{ binding })
17
39
 
18
40
  target_file_path = File.join(searches_path, target_file_name)
19
- IO.write(target_file_path, content)
41
+ write_with_confirmation(target_file_path, content)
20
42
  end
21
43
 
22
44
  def create_searches_path
@@ -25,6 +47,5 @@ module Scaffold
25
47
  searches_path
26
48
  end
27
49
 
28
-
29
50
  end
30
51
  end
@@ -2,7 +2,8 @@ module Scaffold
2
2
  class Params
3
3
  attr_reader :resource_name, # user for use in @user or filenames
4
4
  :resource_class_name, # CompanyOwnership
5
- :namespaces_array,
5
+ :namespaces_array, # The namespaces for the controller
6
+ :modules, # the modules for the model Admin::...
6
7
  :controller_file_name,
7
8
  :template,
8
9
  :css_framework,
@@ -39,6 +40,7 @@ module Scaffold
39
40
  @base_controller = choice[:base_controller] || 'ApplicationController'
40
41
  @namespaces_array = parse_namespaces_array(@namespace) # [:admin, ...?... ]
41
42
 
43
+
42
44
  # controller
43
45
  @resource_name = @model_name.tableize.singularize # user for use in @user or filenames
44
46
  @collection_name = @model_name.tableize # users for use in @users
@@ -145,13 +147,28 @@ module Scaffold
145
147
  # convert company => company_id
146
148
  def search_fields_permitted search_fields, fields
147
149
  to_ids = []
150
+
151
+ expanded_fields = expand_association_to_ids fields
152
+
148
153
  search_fields.each do |key|
149
- next unless fields.keys.include?(key)
150
- type = fields[key]
154
+ next unless expanded_fields.keys.include?(key)
155
+ type = expanded_fields[key]
151
156
  to_ids << (['references', 'belongs_to'].include?(type.downcase) ? "#{key}_id" : key)
152
157
  end
153
158
  to_ids
154
159
  end
155
160
 
161
+ # if the field is belongs_to
162
+ # make so that fields contains the `field` and field_id
163
+ def expand_association_to_ids fields
164
+ expanded = {}
165
+ fields.each_pair do |name, type|
166
+ case type
167
+ when 'belongs_to'
168
+ expanded["#{name}_id"] = 'integer'
169
+ end
170
+ end
171
+ fields.merge(expanded)
172
+ end
156
173
  end
157
174
  end
@@ -3,18 +3,19 @@ module Scaffold
3
3
  def generate
4
4
  views_path = create_views_path
5
5
  templating_engine = choose_templating_engine
6
- print "Creating view:"
6
+
7
+ # print "Creating view:"
7
8
  %w(index new edit show _form).each do |view_name|
8
- print view_name, ' '
9
+ # print view_name, ' '
9
10
  create views_path, view_name, templating_engine, css_framework
10
11
  end
11
- print "\n"
12
+ # print "\n"
12
13
  end
13
14
 
14
15
  def create views_path, view_name, templating_engine, css_framework
15
16
  source_file_name = "#{view_name}.html.#{templating_engine.extension}.erb"
16
17
  target_file_name = "#{view_name}.html.#{templating_engine.extension}"
17
- source_file_path = File.join(root, templates, 'views',
18
+ source_file_path = find_root(templates, 'views',
18
19
  css_framework,
19
20
  templating_engine.source_folder_name,
20
21
  source_file_name)
@@ -24,7 +25,7 @@ module Scaffold
24
25
  content = ::ERB.new(content, nil, '-').result(@params.instance_eval{ binding })#.gsub(/\s+\n$/, "")
25
26
 
26
27
  target_file_path = File.join(create_views_path, target_file_name)
27
- IO.write(target_file_path, content)
28
+ write_with_confirmation(target_file_path, content)
28
29
  end
29
30
 
30
31
  def create_views_path
@@ -38,6 +39,8 @@ module Scaffold
38
39
  case @params.template
39
40
  when 'slim'
40
41
  ::Scaffold::TemplateEngines::Slim.new
42
+ else
43
+ raise "I don't have defined templates for #{@params.template}. However you can use [slim,]"
41
44
  end
42
45
  end
43
46
 
@@ -5,7 +5,7 @@ class <%= @controller_class_name %> < <%= @base_controller %>
5
5
  <%=
6
6
  active_record = ["@#{@collection_name}_search"]
7
7
  active_record << [ "results" ]
8
- active_record << [ "includes(#{@includes.join(', ')})" ] if @includes and !@includes.empty?
8
+ active_record << [ "includes(#{@includes.lazy.map(&:strip).map{|v| v.gsub(',', '')}.to_a.join(', ')})" ] if @includes and !@includes.empty?
9
9
  active_record << [ "joins(#{@joins.join(', ')})" ] if @joins and !@joins.empty?
10
10
  active_record << [ "page(params[:page])", "per(params[:per])" ]
11
11
  active_record << [ "all" ]
@@ -1,6 +1,6 @@
1
- <% if @modules.empty? %>
1
+ <% if @modules.empty? -%>
2
2
  Fabricator(:<%= @resource_name %>) do
3
- <% else %>
3
+ <% else -%>
4
4
  Fabricator(:<%= @resource_name %>, class_name: '<%= @modulized_resource_class_name -%>') do
5
5
  <% end -%>
6
6
  <% @fields.each_pair do |field_name, kind| -%>
@@ -12,4 +12,4 @@ Fabricator(:<%= @resource_name %>, class_name: '<%= @modulized_resource_class_na
12
12
  <%= field_name -%> { Faker::Lorem.word }
13
13
  <% end -%>
14
14
  <% end -%>
15
- end
15
+ end
@@ -0,0 +1,7 @@
1
+ class <%= @modulized_resource_class_name %> < ApplicationRecord
2
+ <% @fields.select {|k,v| @search_fields.include?(k) }.each_pair do |field_name, field_type| -%>
3
+ <% if field_type == 'belongs_to' -%>
4
+ belongs_to :<%= field_name %>
5
+ <% end -%>
6
+ <% end -%>
7
+ end
@@ -2,21 +2,44 @@ class <%= @search_modulized_resource_class_name %>
2
2
  include ActiveModel::Model
3
3
 
4
4
  attr_accessor(
5
- <% @search_fields.each do |field_name| %>
5
+ <% @fields.select {|k,v| @search_fields.include?(k) }.each_pair do |field_name, field_type| %>
6
+ <% if field_type == 'belongs_to' -%>
7
+ :<%= field_name %>_id,
8
+ <% else %>
6
9
  :<%= field_name %>,
7
10
  <% end %>
11
+ <% end %>
8
12
  )
9
13
 
14
+ <% @fields.select {|k,v| @search_fields.include?(k) }.each_pair do |field_name, field_type| %>
15
+ <%- if field_type == "integer" %>
16
+ validates :<%= field_name -%>, numericality: { only_integer: true }, allow_blank: true
17
+ <%- end %>
18
+ <%- end %>
19
+
20
+ def initialize *args
21
+ @relation = <%= @modulized_resource_class_name %>
22
+ super *args
23
+ end
10
24
 
11
25
  def results
12
- <%= @resource_name %> = <%= @modulized_resource_class_name %>
13
- <% @fields.select {|k,v| @search_fields.include?(k) }.each_pair do |field_name, field_type| %>
14
- <%- if field_type == "string" %>
15
- <%= @resource_name %> = <%= @resource_name %>.where("<%= field_name %> LIKE ?", "%#{<%= field_name %>}%") if self.<%= field_name %>.present?
16
- <%- else %>
17
- <%= @resource_name %> = <%= @resource_name %>.where(<%= field_name %>: <%= field_name %>) if self.<%= field_name %>.present?
18
- <%- end %>
19
- <% end %>
26
+ <%= @resource_name %> = @relation
27
+
28
+ <%= @resource_name %> = @relation.order("updated_at")
29
+
30
+ if valid?
31
+ <% @fields.select {|k,v| @search_fields.include?(k) }.each_pair do |field_name, field_type| %>
32
+ <% if ['string', 'text'].include?(field_type) -%>
33
+ <%= @resource_name %> = <%= @resource_name %>.where("<%= field_name %> LIKE ?", "%#{<%= field_name %>}%") if self.<%= field_name %>.present?
34
+ <% elsif field_type == "boolean" -%>
35
+ <%= @resource_name %> = <%= @resource_name %>.where(<%= field_name -%>: <%= field_name -%>=='1') if self.<%= field_name %>.present?
36
+ <% elsif field_type == 'belongs_to' -%>
37
+ <%= @resource_name %> = <%= @resource_name %>.where(<%= field_name %>_id: <%= field_name %>_id) if self.<%= field_name %>_id.present?
38
+ <% else -%>
39
+ <%= @resource_name %> = <%= @resource_name %>.where(<%= field_name %>: <%= field_name %>) if self.<%= field_name %>.present?
40
+ <% end -%>
41
+ <% end -%>
42
+ end
20
43
 
21
44
  <%= @resource_name %>
22
45
  end
@@ -7,10 +7,12 @@
7
7
  = form.association :<%= field_name %>
8
8
  <% elsif kind == 'text' -%>
9
9
  = form.input :<%= field_name -%>, as: :text
10
+ <% elsif ['date', 'datetime'].include?(kind) -%>
11
+ = form.input :<%= field_name -%>, as: :date, html5: true
10
12
  <% else -%>
11
13
  = form.input :<%= field_name %>
12
14
  <% end -%>
13
15
  <% end -%>
14
16
 
15
17
  .form-actions
16
- = form.submit class: 'waves-effect waves btn-large'
18
+ = form.button :button, 'Reset Password', :class => 'btn btn-large waves-effect waves'
@@ -1,8 +1,11 @@
1
1
  h1 = t('scaffold.index.title', model: <%= @modulized_resource_class_name %>.model_name.human(count: 2))
2
2
 
3
- = link_to <%= @new_resource_path %>, class: 'btn waves-effect waves-light' do
4
- i.material-icons.right add
5
- = t('scaffold.actions.new', model: <%= @modulized_resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
3
+ .fixed-action-btn style="bottom: 45px; right: 24px;"
4
+ = link_to <%= @new_resource_path %>, class: 'btn-floating btn-large waves-effect waves-light red' do
5
+ i.material-icons.right add
6
+ = t('scaffold.actions.new', model: <%= @modulized_resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
7
+
8
+
6
9
 
7
10
  .row
8
11
  .col.s12.m9
@@ -29,14 +32,24 @@ h1 = t('scaffold.index.title', model: <%= @modulized_resource_class_name %>.mode
29
32
  = paginate @<%= @collection_name %>
30
33
 
31
34
  .col.s12.m3
32
- .card
35
+
36
+ aside.card.search
33
37
  = simple_form_for <%= "@#{@collection_name}_search" %>, as: :<%= @collection_name %>_search, url: <%= @collection_path %>, method: :get do |form|
34
38
  .card-content
35
39
  h5 = t('scaffold.index.search.header')
36
40
  = form.error_notification
37
- <% @fields.select {|k,v| @search_fields.include?(k) }.keys.each do |field_name| %>
41
+
42
+ <% @fields.select {|k,v| @search_fields.include?(k) }.each_pair do |field_name, field_type| %>
43
+ <% if field_type == 'belongs_to' -%>
44
+ = form.input :<%= field_name -%>_id
45
+ <% elsif ['date', 'datetime'].include?(field_type) -%>
46
+ = form.input :<%= field_name -%>, as: :date, html5: true
47
+ <% elsif field_type == 'boolean' -%>
48
+ = form.input :<%= field_name -%>, as: :boolean, input_html: {class: 'filled-in'}
49
+ <% else %>
38
50
  = form.input :<%= field_name -%>
39
- <% end %>
51
+ <% end -%>
52
+ <% end %>
40
53
 
41
54
  .card-action
42
55
  = link_to t('scaffold.index.search.reset'), url_for(<%= @collection_path %>), class: 'waves-effect waves-light btn lime lighten-5 black-text'
@@ -7,6 +7,8 @@
7
7
  = form.association :<%= field_name %>
8
8
  <% elsif kind == 'text' -%>
9
9
  = form.input :<%= field_name -%>, as: :text
10
+ <% elsif ['date', 'datetime'].include?(kind) -%>
11
+ = form.input :<%= field_name -%>, as: :date, html5: true
10
12
  <% else -%>
11
13
  = form.input :<%= field_name %>
12
14
  <% end -%>
@@ -1,7 +1,5 @@
1
1
  h1 = t('scaffold.index.title', model: <%= @modulized_resource_class_name %>.model_name.human(count: 2).mb_chars.downcase)
2
2
 
3
- = link_to t('scaffold.actions.new', model: <%= @modulized_resource_class_name %>.model_name.human.mb_chars.downcase), <%= @new_resource_path %>, class: 'button small secondary'
4
-
5
3
  .row
6
4
  .small-12.medium-10.columns
7
5
  table
@@ -24,15 +22,26 @@ h1 = t('scaffold.index.title', model: <%= @modulized_resource_class_name %>.mode
24
22
  = paginate @<%= @collection_name %>
25
23
 
26
24
  .small-12.medium-2.columns
27
- .callout.clearfix
25
+ aside.callout.clearfix.actions
26
+ = link_to t('scaffold.actions.new', model: <%= @modulized_resource_class_name %>.model_name.human.mb_chars.downcase), <%= @new_resource_path %>, class: 'button small secondary'
27
+
28
+ aside.search.callout.clearfix
28
29
  h5 = t('scaffold.index.search.header')
29
30
 
30
31
  = simple_form_for <%= "@#{@collection_name}_search" %>, as: :<%= @collection_name %>_search, url: <%= @collection_path %>, method: :get do |form|
31
32
  = form.error_notification
32
33
  .form-inputs
33
- <% @fields.select {|k,v| @search_fields.include?(k) }.keys.each do |field_name| %>
34
+ <% @fields.select {|k,v| @search_fields.include?(k) }.each_pair do |field_name, field_type| %>
35
+ <% if field_type == 'belongs_to' -%>
36
+ = form.input :<%= field_name -%>_id
37
+ <% elsif ['date', 'datetime'].include?(field_type) -%>
38
+ = form.input :<%= field_name -%>, as: :date, html5: true
39
+ <% elsif field_type == 'boolean' -%>
40
+ = form.input :<%= field_name -%>, as: :boolean, input_html: {class: 'filled-in'}
41
+ <% else %>
34
42
  = form.input :<%= field_name -%>
35
- <% end %>
43
+ <% end -%>
44
+ <% end %>
36
45
 
37
46
  .form-actions
38
47
  = form.submit t('scaffold.index.search.button'), class: 'button'
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffold_pico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gudata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-25 00:00:00.000000000 Z
11
+ date: 2016-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: choice
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: require_all
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 2.0.1
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 2.0.1
82
+ version: '0'
83
83
  description: Scaffolding
84
84
  email: i.bardarov@gmail.com
85
85
  executables:
@@ -87,10 +87,10 @@ executables:
87
87
  extensions: []
88
88
  extra_rdoc_files:
89
89
  - LICENSE.txt
90
- - README.rdoc
90
+ - README.md
91
91
  files:
92
92
  - LICENSE.txt
93
- - README.rdoc
93
+ - README.md
94
94
  - bin/scaffold_pico
95
95
  - lib/scaffold/base_generator.rb
96
96
  - lib/scaffold/cli.rb
@@ -105,6 +105,7 @@ files:
105
105
  - lib/scaffold_pico.rb
106
106
  - lib/templates/pico/controller.rb.erb
107
107
  - lib/templates/pico/fabricators/fabrication.rb.erb
108
+ - lib/templates/pico/model.rb.erb
108
109
  - lib/templates/pico/search.rb.erb
109
110
  - lib/templates/pico/views/materialize/slim/_form.html.slim.erb
110
111
  - lib/templates/pico/views/materialize/slim/edit.html.slim.erb
@@ -126,19 +127,18 @@ require_paths:
126
127
  - lib
127
128
  required_ruby_version: !ruby/object:Gem::Requirement
128
129
  requirements:
129
- - - '>='
130
+ - - ">="
130
131
  - !ruby/object:Gem::Version
131
132
  version: '0'
132
133
  required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  requirements:
134
- - - '>='
135
+ - - ">="
135
136
  - !ruby/object:Gem::Version
136
137
  version: '0'
137
138
  requirements: []
138
139
  rubyforge_project:
139
- rubygems_version: 2.4.6
140
+ rubygems_version: 2.6.8
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: Scaffold should be simple
143
144
  test_files: []
144
- has_rdoc:
@@ -1,79 +0,0 @@
1
- = scaffold_pico
2
-
3
-
4
- ruby -I lib bin/scaffold_pico.rb \
5
- --css_framework=materialize --template=slim \
6
- -m User -n Admin
7
- --fields name:string
8
- --fabrication \
9
-
10
-
11
- Used in production:
12
- scaffold_pico.rb -m Company -n super_admin --fields name:string website:string active:string subscription:string contact_person:string
13
-
14
- scaffold_pico.rb -m CompanyOwnerships -b AuthenticatedController -n admin \
15
- --includes :user :company \
16
- --css_framework=materialize \
17
- --fields user_id: company_id: admin:boolean approved:boolean \
18
- --index-fields user_id admin approved \
19
- --search-fields admin approved
20
-
21
- scaffold_pico.rb -m Admin::Assistant -n administation/pencho --fields first_name:string last_name:string
22
-
23
- Example with options:
24
- scaffold_pico.rb -d --css_framework=materialize \
25
- -m Vector -n manage -b AdminController \
26
- --fields name: featured:boolean aspect_ratio: portrait:boolean landscape:boolean imported:boolean trending:boolean width:integer height:integer transperant:boolean bw:boolean license:belongs_to group_id:integer tool:belongs_to user_id: category_id: category_display_order:integer group_display_order:integer svg:file ai:file png:file emf:file wmf:file \
27
- --index-fields id name imported featured \
28
- --search-fields name aspect_ratio landscape portrait imported featured trending width height transperant bw license_id group_id tool_id user_id category_id
29
- --services_folder=services
30
-
31
- == I18n
32
-
33
- en.yml:
34
-
35
- activerecord:
36
- notices:
37
- success:
38
- create: Was successfully created %{model}
39
- update: Was successfully updated %{model}
40
- destroy: Was successfully destroyed %{model}
41
- failed:
42
- create: Fail creating %{model}
43
- update: Fail updating %{model}
44
- destroy: Fail destroing %{model}
45
-
46
- == Copyright
47
-
48
- Copyright (c) 2016 gudata. See LICENSE.txt for
49
- further details.
50
-
51
-
52
-
53
- 2fix
54
-
55
-
56
- scaffold_pico.rb -m Admin::CompanyOwnerships -b AuthenticatedController -n admin \
57
- --includes :user, :company \ <---
58
- --css_framework=materialize \
59
- --fields user_id: company_id: admin:boolean approved:boolean \ <---belongsto, file fields
60
- --index-fields user_id admin approved \
61
- --search-fields admin approved <-- missing searchfields
62
-
63
- scaffold_pico.rb -m Auctions::AuctionItem -b Manage::BaseController -n manage \
64
- --includes :user :page :auction \
65
- --css_framework=zurb --services_folder=actions\
66
- --fields id: auction:belongs_to user:belongs_to page:belongs_to state: message:text money_wanted_by_user: money_approved_for_user: tickets_count: ended_at: claimed_at: document_1:file document_2:file document_3:file document_4:file document_5:file created_at: \
67
- --index-fields auction user page state money_wanted_by_user \
68
- --search-fields auction_id user_id
69
-
70
-
71
- Started POST "/super_admin/company_ownerships" for 127.0.0.1 at 2016-05-18 21:36:21 +0300
72
- Processing by SuperAdmin::CompanyOwnershipsController#create as HTML
73
- Parameters: {"utf8"=>"✓", "authenticity_token"=>"OBASAkBg11kfNd0omZ6Jd4AApmCIU1Q2f9uCq/665cwf/qJva74jkS620ELii96stkPcYfLfzes0yu0i/+nKAQ==", "company_ownership"=>{"user_id"=>"1", "company_id"=>"1", "admin"=>"0", "approved"=>"0"}, "commit"=>"Създай Членство"}
74
- User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 4], ["LIMIT", 1]]
75
- Unpermitted parameters: user_id, company_id <---
76
-
77
-
78
- services/action folder param
79
- auction = auction.where(name: name) if self.name.present?