decent_ham 0.0.2 → 0.0.3

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: 6b0ce76a318b0a68c4e81b3e66c660c9d0eff065
4
- data.tar.gz: c52091e00da451549f61efb047bfb96bdf11a7b2
3
+ metadata.gz: ef2ab4ac4bcea5f49f0fc522c44d97863fdad728
4
+ data.tar.gz: eab7d0ba3f8b4684f75ac1c1fce9e995743c7ff7
5
5
  SHA512:
6
- metadata.gz: 7301d6933f0d8a8c07faa681bb8441943bcd5318689878128ccfcca165eb10cf32caa892e0f701faa682681c84b0331b1a356d2c4674f79f0e6dc908b2958c0a
7
- data.tar.gz: dda3b1b61143d9252ef947fad3adce92804eb8b33597660ba419d1f546395f435a91bbd83bb4cbe57ec8ec8106734b4fed4ffe882e24c7d47b81c31c4d387a5e
6
+ metadata.gz: d7f8f191d3c3b570805bc227902083ae66a7d956cdd2ad42f9b3a6d27a03683b589b9aa570a8a25a31fe7dab1045bbbe492c66465ab271dd52de4f50545ec1dd
7
+ data.tar.gz: 8b8a6c38a5f911444c5b9782a4013d1d5b2adc6ebc448023db56ca19c3d98e6bfd75fc09132975823cc8368e5ad32e75cc9e38de8e40de14974ef055d16da7c7
@@ -0,0 +1,14 @@
1
+ %section
2
+
3
+ %article
4
+
5
+ = form_for <%= singular_name %> do |f|
6
+ %fieldset
7
+ <% @attributes.each do |attribute| %>
8
+ %dl
9
+ %dt= f.label :<%= attribute.name %>
10
+ %dd= <%= attribute.form_field %>
11
+ <% end %>
12
+ %fieldset.actions
13
+ = f.submit
14
+
@@ -0,0 +1,27 @@
1
+ class <%= plural_name.capitalize %>Controller < ApplicationController
2
+ expose(:<%= plural_name %>)
3
+ expose(:<%= singular_name %>)
4
+
5
+ def create
6
+ if <%= singular_name %>.update_attributes(<%= singular_name %>_params)
7
+ redirect_to <%= singular_name %>, notice: "Your changes have been saved."
8
+ else
9
+ flash.now[:error] = "Sorry, but something went wrong"
10
+ render :new
11
+ end
12
+ end
13
+ alias update create
14
+
15
+ def destroy
16
+ <%= singular_name %>.destroy
17
+ redirect_to :<%= plural_name %>
18
+ end
19
+
20
+ private
21
+
22
+ def <%= singular_name %>_params
23
+ # make sure to whitelist attributes as necessary
24
+ params.require(:<%= singular_name %>).permit(<% @attributes.each do |attribute| %>:<%= attribute.name %>, <% end %>)
25
+ end
26
+
27
+ end
@@ -0,0 +1,9 @@
1
+ %section
2
+
3
+ %article
4
+
5
+ %h1 Edit <%= singular_name.capitalize %>
6
+
7
+ = render 'form'
8
+
9
+ = link_to "Delete", <%= singular_name %>, method: :delete
@@ -0,0 +1,30 @@
1
+ %section
2
+
3
+ %article
4
+
5
+ %h1 All <%= plural_name.capitalize %>
6
+
7
+ = link_to "New <%= singular_name %>", new_<%= singular_name %>_path
8
+
9
+ %table
10
+ %thead
11
+ %tr
12
+ <% @attributes.each do |attribute| %>%td <%= attribute.name.gsub(/_/,' ').capitalize %>
13
+ <% end %>
14
+ %td
15
+ %tbody
16
+ - <%= plural_name %>.each do |<%= singular_name %>|
17
+ %tr
18
+ <% @attributes.each do |attribute| %>%td= <%= singular_name %>.<%= attribute.name %>
19
+ <% end %>
20
+ %td
21
+ = link_to "View", <%= singular_name %>
22
+ |
23
+ = link_to "Edit", edit_<%= singular_name %>_path(<%= singular_name %>)
24
+
25
+
26
+
27
+
28
+
29
+
30
+
@@ -0,0 +1,3 @@
1
+ class <%= singular_name.capitalize %> < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,7 @@
1
+ %section
2
+
3
+ %article
4
+
5
+ %h1 Create <%= singular_name.capitalize %>
6
+
7
+ = render 'form'
@@ -0,0 +1,17 @@
1
+ %section
2
+
3
+ %article
4
+
5
+ %h1 View <%= singular_name.capitalize %>
6
+
7
+ = link_to "All <%= plural_name.capitalize %>", <%= plural_name %>_path
8
+ |
9
+ = link_to "Edit", edit_<%= singular_name %>_path(<%= singular_name %>)
10
+
11
+ %table
12
+ <% @attributes.each do |attribute| %>
13
+ %tr
14
+ %td <%= attribute.name.gsub(/_/,' ').capitalize %>
15
+ %td= <%= singular_name %>.<%= attribute.name %>
16
+ <% end %>
17
+
@@ -0,0 +1,67 @@
1
+ class DecentHamGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def singular_name
5
+ name.singularize
6
+ end
7
+
8
+ def plural_name
9
+ name
10
+ end
11
+
12
+ def strong_params
13
+ strong_params = ":#{singular_name}_params"
14
+ end
15
+
16
+ def create_model
17
+ template "model.rb", "app/models/#{singular_name}.rb"
18
+ end
19
+
20
+ def model_attributes
21
+ constant_name.columns_hash.map do |key, value|
22
+ OpenStruct.new(name: key, data_type: value.type)
23
+ end.delete_if { |column| %w(id created_at updated_at).include? column.name }
24
+ end
25
+
26
+ def create_controller
27
+ @attributes = model_attributes
28
+ template "controller.rb", "app/controllers/#{name}_controller.rb"
29
+ end
30
+
31
+ def add_route
32
+ route "resources :#{name}"
33
+ end
34
+
35
+ def constant_name
36
+ singular_name.capitalize.constantize
37
+ end
38
+
39
+ def attach_form_fields
40
+ model_attributes.each do |attribute|
41
+ attribute.form_field =
42
+ case attribute.data_type
43
+ when :string || :decimal || :integer || :float || :references
44
+ "f.text_field :#{attribute.name}"
45
+ when :text
46
+ "f.text_area :#{attribute.name}"
47
+ when :datetime || :timestamp
48
+ "f.datetime_select :#{attribute.name}"
49
+ when :boolean
50
+ "f.check_box :#{attribute.name}"
51
+ when :date
52
+ "f.date_select :#{attribute.name}"
53
+ when :time
54
+ "f.time_select :#{attribute.name}"
55
+ end
56
+ end
57
+ end
58
+
59
+ def create_views
60
+ @attributes = attach_form_fields
61
+ %w(index new edit _form show).each do |view_name|
62
+ template "#{view_name}.html.haml", "app/views/#{name}/#{view_name}.html.haml"
63
+ end
64
+ end
65
+
66
+ end
67
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decent_ham
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vic Ramon
@@ -53,23 +53,25 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Decent Ham generates rails crud using decent_exposure and haml.
56
- email:
57
- - v@vicramon.com
56
+ email: v@vicramon.com
58
57
  executables: []
