formgen 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
data/formgen.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{formgen}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pullmonkey"]
@@ -29,11 +29,15 @@ Gem::Specification.new do |s|
29
29
  "lib/generators/skizmo/form/USAGE",
30
30
  "lib/generators/skizmo/form/form_generator.rb",
31
31
  "lib/generators/skizmo/form/templates/_form.html.erb",
32
+ "lib/generators/skizmo/form/templates/_form.html.haml",
32
33
  "lib/generators/skizmo/form/templates/_nested_fields.html.erb",
34
+ "lib/generators/skizmo/form/templates/_nested_fields.html.haml",
33
35
  "lib/generators/skizmo/form/templates/edit.html.erb",
36
+ "lib/generators/skizmo/form/templates/edit.html.haml",
34
37
  "lib/generators/skizmo/form/templates/helper.rb",
35
38
  "lib/generators/skizmo/form/templates/javascript.js",
36
39
  "lib/generators/skizmo/form/templates/new.html.erb",
40
+ "lib/generators/skizmo/form/templates/new.html.haml",
37
41
  "lib/generators/skizmo/form/templates/setup_helper.rb",
38
42
  "test/helper.rb",
39
43
  "test/test_formgen.rb"
@@ -10,7 +10,7 @@ module Skizmo
10
10
  class_option :select_boxes, :type => :boolean, :default => true,
11
11
  :description => "Generates select box selections for belongs_to and has_many associations that are not accepted as nested_attributes"
12
12
 
13
- def generate_form
13
+ def generate_form
14
14
  unless nested_has_many_classes.empty?
15
15
  copy_file "javascript.js", "public/javascripts/jquery.add_remove_links.js" if options.javascript?
16
16
  copy_file "helper.rb", "app/helpers/add_remove_links_helper.rb" if options.helpers?
@@ -18,21 +18,25 @@ module Skizmo
18
18
  unless nested_classes_with_attributes.empty?
19
19
  template "setup_helper.rb", "app/helpers/#{file_name}_setup_helper.rb" if options.helpers?
20
20
  end
21
- template "new.html.erb", "app/views/#{file_name.pluralize}/new.html.erb"
22
- template "edit.html.erb", "app/views/#{file_name.pluralize}/edit.html.erb"
21
+ template "new.html.#{engine}", "app/views/#{file_name.pluralize}/new.html.#{engine}"
22
+ template "edit.html.#{engine}", "app/views/#{file_name.pluralize}/edit.html.#{engine}"
23
23
  @have_attachment_string = have_attachments? ? ", :html => { :multipart => true }" : ""
24
- template "_form.html.erb", "app/views/#{file_name.pluralize}/_form.html.erb"
24
+ template "_form.html.#{engine}", "app/views/#{file_name.pluralize}/_form.html.#{engine}"
25
25
  nested_classes_with_attributes.each do |hash_with_kls_and_attrs|
26
26
  @kls = hash_with_kls_and_attrs[:kls] # class object
27
27
  @sym = hash_with_kls_and_attrs[:sym] # passed to the fields_for
28
28
  @attrs = hash_with_kls_and_attrs[:attrs] # attrs that are worthy for this association
29
29
  @assoc = hash_with_kls_and_attrs[:assoc] # so we know whether to use the add and remove links or not
30
- template "_nested_fields.html.erb", "app/views/#{file_name.pluralize}/_#{@sym.to_s.singularize}_fields.html.erb"
30
+ template "_nested_fields.html.#{engine}", "app/views/#{file_name.pluralize}/_#{@sym.to_s.singularize}_fields.html.#{engine}"
31
31
  end
32
32
  end
33
33
 
34
34
  private
35
35
 
36
+ def engine
37
+ ::Rails.application.config.app_generators.rails[:template_engine].to_s rescue "erb"
38
+ end
39
+
36
40
  def file_name
37
41
  cls_underscore
38
42
  end
