scaffold_pico 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1247d50bcbd659f4e3d50c8fa8020820da9f588c
4
- data.tar.gz: a84bce5591ef237baced3dbe3e285c43b575402d
3
+ metadata.gz: 5392f621e57e3dfb50e1290ebe19dc31ce5fd928
4
+ data.tar.gz: 821c617625303636091c81c4136797f402329f02
5
5
  SHA512:
6
- metadata.gz: 8d22ee17e20281f180d636ce9acf5135b4279079f08c3d2491bbb0653199f32652fd21c1fa452d31da0b0a78d6fd925d3b2c90c54b96f71f9b8972d2a6a11a60
7
- data.tar.gz: 7619cf459d138001120ceb8855030184367a1b7a51cee121db3e560b6169765db8535576b59a4809bc5b261b496eeadbae6e4a5ebd19ee9dabfc9ee2899c48e1
6
+ metadata.gz: 8ca1e165147e9d113178c22ffacce5a3907ab06d349e9ee0cc4d81b2602caa4e4ad087b0a10e30b7ce06485740650a40616fb1235d4ad6009bb8608cdaacc96e
7
+ data.tar.gz: de1c778720fc95fe5fd745d5300d2e88159047f08a16490cea17712bfce3fc00d23fdb5425fbc67ae7a86eaa03345468824478ca766174efed8c8f10b2fb9d0f
data/lib/scaffold_pico.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext'
1
2
  require 'active_support/inflector'
2
3
  require 'active_support/core_ext/object/blank'
3
4
  require 'ostruct'
