core-generators 0.0.1

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.
Files changed (46) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/README.textile +51 -0
  4. data/Rakefile +2 -0
  5. data/core-generators.gemspec +21 -0
  6. data/lib/core-generators.rb +6 -0
  7. data/lib/core/inherited_resource_controller.rb +10 -0
  8. data/lib/core/paginated_controller.rb +12 -0
  9. data/lib/core/version.rb +3 -0
  10. data/lib/generators/core/install/install_generator.rb +132 -0
  11. data/lib/generators/core/install/templates/bootstrap.rake +43 -0
  12. data/lib/generators/core/install/templates/locales/core.en.yml +20 -0
  13. data/lib/generators/core/install/templates/locales/core.es.yml +17 -0
  14. data/lib/generators/core/install/templates/settings.yml +17 -0
  15. data/lib/generators/core/install/templates/simple_form_custom.rb +58 -0
  16. data/lib/generators/core/layout/layout_generator.rb +42 -0
  17. data/lib/generators/core/layout/templates/core.js +113 -0
  18. data/lib/generators/core/layout/templates/core_helper.rb +114 -0
  19. data/lib/generators/core/layout/templates/images/arrow.png +0 -0
  20. data/lib/generators/core/layout/templates/images/boxbar-background.png +0 -0
  21. data/lib/generators/core/layout/templates/images/button-background-active.png +0 -0
  22. data/lib/generators/core/layout/templates/images/button-background.png +0 -0
  23. data/lib/generators/core/layout/templates/images/buttons/cross.png +0 -0
  24. data/lib/generators/core/layout/templates/images/buttons/edit.png +0 -0
  25. data/lib/generators/core/layout/templates/images/buttons/key.png +0 -0
  26. data/lib/generators/core/layout/templates/images/buttons/tick.png +0 -0
  27. data/lib/generators/core/layout/templates/images/menubar-background.png +0 -0
  28. data/lib/generators/core/layout/templates/stylesheets/base.sass +366 -0
  29. data/lib/generators/core/layout/templates/stylesheets/override.sass +1 -0
  30. data/lib/generators/core/layout/templates/stylesheets/style.sass +434 -0
  31. data/lib/generators/core/layout/templates/views/haml/_sidebar.html.haml +14 -0
  32. data/lib/generators/core/layout/templates/views/haml/layout.html.haml +38 -0
  33. data/lib/generators/core/scaffold/scaffold_generator.rb +125 -0
  34. data/lib/generators/core/scaffold/templates/controller.rb +10 -0
  35. data/lib/generators/core/scaffold/templates/helper.rb +3 -0
  36. data/lib/generators/core/scaffold/templates/migration.rb +16 -0
  37. data/lib/generators/core/scaffold/templates/model.rb +5 -0
  38. data/lib/generators/core/scaffold/templates/views/haml/_collection.html.haml +25 -0
  39. data/lib/generators/core/scaffold/templates/views/haml/_form.html.haml +13 -0
  40. data/lib/generators/core/scaffold/templates/views/haml/_search.html.haml +7 -0
  41. data/lib/generators/core/scaffold/templates/views/haml/edit.html.haml +11 -0
  42. data/lib/generators/core/scaffold/templates/views/haml/index.html.haml +8 -0
  43. data/lib/generators/core/scaffold/templates/views/haml/index.js.haml +1 -0
  44. data/lib/generators/core/scaffold/templates/views/haml/new.html.haml +12 -0
  45. data/lib/generators/core/scaffold/templates/views/haml/show.html.haml +19 -0
  46. metadata +112 -0