59
58
  extensions: []
60
59
  extra_rdoc_files: []
61
60
  files:
62
- - .gitignore
61
+ - lib/generators/decent_ham/templates/_form.html.haml
62
+ - lib/generators/decent_ham/templates/controller.rb
63
+ - lib/generators/decent_ham/templates/edit.html.haml
64
+ - lib/generators/decent_ham/templates/index.html.haml
65
+ - lib/generators/decent_ham/templates/model.rb
66
+ - lib/generators/decent_ham/templates/new.html.haml
67
+ - lib/generators/decent_ham/templates/show.html.haml
68
+ - lib/generators/decent_ham_generator.rb
63
69
  - Gemfile
64
70
  - LICENSE.txt
65
- - README.md
66
71
  - Rakefile
67
- - decent_ham.gemspec
68
- - lib/decent_ham.rb
69
- - lib/decent_ham/version.rb
70
- homepage: ''
71
- licenses:
72
- - MIT
72
+ - README.md
73
+ homepage:
74
+ licenses: []
73
75
  metadata: {}
74
76
  post_install_message:
75
77
  rdoc_options: []
@@ -90,5 +92,5 @@ rubyforge_project:
90
92
  rubygems_version: 2.0.3
91
93
  signing_key:
92
94
  specification_version: 4
93
- summary: ''
95
+ summary: Decent Ham generates rails crud using decent_exposure and haml.
94
96
  test_files: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/decent_ham.gemspec DELETED
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'decent_ham/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "decent_ham"
8
- spec.version = DecentHam::VERSION
9
- spec.authors = ["Vic Ramon"]
10
- spec.email = ["v@vicramon.com"]
11
- spec.description = %q{Decent Ham generates rails crud using decent_exposure and haml.}
12
- spec.summary = %q{}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- end
@@ -1,3 +0,0 @@
1
- module DecentHam
2
- VERSION = "0.0.2"
3
- end
data/lib/decent_ham.rb DELETED
@@ -1,5 +0,0 @@
1
- require "decent_ham/version"
2
-
3
- module DecentHam
4
- require 'decent_ham/decent_ham_generator.rb'
5
- end