@@ -0,0 +1,72 @@
1
+ class <%= @controller_class_name %> < <%= @base_controller %>
2
+
3
+ def index
4
+ <%= "@#{@collection_name}_search = #{@search_modulized_resource_class_name}.new(search_#{@collection_name}_params)" %>
5
+ <%=
6
+ active_record = ["@#{@collection_name}_search"]
7
+ active_record << [ "results" ]
8
+ active_record << [ "includes(#{@includes.join(', ')})" ] if @includes and !@includes.empty?
9
+ active_record << [ "joins(#{@joins.join(', ')})" ] if @joins and !@joins.empty?
10
+ active_record << [ "page(params[:page])", "per(params[:per])" ]
11
+ active_record << [ "all" ]
12
+ "@#{@collection_name} = #{active_record.join('.')}"
13
+ %>
14
+ end
15
+
16
+ def show
17
+ @<%= @resource_name %> = <%= @modulized_resource_class_name %>.find(params[:id])
18
+ end
19
+
20
+ def new
21
+ @<%= @resource_name %> = <%= @modulized_resource_class_name %>.new
22
+ end
23
+
24
+ def edit
25
+ @<%= @resource_name %> = <%= @modulized_resource_class_name %>.find(params[:id])
26
+ end
27
+
28
+ def create
29
+ @<%= @resource_name %> = <%= @modulized_resource_class_name %>.new(<%= @collection_name %>_params)
30
+
31
+ respond_to do |format|
32
+ if @<%= @resource_name %>.save
33
+ <%= "message = t('create', scope: [:scaffold, :notices, :success], model: #{@resource_class_name}.model_name.human.mb_chars.downcase)" %>
34
+ format.html { redirect_to <%= @collection_path %>, notice: message }
35
+ else
36
+ format.html { render :new }
37
+ end
38
+ end
39
+ end
40
+
41
+ def update
42
+ @<%= @resource_name %> = <%= @modulized_resource_class_name %>.find(params[:id])
43
+ respond_to do |format|
44
+ if @<%= @resource_name %>.update(<%= @collection_name %>_params)
45
+ <%= "message = t('update', scope: [:scaffold, :notices, :success], model: #{@resource_class_name}.model_name.human.mb_chars.downcase)" %>
46
+ format.html { redirect_to <%= @collection_path %>, notice: message }
47
+ else
48
+ format.html { render :edit }
49
+ end
50
+ end
51
+ end
52
+
53
+ def destroy
54
+ @<%= @resource_name %> = <%= @modulized_resource_class_name %>.find(params[:id])
55
+ @<%= @resource_name %>.destroy
56
+ respond_to do |format|
57
+ <%= "message = t('destroy', scope: [:scaffold, :notices, :success], model: #{@resource_class_name}.model_name.human.mb_chars.downcase)" %>
58
+ format.html { redirect_to <%= @collection_path %>, notice: message }
59
+ end
60
+ end
61
+
62
+ private
63
+ def <%= @collection_name %>_params
64
+ params[:<%= @resource_name %>].permit(<%= @fields.keys.collect{|field| ":#{field}"}.join(', ') %>)
65
+ end
66
+
67
+ def search_<%= @collection_name %>_params
68
+ return {} if params[:<%= @collection_name %>_search].blank?
69
+ params[:<%= @collection_name %>_search].permit(<%= @fields.keys.collect{|field| ":#{field}"}.join(', ') %>)
70
+ end
71
+
72
+ end
@@ -0,0 +1,20 @@
1
+ class <%= @search_modulized_resource_class_name %>
2
+ include ActiveModel::Model
3
+
4
+ attr_accessor(
5
+ <% @search_fields.each do |field_name| %>
6
+ :<%= field_name %>,
7
+ <% end %>
8
+ )
9
+
10
+
11
+ def results
12
+ <%= @resource_name %> = <%= @modulized_resource_class_name %>
13
+ <% @search_fields.each do |field_name| %>
14
+ <%= @resource_name %> = <%= @resource_name %>.where(<%= field_name %>: <%= field_name %>) if self.<%= field_name %>.present?
15
+ <% end %>
16
+
17
+ <%= @resource_name %>
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ = form.error_notification
2
+ .form-inputs
3
+ <% @fields.each_pair do |field_name, kind| -%>
4
+ <% if kind == 'file' -%>
5
+ = form.input :<%= field_name -%>, as: :file
6
+ <% elsif kind == 'belongs_to' -%>
7
+ = form.association :<%= field_name %>
8
+ <% elsif kind == 'text' -%>
9
+ = form.input :<%= field_name -%>, as: :text
10
+ <% else -%>
11
+ = form.input :<%= field_name %>
12
+ <% end -%>
13
+ <% end -%>
14
+
15
+ .form-actions
16
+ = form.submit class: 'waves-effect waves btn-large'
@@ -0,0 +1,20 @@
1
+ h1 = t('scaffold.edit.title', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
2
+
3
+ .section
4
+ .left
5
+ = link_to <%= @collection_path %>, class: 'waves-effect waves-light btn' do
6
+ i.material-icons.right view_list
7
+ = t('scaffold.show.actions.index', model: <%= @resource_class_name %>.model_name.human(count: 2).mb_chars.downcase)
8
+
9
+
10
+ .right
11
+ = link_to <%= @new_resource_path %>, class: 'btn waves-effect waves-light' do
12
+ i.material-icons.right add
13
+ = t('scaffold.actions.new', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
14
+
15
+ .clearfix
16
+
17
+ .card
18
+ .card-content
19
+ = simple_form_for <%= @instance_resource_path %> do |form|
20
+ = render 'form', form: form
@@ -0,0 +1,44 @@
1
+ h1 = t('scaffold.index.title', model: <%= @resource_class_name %>.model_name.human(count: 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: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
6
+
7
+ .row
8
+ .col.s12.m9
9
+ .card
10
+ .card-content
11
+ table.striped.highlight.responsive-table
12
+ thead
13
+ tr
14
+ <% @fields.select {|k,v| @index_fields.include?(k) }.keys.each do |field_name| %>
15
+ th = <%= @resource_class_name -%>.human_attribute_name(:<%= field_name -%>)
16
+ <% end %>
17
+ th colspan=3 = t('scaffold.index.actions')
18
+
19
+ tbody
20
+ - @<%= @collection_name %>.each do |<%= @resource_name %>|
21
+ tr
22
+ <% @fields.select {|k,v| @index_fields.include?(k) }.keys.each do |field_name| %>
23
+ td = <%= @resource_name %>.<%= field_name -%>
24
+ <% end %>
25
+ td = link_to t('scaffold.index.show'), <%= @resource_path %>
26
+ td = link_to t('scaffold.index.edit'), <%= @edit_resource_path %>
27
+ td = link_to t('scaffold.index.destroy'), <%= @resource_path %>, data: {:confirm => t('scaffold.confirm')}, :method => :delete
28
+ .card-action
29
+ = paginate @<%= @collection_name %>
30
+
31
+ .col.s12.m3
32
+ .card
33
+ = simple_form_for <%= "@#{@collection_name}_search" %>, as: :<%= @collection_name %>_search, url: <%= @collection_path %>, method: :get do |form|
34
+ .card-content
35
+ h5 = t('scaffold.index.search.header')
36
+ = form.error_notification
37
+ <% @fields.select {|k,v| @search_fields.include?(k) }.keys.each do |field_name| %>
38
+ = form.input :<%= field_name -%>
39
+ <% end %>
40
+
41
+ .card-action
42
+ = link_to t('scaffold.index.search.reset'), url_for(<%= @collection_path %>), class: 'waves-effect waves-light btn lime lighten-5 black-text'
43
+ = form.submit t('scaffold.index.search.button'), class: 'right waves-effect waves-light btn'
44
+ .clearfix
@@ -0,0 +1,14 @@
1
+ h1 = t('scaffold.new.title', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
2
+
3
+ .section
4
+ .left
5
+ = link_to <%= @collection_path %>, class: 'waves-effect waves-light btn' do
6
+ i.material-icons.right view_list
7
+ = t('scaffold.show.actions.index', model: <%= @resource_class_name %>.model_name.human(count: 2).mb_chars.downcase)
8
+
9
+ .clearfix
10
+
11
+ .card
12
+ .card-content
13
+ = simple_form_for <%= @instance_resource_path %> do |form|
14
+ = render 'form', form: form
@@ -0,0 +1,26 @@
1
+ h1 = t('scaffold.show.title', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
2
+
3
+ .section
4
+ .left
5
+ = link_to <%= @collection_path %>, class: 'waves-effect waves-light btn' do
6
+ i.material-icons.right view_list
7
+ = t('scaffold.actions.index', model: <%= @resource_class_name %>.model_name.human(count: 2).mb_chars.downcase)
8
+ .right
9
+ = link_to <%= @instance_edit_resource_path %>, class: 'btn waves-effect waves-light' do
10
+ i.material-icons.right mode_edit
11
+ = t('scaffold.actions.edit', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
12
+ = link_to <%= @new_resource_path %>, class: 'btn waves-effect waves-light' do
13
+ i.material-icons.right add
14
+ = t('scaffold.actions.new', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
15
+
16
+ .clearfix
17
+
18
+ .card
19
+ .card-content
20
+ table.striped.highlight.responsive-table
21
+ tbody
22
+ <% @fields.keys.each do |field_name| %>
23
+ tr
24
+ td = <%= @resource_class_name -%>.human_attribute_name(:<%= field_name -%>)
25
+ td = @<%= @resource_name %>.<%= field_name -%>
26
+ <% end %>
@@ -0,0 +1,16 @@
1
+ = form.error_notification
2
+ .form-inputs
3
+ <% @fields.each_pair do |field_name, kind| -%>
4
+ <% if kind == 'file' -%>
5
+ = form.input :<%= field_name -%>, as: :file
6
+ <% elsif kind == 'belongs_to' -%>
7
+ = form.association :<%= field_name %>
8
+ <% elsif kind == 'text' -%>
9
+ = form.input :<%= field_name -%>, as: :text
10
+ <% else -%>
11
+ = form.input :<%= field_name %>
12
+ <% end -%>
13
+ <% end -%>
14
+
15
+ .form-actions
16
+ = form.submit class: 'waves-effect waves btn-large'
@@ -0,0 +1,11 @@
1
+ h1 = t('scaffold.edit.title', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
2
+
3
+ .callout.clearfix
4
+ .float-left
5
+ = link_to t('scaffold.show.actions.index', model: <%= @resource_class_name %>.model_name.human(count: 2).mb_chars.downcase), <%= @collection_path %>, class: 'button small primary'
6
+ .float-right
7
+ = link_to t('scaffold.actions.edit', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase), <%= @instance_edit_resource_path %>, class: 'button small warning'
8
+ = link_to t('scaffold.actions.new', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase), <%= @new_resource_path %>, class: 'button small secondary'
9
+
10
+ = simple_form_for <%= @instance_resource_path %> do |form|
11
+ = render 'form', form: form
@@ -0,0 +1,39 @@
1
+ h1 = t('scaffold.index.title', model: <%= @resource_class_name %>.model_name.human(count: 2).mb_chars.downcase)
2
+
3
+ = link_to t('scaffold.actions.new', model: <%= @resource_class_name %>.model_name.human.mb_chars.downcase), <%= @new_resource_path %>, class: 'button small secondary'
4
+
5
+ .row
6
+ .small-12.medium-10.columns
7
+ table
8
+ thead
9
+ tr
10
+ <% @fields.select {|k,v| @index_fields.include?(k) }.keys.each do |field_name| %>
11
+ th = <%= @resource_class_name -%>.human_attribute_name(:<%= field_name -%>)
12
+ <% end %>
13
+ th colspan=3 = t('scaffold.index.actions')
14
+
15
+ tbody
16
+ - @<%= @collection_name %>.each do |<%= @resource_name %>|
17
+ tr
18
+ <% @fields.select {|k,v| @index_fields.include?(k) }.keys.each do |field_name| %>
19
+ td = <%= @resource_name %>.<%= field_name -%>
20
+ <% end %>
21
+ td = link_to t('scaffold.index.show'), <%= @resource_path %>
22
+ td = link_to t('scaffold.index.edit'), <%= @edit_resource_path %>
23
+ td = link_to t('scaffold.index.destroy'), <%= @resource_path %>, data: {:confirm => t('scaffold.confirm')}, :method => :delete
24
+ = paginate @<%= @collection_name %>
25
+
26
+ .small-12.medium-2.columns
27
+ .callout.clearfix
28
+ h5 = t('scaffold.index.search.header')
29
+
30
+ = simple_form_for <%= "@#{@collection_name}_search" %>, as: :<%= @collection_name %>_search, url: <%= @collection_path %>, method: :get do |form|
31
+ = form.error_notification
32
+ .form-inputs
33
+ <% @fields.select {|k,v| @search_fields.include?(k) }.keys.each do |field_name| %>
34
+ = form.input :<%= field_name -%>
35
+ <% end %>
36
+
37
+ .form-actions
38
+ = form.submit t('scaffold.index.search.button'), class: 'button'
39
+ = link_to t('scaffold.index.search.reset'), url_for(<%= @collection_path %>), class: 'button small secondary'
@@ -0,0 +1,8 @@
1
+ h1 = t('scaffold.new.title', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
2
+
3
+ .callout.clearfix
4
+ .float-left
5
+ = link_to t('scaffold.show.actions.index', model: <%= @resource_class_name %>.model_name.human(count: 2).mb_chars.downcase), <%= @collection_path %>, class: 'button small primary'
6
+
7
+ = simple_form_for <%= @instance_resource_path %> do |form|
8
+ = render 'form', form: form
@@ -0,0 +1,16 @@
1
+ h1 = t('scaffold.show.title', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase)
2
+
3
+ .callout.clearfix
4
+ .float-left
5
+ = link_to t('scaffold.show.actions.index', model: <%= @resource_class_name %>.model_name.human(count: 2).mb_chars.downcase), <%= @collection_path %>, class: 'button small primary'
6
+ .float-right
7
+ = link_to t('scaffold.actions.edit', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase), <%= @instance_edit_resource_path %>, class: 'button small warning'
8
+ = link_to t('scaffold.actions.new', model: <%= @resource_class_name %>.model_name.human(count: 1).mb_chars.downcase), <%= @new_resource_path %>, class: 'button small secondary'
9
+
10
+ table
11
+ tbody
12
+ <% @fields.keys.each do |field_name| %>
13
+ tr
14
+ td = <%= @resource_class_name -%>.human_attribute_name(:<%= field_name -%>)
15
+ td = @<%= @resource_name %>.<%= field_name -%>
16
+ <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffold_pico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - gudata
@@ -102,6 +102,18 @@ files:
102
102
  - lib/scaffold/template_engines/slim.rb
103
103
  - lib/scaffold/views_generator.rb
104
104
  - lib/scaffold_pico.rb
105
+ - lib/templates/pico/controller.rb.erb
106
+ - lib/templates/pico/search.rb.erb
107
+ - lib/templates/pico/views/materialize/slim/_form.html.slim.erb
108
+ - lib/templates/pico/views/materialize/slim/edit.html.slim.erb
109
+ - lib/templates/pico/views/materialize/slim/index.html.slim.erb
110
+ - lib/templates/pico/views/materialize/slim/new.html.slim.erb
111
+ - lib/templates/pico/views/materialize/slim/show.html.slim.erb
112
+ - lib/templates/pico/views/zurb/slim/_form.html.slim.erb
113
+ - lib/templates/pico/views/zurb/slim/edit.html.slim.erb
114
+ - lib/templates/pico/views/zurb/slim/index.html.slim.erb
115
+ - lib/templates/pico/views/zurb/slim/new.html.slim.erb
116
+ - lib/templates/pico/views/zurb/slim/show.html.slim.erb
105
117
  homepage: http://github.com/gudata/scaffold_pico
106
118
  licenses:
107
119
  - MIT