@@ -0,0 +1,38 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title=APP_CONFIG.app_name
5
+ = stylesheet_link_tag "<%= file_name %>/base", "<%= file_name %>/style", "<%= file_name %>/override",
6
+ = javascript_include_tag :defaults, 'jquery.form','core', :cache => true
7
+ = csrf_meta_tag :cache => true
8
+ %body
9
+ #container
10
+ #header
11
+ %h1
12
+ %a{:href => "/"} Application
13
+ #user-navigation
14
+ %ul.wat-cf
15
+ %li
16
+ %a{:href => "#"}= t("core.profile", :default => "Profile")
17
+ %li
18
+ %a.logout{:href => "/logout"}= t("core.logout", :default => "Logout")
19
+
20
+ #main-navigation
21
+ %ul.wat-cf
22
+ %li
23
+ %a{:href => "#"}= t("core.home", :default => "Home")
24
+
25
+ #wrapper.wat-cf
26
+ - flashes
27
+ #main
28
+ .block
29
+ .content
30
+ = yield
31
+ #footer
32
+ .block
33
+ %p
34
+ Copyright &copy; #{Time.now.year} #{APP_CONFIG.app_name}.
35
+ #sidebar
36
+ = yield :sidebar
37
+
38
+
@@ -0,0 +1,125 @@
1
+ require 'rails/generators/migration'
2
+ require 'rails/generators/resource_helpers'
3
+ require 'rails/generators/generated_attribute'
4
+ require 'rails/generators/active_record/migration'
5
+
6
+ class Core::ScaffoldGenerator < Rails::Generators::NamedBase
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ include Rails::Generators::ResourceHelpers
11
+ include Rails::Generators::Migration
12
+ extend ActiveRecord::Generators::Migration
13
+
14
+ check_class_collision :suffix => "Controller"
15
+
16
+ argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
17
+
18
+ class_option :timestamps, :type => :boolean, :default => true
19
+ class_option :parent, :type => :string, :default => 'ActiveRecord::Base',
20
+ :desc => "The parent class for the generated model"
21
+
22
+ def initialize(*args, &block)
23
+ super
24
+
25
+ @controller_actions = []
26
+ @model_attributes = []
27
+
28
+ args_for_c_m.each do |arg|
29
+ if arg.include?(':')
30
+ @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
31
+ else
32
+ @controller_actions << arg
33
+ @controller_actions << 'create' if arg == 'new'
34
+ @controller_actions << 'update' if arg == 'edit'
35
+ end
36
+ end
37
+
38
+ @controller_actions.uniq!
39
+ @model_attributes.uniq!
40
+
41
+ if @controller_actions.empty?
42
+ @controller_actions = default_actions - @controller_actions
43
+ end
44
+ end
45
+
46
+ def create_controller_files
47
+ template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name.pluralize}_controller.rb")
48
+ end
49
+
50
+ def create_helper_file
51
+ template 'helper.rb', File.join('app/helpers', class_path, "#{controller_file_name.pluralize}_helper.rb")
52
+ end
53
+
54
+ def create_model_file
55
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
56
+ end
57
+
58
+ def add_resource_route
59
+ return if options[:actions].present?
60
+ route_config = class_path.collect{|namespace| "namespace :#{namespace} do" }.join("\n ")
61
+ route_config << "\n"
62
+ route_config << (" " * (class_path.size + 1 )+ "resources :#{file_name.pluralize}\n")
63
+ route_config << " end\n" * class_path.size
64
+ route route_config
65
+ end
66
+
67
+ def copy_view_files
68
+ actions.each do |action|
69
+ if %w[index show new edit].include?(action)
70
+ template "views/#{view_language}/#{action}.html.#{view_language}", "#{views_path}/#{action}.html.#{view_language}"
71
+ end
72
+ end
73
+
74
+ if form_partial?
75
+ template "views/#{view_language}/_form.html.#{view_language}", "#{views_path}/_form.html.#{view_language}"
76
+ end
77
+
78
+ if index?
79
+ template "views/#{view_language}/_search.html.#{view_language}", "#{views_path}/_search.html.#{view_language}"
80
+ template "views/#{view_language}/_collection.html.#{view_language}", "#{views_path}/_#{plural_name}.html.#{view_language}"
81
+ template "views/#{view_language}/index.js.#{view_language}", "#{views_path}/index.js.#{view_language}"
82
+ end
83
+ end
84
+
85
+ def create_migration_file
86
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
87
+ end
88
+
89
+ private
90
+
91
+ def views_path
92
+ File.join("app/views", class_path, plural_name)
93
+ end
94
+
95
+ def form_partial?
96
+ actions.include?("new") || actions.include?("edit")
97
+ end
98
+
99
+ def index?
100
+ actions.include?("index")
101
+ end
102
+ def default_actions?
103
+ actions == default_actions
104
+ end
105
+
106
+ def default_actions
107
+ %w(index create update new edit destroy show)
108
+ end
109
+
110
+ def attributes
111
+ @model_attributes
112
+ end
113
+
114
+ def actions
115
+ @controller_actions || default_actions
116
+ end
117
+
118
+ def parent_class_name
119
+ options[:parent] || "ActiveRecord::Base"
120
+ end
121
+
122
+ def view_language
123
+ 'haml'
124
+ end
125
+ end
@@ -0,0 +1,10 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+
3
+ include Core::InheritedResourceController
4
+ <%- if actions.include?('index') -%>
5
+ include Core::PaginatedController
6
+ <% end %>
7
+ <%- unless default_actions? -%>
8
+ actions <%= actions.map {|a| ":#{a}" }.join(", ") %>
9
+ <%- end -%>
10
+ end
@@ -0,0 +1,3 @@
1
+ module <%= controller_class_name %>Helper
2
+
3
+ end
@@ -0,0 +1,16 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ <%- if options[:timestamps] -%>
8
+ t.timestamps
9
+ <% end -%>
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= table_name %>
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ class <%= class_name %> < <%= parent_class_name.classify %>
2
+ <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
3
+ belongs_to :<%= attribute.name %>
4
+ <% end -%>
5
+ end
@@ -0,0 +1,25 @@
1
+ #results
2
+ %table.table
3
+ %tr
4
+ %th.first
5
+ <%- for attribute in attributes -%>
6
+ %th= sort_link @search, :<%= attribute.name %>, t("activerecord.attributes.<%= singular_name %>.<%= attribute.name %>", :default => t("activerecord.labels.<%= attribute.name %>", :default => "<%= attribute.human_name %>"))
7
+ <%- end -%>
8
+ %th
9
+ .right #{pluralize(@search.count, "<%= singular_name.humanize %>")} found
10
+ - <%= plural_name %>.each do |<%= singular_name %>|
11
+ %tr{ :class => cycle("odd", "even") }
12
+ %td
13
+ <%- for attribute in attributes -%>
14
+ %td= <%= singular_name %>.<%= attribute.name %>
15
+ <%- end -%>
16
+ %td.last
17
+ = link_to t("core.show"), resource_path(<%= singular_name %>)
18
+ |
19
+ = link_to t("core.edit"), edit_resource_path(<%= singular_name %>)
20
+ |
21
+ = link_to t("core.delete"), resource_path(<%= singular_name %>), :method => :delete, :confirm => t("core.confirm")
22
+
23
+ .actions-bar.wat-cf
24
+ .actions
25
+ = will_paginate <%= plural_name %>
@@ -0,0 +1,13 @@
1
+ = simple_form_for(@<%= singular_name %>, :html => { :class => :form } ) do |f|
2
+ .inputs
3
+ <%- attributes.each do |attribute| -%>
4
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
5
+ <%- end -%>
6
+
7
+ .group.navform.wat-cf
8
+ %button.button{ :type => 'submit' }
9
+ = image_tag "buttons/tick.png", :alt => t("core.save")
10
+ = t "core.save"
11
+ = link_to((@<%= singular_name %>.new_record? ? collection_path : resource_path(@<%= singular_name %>)), :class => "button") do
12
+ = image_tag "buttons/cross.png", :alt => t("core.cancel")
13
+ = t "core.cancel"
@@ -0,0 +1,7 @@
1
+ = form_for @search, :url => collection_path, :html => { :method => :get, :class => 'search' } do |f|
2
+ <%- for attribute in attributes -%>
3
+ %p
4
+ = f.label :<%= attribute.name %>
5
+ = f.text_field :<%= attribute.name %>_<%= %w(string text).include?(attribute.type.to_s) ? "contains" : 'equals' %>
6
+ <%- end -%>
7
+ = f.submit
@@ -0,0 +1,11 @@
1
+ .block
2
+ .content
3
+ %h2.title
4
+ = t "core.edit"
5
+ <%= singular_name %>
6
+ .inner
7
+ = render 'form'
8
+
9
+ - sidebar do
10
+ - navigation_list do
11
+ - action_links_for_current_action
@@ -0,0 +1,8 @@
1
+ .block
2
+ - content_block '<%= plural_name.humanize %>' do
3
+ = render :partial => '<%= controller_file_name %>', :locals => { :<%= controller_file_name %> => @<%= controller_file_name %> }
4
+
5
+ - sidebar do
6
+ - navigation_list do
7
+ - action_links_for_current_action
8
+ - content_for :search , render('search')
@@ -0,0 +1 @@
1
+ = render :partial => '<%= controller_file_name %>', :locals => { :<%= controller_file_name %> => @<%= controller_file_name %> }
@@ -0,0 +1,12 @@
1
+ .block
2
+
3
+ .content
4
+ %h2.title
5
+ = t "core.new"
6
+ <%= singular_name.humanize %>
7
+ .inner
8
+ = render 'form'
9
+
10
+ - sidebar do
11
+ - navigation_list do
12
+ - action_links_for_current_action
@@ -0,0 +1,19 @@
1
+ .block
2
+ .content
3
+ .inner
4
+ = show_for @<%= singular_name %> do |s|
5
+ <%- attributes.each do |attribute| -%>
6
+ = s.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %>
7
+ <%- end -%>
8
+
9
+ .wat-cf
10
+ = link_to edit_resource_path(@<%= singular_name %>), :class => "button" do
11
+ = image_tag "buttons/edit.png", :alt => t("core.edit")
12
+ = t "core.edit"
13
+ = link_to resource_path(@<%= singular_name %>), :method => "delete", :class => "button", :confirm => t("core.confirm") do
14
+ = image_tag "buttons/cross.png", :alt => t("core.delete")
15
+ = t "core.delete"
16
+
17
+ - sidebar do
18
+ - navigation_list do
19
+ - action_links_for_current_action
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: core-generators
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - lucasefe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-15 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: core generators used by me
23
+ email:
24
+ - lucasefe@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.textile
35
+ - Rakefile
36
+ - core-generators.gemspec
37
+ - lib/core-generators.rb
38
+ - lib/core/inherited_resource_controller.rb
39
+ - lib/core/paginated_controller.rb
40
+ - lib/core/version.rb
41
+ - lib/generators/core/install/install_generator.rb
42
+ - lib/generators/core/install/templates/bootstrap.rake
43
+ - lib/generators/core/install/templates/locales/core.en.yml
44
+ - lib/generators/core/install/templates/locales/core.es.yml
45
+ - lib/generators/core/install/templates/settings.yml
46
+ - lib/generators/core/install/templates/simple_form_custom.rb
47
+ - lib/generators/core/layout/layout_generator.rb
48
+ - lib/generators/core/layout/templates/core.js
49
+ - lib/generators/core/layout/templates/core_helper.rb
50
+ - lib/generators/core/layout/templates/images/arrow.png
51
+ - lib/generators/core/layout/templates/images/boxbar-background.png
52
+ - lib/generators/core/layout/templates/images/button-background-active.png
53
+ - lib/generators/core/layout/templates/images/button-background.png
54
+ - lib/generators/core/layout/templates/images/buttons/cross.png
55
+ - lib/generators/core/layout/templates/images/buttons/edit.png
56
+ - lib/generators/core/layout/templates/images/buttons/key.png
57
+ - lib/generators/core/layout/templates/images/buttons/tick.png
58
+ - lib/generators/core/layout/templates/images/menubar-background.png
59
+ - lib/generators/core/layout/templates/stylesheets/base.sass
60
+ - lib/generators/core/layout/templates/stylesheets/override.sass
61
+ - lib/generators/core/layout/templates/stylesheets/style.sass
62
+ - lib/generators/core/layout/templates/views/haml/_sidebar.html.haml
63
+ - lib/generators/core/layout/templates/views/haml/layout.html.haml
64
+ - lib/generators/core/scaffold/scaffold_generator.rb
65
+ - lib/generators/core/scaffold/templates/controller.rb
66
+ - lib/generators/core/scaffold/templates/helper.rb
67
+ - lib/generators/core/scaffold/templates/migration.rb
68
+ - lib/generators/core/scaffold/templates/model.rb
69
+ - lib/generators/core/scaffold/templates/views/haml/_collection.html.haml
70
+ - lib/generators/core/scaffold/templates/views/haml/_form.html.haml
71
+ - lib/generators/core/scaffold/templates/views/haml/_search.html.haml
72
+ - lib/generators/core/scaffold/templates/views/haml/edit.html.haml
73
+ - lib/generators/core/scaffold/templates/views/haml/index.html.haml
74
+ - lib/generators/core/scaffold/templates/views/haml/index.js.haml
75
+ - lib/generators/core/scaffold/templates/views/haml/new.html.haml
76
+ - lib/generators/core/scaffold/templates/views/haml/show.html.haml
77
+ has_rdoc: true
78
+ homepage: ""
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options: []
83
+
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project: core-generators
107
+ rubygems_version: 1.4.1
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: core generators used by me
111
+ test_files: []
112
+