@@ -0,0 +1,46 @@
1
+ <% if options.helpers? -%>
2
+ = form_for setup_<%= cls_underscore %>(@<%= cls.to_s.underscore %>)<%= @have_attachment_string %> do |f|
3
+ <% else -%>
4
+ = form_for @<%= cls.to_s.underscore %><%= @have_attachment_string %> do |f|
5
+ <% end -%>
6
+ - if @<%= cls.to_s.underscore %>.errors.any?
7
+ #errorExplanation
8
+ %h2
9
+ =pluralize(@<%= cls.to_s.underscore %>.errors.count, "error")
10
+ prohibited this <%= cls.to_s.underscore.gsub("_"," ") %> from being saved:
11
+ %ul
12
+ -@<%= cls.to_s.underscore %>.errors.full_messages.each do |msg|
13
+ %li= msg
14
+ <% attributes_worth_using_in_the_form.each do |att| -%>
15
+ .field
16
+ = f.label :<%= att %>
17
+ = f.<%= attr_form_method(cls, att) %> :<%= att %>
18
+ <% end -%>
19
+ <% if options.select_boxes? -%>
20
+ <% non_nested_belongs_to_classes.each do |cls_name| -%>
21
+ .field
22
+ = f.label :<%= cls_name %>_id, "<%= cls_name.to_s.underscore.gsub("_", " ").camelize %>"
23
+ = f.select :<%= cls_name %>_id, build_select_list(:<%= cls_name %>), {:prompt => "Please select one"}
24
+ <% end -%>
25
+ <% non_nested_has_many_classes.each do |cls_name| -%>
26
+ .field
27
+ = f.label :<%= cls_name.to_s.singularize %>_ids, "<%= cls_name.to_s.underscore.gsub("_", " ").camelize %>"
28
+ = f.select :<%= cls_name.to_s.singularize %>_ids, build_select_list(:<%= cls_name %>), {:prompt => "Please select"}, {:multiple => true, :size => 4}
29
+ <% end -%>
30
+ <% end -%>
31
+ <% nested_belongs_to_classes.each do |cls_name| -%>
32
+ = f.fields_for :<%= cls_name %> do |nf|
33
+ = render '<%= cls_name.to_s.singularize.underscore %>_fields', :f => nf
34
+ <% end -%>
35
+ <% nested_has_many_classes.each do |cls_name| -%>
36
+ = f.fields_for :<%= cls_name %> do |nf|
37
+ = render '<%= cls_name.to_s.singularize.underscore %>_fields', :f => nf
38
+ <% if options.javascript? -%>
39
+ %p= link_to_add_fields "Add <%= cls_name.to_s.singularize.gsub("_"," ") %>", f, :<%= cls_name %>
40
+ <% end -%>
41
+ <% end -%>
42
+ = f.submit "Save"
43
+ <% if options.javascript? -%>
44
+ = content_for :head do
45
+ = javascript_include_tag 'jquery.add_remove_links.js'
46
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ .fields
2
+ <% @attrs.each do |att| -%>
3
+ .field
4
+ = f.label :<%= att %>
5
+ = f.<%= attr_form_method(@kls, att) %> :<%= att %>
6
+ <% end -%>
7
+ <% if @assoc == :has_many and options.javascript? -%>
8
+ = link_to_remove_fields "remove", f
9
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ %h1 Editing <%= name.underscore.gsub("_", " ") %>
2
+ = render 'form'
3
+ = link_to 'back', :back
@@ -0,0 +1,3 @@
1
+ %h1 New <%= name.underscore.gsub("_", " ") %>
2
+ = render 'form'
3
+ = link_to 'back', :back
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formgen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pullmonkey
@@ -100,11 +100,15 @@ files:
100
100
  - lib/generators/skizmo/form/USAGE
101
101
  - lib/generators/skizmo/form/form_generator.rb
102
102
  - lib/generators/skizmo/form/templates/_form.html.erb
103
+ - lib/generators/skizmo/form/templates/_form.html.haml
103
104
  - lib/generators/skizmo/form/templates/_nested_fields.html.erb
105
+ - lib/generators/skizmo/form/templates/_nested_fields.html.haml
104
106
  - lib/generators/skizmo/form/templates/edit.html.erb
107
+ - lib/generators/skizmo/form/templates/edit.html.haml
105
108
  - lib/generators/skizmo/form/templates/helper.rb
106
109
  - lib/generators/skizmo/form/templates/javascript.js
107
110
  - lib/generators/skizmo/form/templates/new.html.erb
111
+ - lib/generators/skizmo/form/templates/new.html.haml
108
112
  - lib/generators/skizmo/form/templates/setup_helper.rb
109
113
  - test/helper.rb
110
114
  - test/test_formgen.rb