base-generators 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.gitignore +3 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +64 -0
  4. data/Rakefile +35 -0
  5. data/VERSION +1 -0
  6. data/base-generators.gemspec +75 -0
  7. data/generators/base_bootstrap/base_bootstrap_generator.rb +29 -0
  8. data/generators/base_bootstrap/templates/_block.html.haml +9 -0
  9. data/generators/base_bootstrap/templates/_block_form.html.haml +8 -0
  10. data/generators/base_bootstrap/templates/_flashes.html.haml +5 -0
  11. data/generators/base_bootstrap/templates/_header.html.haml +16 -0
  12. data/generators/base_bootstrap/templates/_secondary_navigation.html.haml +12 -0
  13. data/generators/base_bootstrap/templates/_sidebar.html.haml +15 -0
  14. data/generators/base_bootstrap/templates/base_helper.rb +67 -0
  15. data/generators/base_bootstrap/templates/layout.html.haml +28 -0
  16. data/generators/base_scaffold/base_scaffold_generator.rb +138 -0
  17. data/generators/base_scaffold/templates/common.js +19 -0
  18. data/generators/base_scaffold/templates/controller.rb +8 -0
  19. data/generators/base_scaffold/templates/helper.rb +2 -0
  20. data/generators/base_scaffold/templates/migration.rb +15 -0
  21. data/generators/base_scaffold/templates/model.rb +2 -0
  22. data/generators/base_scaffold/templates/view__collection.haml +23 -0
  23. data/generators/base_scaffold/templates/view__form.haml +4 -0
  24. data/generators/base_scaffold/templates/view__search.haml +7 -0
  25. data/generators/base_scaffold/templates/view_edit.haml +8 -0
  26. data/generators/base_scaffold/templates/view_index.haml +10 -0
  27. data/generators/base_scaffold/templates/view_index.js.haml +1 -0
  28. data/generators/base_scaffold/templates/view_new.haml +7 -0
  29. data/generators/base_scaffold/templates/view_show.haml +9 -0
  30. data/rails/init.rb +0 -0
  31. data/rails_template.rb +218 -0
  32. data/tasks/scaffold_it_tasks.rake +4 -0
  33. data/test/scaffold_it_test.rb +8 -0
  34. data/test/test_helper.rb +3 -0
  35. data/uninstall.rb +1 -0
  36. metadata +97 -0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Manifest
2
+ doc
3
+ pkg
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,64 @@
1
+ h1. BaseGenerators
2
+
3
+ BaseGenerators tries to ease the pain of starting a new app from scratch by automating tasks with generators.
4
+
5
+ h2. Installation
6
+
7
+ Easy, dude.
8
+
9
+ <pre>
10
+ ruby script/plugin install git://github.com/lucasefe/base-generators.git
11
+ </pre>
12
+
13
+ h2. Generators
14
+
15
+ h3. base_bootstrap
16
+
17
+ This generator copies all the templates and helper methods needed for the base_scaffold generator.
18
+
19
+ <pre>
20
+ ruby script/generate base_bootstrap layout_name
21
+ </pre>
22
+
23
+ h3. base_scaffold
24
+
25
+ This generator provides a scaffold structure that implements "ajax":http://github.com/jquery/jquery/ "pagination":http://github.com/mislav/will_paginate, "search":http://github.com/binarylogic/searchlogic, and "base html style":http://github.com/pilu/web-app-theme. Most of the functionality is built with standard ruby gems. Clearly, I am not trying to reinvent the wheel, but to embrace our wonderful community.
26
+
27
+ <pre>
28
+ ruby script/generate base_scaffold Product name:string price:decimal notes:text enabled:boolean
29
+ </pre>
30
+
31
+ h2. Dependencies
32
+
33
+ * Ruby Gems
34
+ ** formtastic
35
+ ** haml
36
+ ** inherited_resources
37
+ ** searchlogic
38
+ ** validation_reflection
39
+ ** web-app-theme
40
+ ** will_paginate
41
+ ** show_for (version 0.1.3)
42
+
43
+ * Javascripts Files
44
+ ** "jquery":http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js
45
+ ** "jquery.form":http://jquery.malsup.com/form/jquery.form.js?2.36
46
+ ** "jquery-ui":http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js
47
+ ** "jrails":http://github.com/aaronchi/jrails/raw/master/javascripts/jrails.js
48
+ ** "livequery":http://github.com/brandonaaron/livequery/raw/master/jquery.livequery.js
49
+
50
+ h2. PLUS: Easy bootstrap of your new app!
51
+
52
+ If your starting with a new app, then you can rely on my own rails template to install the dependencies.
53
+ *Warning*: Although it's base on other rails templates, it also includes my personal choices, so you may not agree with it.
54
+
55
+ <pre>
56
+ rails -m http://github.com/lucasefe/base-generators/raw/master/rails_template.rb my_new_rails_app
57
+ </pre>
58
+
59
+
60
+ h2. Disclaimer
61
+
62
+ This is a work in progress, so don't complain about it. If you don't like something, contribute to fix it.
63
+
64
+ (c) Copyright 2009 Lucas Florio. MIT License. Do whatever you want.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # Rakefile
2
+ require 'rubygems'
3
+ require 'rake'
4
+
5
+ # require 'echoe'
6
+ # Echoe.new('base-generators', '0.1.0') do |p|
7
+ # p.summary = "Rails Generators using SearchLogic, Formtastic, jquery and many more."
8
+ # p.description = "BaseGenerators tries to ease the pain of starting a new app from scratch by automating tasks with generators."
9
+ # p.url = "http://github.com/lucasefe/base-generators"
10
+ # p.author = "Lucas Efe"
11
+ # p.email = "lucasefe@gmail.com"
12
+ # p.ignore_pattern = ["tmp/*", "script/*"]
13
+ # p.development_dependencies = []
14
+ # end
15
+ #
16
+
17
+ begin
18
+ require 'jeweler'
19
+ Jeweler::Tasks.new do |gemspec|
20
+ gemspec.name = "base-generators"
21
+ gemspec.summary = "Rails Generators using SearchLogic, Formtastic, jquery and many more."
22
+ gemspec.description = "BaseGenerators tries to ease the pain of starting a new app from scratch by automating tasks with generators."
23
+ gemspec.homepage = "http://github.com/lucasefe/base-generators"
24
+ gemspec.authors = ["Lucas Efe"]
25
+ gemspec.email = "lucasefe@gmail.com"
26
+ end
27
+ Jeweler::GemcutterTasks.new
28
+ rescue LoadError
29
+ puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
30
+ end
31
+
32
+
33
+
34
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
35
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{base-generators}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Lucas Efe"]
12
+ s.date = %q{2010-04-26}
13
+ s.description = %q{BaseGenerators tries to ease the pain of starting a new app from scratch by automating tasks with generators.}
14
+ s.email = %q{lucasefe@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.textile"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.textile",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "base-generators.gemspec",
25
+ "generators/base_bootstrap/base_bootstrap_generator.rb",
26
+ "generators/base_bootstrap/templates/_block.html.haml",
27
+ "generators/base_bootstrap/templates/_block_form.html.haml",
28
+ "generators/base_bootstrap/templates/_flashes.html.haml",
29
+ "generators/base_bootstrap/templates/_header.html.haml",
30
+ "generators/base_bootstrap/templates/_secondary_navigation.html.haml",
31
+ "generators/base_bootstrap/templates/_sidebar.html.haml",
32
+ "generators/base_bootstrap/templates/base_helper.rb",
33
+ "generators/base_bootstrap/templates/layout.html.haml",
34
+ "generators/base_scaffold/base_scaffold_generator.rb",
35
+ "generators/base_scaffold/templates/common.js",
36
+ "generators/base_scaffold/templates/controller.rb",
37
+ "generators/base_scaffold/templates/helper.rb",
38
+ "generators/base_scaffold/templates/migration.rb",
39
+ "generators/base_scaffold/templates/model.rb",
40
+ "generators/base_scaffold/templates/view__collection.haml",
41
+ "generators/base_scaffold/templates/view__form.haml",
42
+ "generators/base_scaffold/templates/view__search.haml",
43
+ "generators/base_scaffold/templates/view_edit.haml",
44
+ "generators/base_scaffold/templates/view_index.haml",
45
+ "generators/base_scaffold/templates/view_index.js.haml",
46
+ "generators/base_scaffold/templates/view_new.haml",
47
+ "generators/base_scaffold/templates/view_show.haml",
48
+ "rails/init.rb",
49
+ "rails_template.rb",
50
+ "tasks/scaffold_it_tasks.rake",
51
+ "test/scaffold_it_test.rb",
52
+ "test/test_helper.rb",
53
+ "uninstall.rb"
54
+ ]
55
+ s.homepage = %q{http://github.com/lucasefe/base-generators}
56
+ s.rdoc_options = ["--charset=UTF-8"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.3.6}
59
+ s.summary = %q{Rails Generators using SearchLogic, Formtastic, jquery and many more.}
60
+ s.test_files = [
61
+ "test/scaffold_it_test.rb",
62
+ "test/test_helper.rb"
63
+ ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
+ s.specification_version = 3
68
+
69
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
+ else
71
+ end
72
+ else
73
+ end
74
+ end
75
+
@@ -0,0 +1,29 @@
1
+ # Basado en el scaffold generator de Resource Controller.
2
+ class BaseBootstrapGenerator < Rails::Generator::NamedBase
3
+ def initialize(runtime_args, runtime_options = {})
4
+ super
5
+ @layout_name = @name.underscore
6
+ end
7
+
8
+ def manifest
9
+ record do |m|
10
+ m.directory(File.join('app/views/layouts'))
11
+ m.directory(File.join('app/views/common'))
12
+ m.directory(File.join('app/helpers'))
13
+
14
+ templates = File.join([File.dirname(__FILE__), "templates"])
15
+ Dir.glob(File.join([templates, "_*.html.haml"])).each do |html|
16
+ html_basename = File.basename(html)
17
+ m.file(html_basename, "app/views/common/#{html_basename}")
18
+ end
19
+ m.file("layout.html.haml", "app/views/layouts/#{@layout_name}.html.haml")
20
+ m.file("base_helper.rb", "app/helpers/base_helper.rb")
21
+ end
22
+ end
23
+
24
+ protected
25
+ # Override with your own usage banner.
26
+ def banner
27
+ "Usage: #{$0} base_bootstrap application"
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ #block-tables.block
2
+ .secondary_navigation
3
+ = secondary_navigation
4
+ .content
5
+ %h2.title= title
6
+ .inner
7
+ - unless options[:no_flash] == true
8
+ = flashes
9
+ = content
@@ -0,0 +1,8 @@
1
+ #block-forms.block
2
+ .secondary_navigation
3
+ = render :partial => 'common/secondary_navigation'
4
+ .content
5
+ %h2.title= title
6
+ .inner
7
+ = flashes
8
+ = content
@@ -0,0 +1,5 @@
1
+ - unless flash.blank?
2
+ .flash
3
+ - flash.keys.each do |level|
4
+ .message{:class => level.to_s}
5
+ %p= flash[level]
@@ -0,0 +1,16 @@
1
+ #header
2
+ %h1= link_to APP_CONFIG[:site_name]
3
+ #user-navigation
4
+ %ul
5
+ %li= link_to "Profile"
6
+ %li.logout= link_to "Logout"
7
+ .clear
8
+ #main-navigation
9
+ %ul
10
+ %li= link_to "Dashboard"
11
+ %li= link_to "Menu 1"
12
+ %li= link_to "Menu 2"
13
+ %li= link_to "Menu 3"
14
+ .clear
15
+
16
+
@@ -0,0 +1,12 @@
1
+ .secondary-navigation
2
+ %ul
3
+ %li
4
+ %a{ :href => "#" }
5
+ Sub Object 1
6
+ %li
7
+ %a{ :href => "#" }
8
+ Sub Object 2
9
+ %li
10
+ %a{ :href => "#" }
11
+ Sub Object 3
12
+ .clear
@@ -0,0 +1,15 @@
1
+ - show_content_if yield(:actions) do |content|
2
+ .block
3
+ %h3.toggle-block Actions
4
+ .sidebar-block
5
+ %ul.navigation
6
+ = content
7
+ .clear
8
+
9
+ - show_content_if yield(:search) do |content|
10
+ .block
11
+ %h3.toggle-block
12
+ %a{:title => "Click to show/hide search box"} Search
13
+ .sidebar-block{:style => 'display:none;'}
14
+ = content
15
+ .clear
@@ -0,0 +1,67 @@
1
+ module BaseHelper
2
+ mattr_accessor :default_secondary_navigation_path
3
+ @@default_secondary_navigation_path = 'common/secondary_navigation'
4
+ def title(page_title, show_title = true)
5
+ @content_for_title = page_title.to_s
6
+ @show_title = show_title
7
+ end
8
+
9
+ def show_title?
10
+ @show_title
11
+ end
12
+ def nav_link(title, url, options = {})
13
+ link = link_to(title, url)
14
+ # solo si LockDown me deja!
15
+ unless link.blank?
16
+ # Activo el item?
17
+ css = {}
18
+ css = {:class => "active"} if (params[:controller].=~ options[:active] || params[:controller].include?(title.underscore))
19
+ haml_tag :li, css do
20
+ haml_concat link
21
+ end
22
+ end
23
+ end
24
+ def stylesheet(*args)
25
+ content_for(:head) { stylesheet_link_tag(*args) }
26
+ end
27
+
28
+ def javascript(*args)
29
+ content_for(:head) { javascript_include_tag(*args) }
30
+ end
31
+ def show_content_if(content, &block)
32
+ if content.present?
33
+ yield(content)
34
+ end
35
+ end
36
+ def sidebar_link(name, options = {}, html_options = nil)
37
+ content_tag(:li, link_to(name, options, html_options))
38
+ end
39
+ def navigation_block(nav = nil)
40
+ render(:partial => (nav||@@default_secondary_navigation_path))
41
+ end
42
+ def flashes
43
+ render :partial => 'common/flashes'
44
+ end
45
+ def block(title, options = {}, &block)
46
+ content = capture(&block)
47
+ out = render :partial => 'common/block', :locals => {
48
+ :secondary_navigation => secondary_navigation_content,
49
+ :title => title,
50
+ :content => content,
51
+ :options => options
52
+ }
53
+ concat out
54
+ end
55
+ def secondary_navigation_content
56
+ if @@default_secondary_navigation_path
57
+ render(:partial => @@default_secondary_navigation_path)
58
+ else
59
+ ""
60
+ end
61
+ end
62
+ def block_form(title, &block)
63
+ content = capture(&block)
64
+ out = render :partial => 'common/block_form', :locals => { :title => title, :content => content}
65
+ concat out
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ !!! Strict
2
+ %html{ :lang => "en", :xmlns => "http://www.w3.org/1999/xhtml" }
3
+ %head
4
+ %meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-Type" }
5
+ %title
6
+ = h(yield(:title) || APP_CONFIG[:site_name] || "APP Name")
7
+ = stylesheet_link_tag 'web_app_theme', "themes/reidb-greenish/style"
8
+ = stylesheet_link_tag 'formtastic', "formtastic_changes"
9
+ = javascript_include_tag 'jquery'
10
+ = javascript_include_tag 'jquery-ui'
11
+ = javascript_include_tag 'jquery.form'
12
+ = javascript_include_tag 'jrails'
13
+ = javascript_include_tag 'jquery.livequery'
14
+ = yield(:head)
15
+ = javascript_include_tag 'application'
16
+ %body
17
+ #container
18
+ = render :partial => 'common/header'
19
+ #wrapper
20
+ #main
21
+ = yield
22
+ #footer
23
+ .block
24
+ %p
25
+ Copyright &copy; 2009 Your Site.
26
+ #sidebar
27
+ = render :partial => 'common/sidebar'
28
+ .clear
@@ -0,0 +1,138 @@
1
+ # Basado en el scaffold generator de Resource Controller.
2
+ class BaseScaffoldGenerator < Rails::Generator::NamedBase
3
+ attr_reader :controller_name,
4
+ :controller_class_path,
5
+ :controller_file_path,
6
+ :controller_class_nesting,
7
+ :controller_class_nesting_depth,
8
+ :controller_class_name,
9
+ :controller_singular_name,
10
+ :controller_plural_name,
11
+ :resource_edit_path,
12
+ :default_file_extension,
13
+ :generator_default_file_extension
14
+ alias_method :controller_file_name, :controller_singular_name
15
+ alias_method :controller_table_name, :controller_plural_name
16
+
17
+ def initialize(runtime_args, runtime_options = {})
18
+ super
19
+ @controller_name = @name.pluralize
20
+
21
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
22
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
23
+
24
+ if @controller_class_nesting.empty?
25
+ @controller_class_name = @controller_class_name_without_nesting
26
+ else
27
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
28
+ end
29
+ end
30
+
31
+ def manifest
32
+ generator_default_file_extension = "haml"
33
+ default_file_extension = "html.#{generator_default_file_extension}"
34
+ record do |m|
35
+ m.class_collisions(class_path, "#{class_name}")
36
+
37
+ # Controller, helper, views, and test directories.
38
+ m.directory(File.join('app/models', class_path))
39
+ m.directory(File.join('app/controllers', controller_class_path))
40
+ m.directory(File.join('app/helpers', controller_class_path))
41
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
42
+
43
+ scaffold_views.each do |action|
44
+ m.template(
45
+ "view_#{action}.#{generator_default_file_extension}",
46
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
47
+ )
48
+ end
49
+ m.template("view__collection.#{generator_default_file_extension}",
50
+ File.join('app/views', controller_class_path, controller_file_name, "_#{plural_name}.#{default_file_extension}" ))
51
+ m.template("view_index.js.#{generator_default_file_extension}",
52
+ File.join('app/views', controller_class_path, controller_file_name, "index.js.#{generator_default_file_extension}" ))
53
+
54
+
55
+ m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
56
+ m.template('controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
57
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
58
+
59
+ m.template('common.js', 'public/javascripts/common.js')
60
+
61
+ unless options[:skip_migration]
62
+ migration_template = 'migration.rb'
63
+
64
+ m.migration_template(
65
+ migration_template, 'db/migrate',
66
+ :assigns => {
67
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
68
+ :attributes => attributes
69
+ },
70
+ :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
71
+ )
72
+ end
73
+
74
+ m.route_resources controller_file_name
75
+ end
76
+ end
77
+
78
+ protected
79
+ # Override with your own usage banner.
80
+ def banner
81
+ "Usage: #{$0} scaffold_for ModelName [field:type, field:type]"
82
+ end
83
+
84
+ def basic_views
85
+ %w[ index show new edit ]
86
+ end
87
+
88
+ def scaffold_views
89
+ basic_views + %w[ _form _search ]
90
+ end
91
+
92
+ def model_name
93
+ class_name.demodulize
94
+ end
95
+
96
+ # def add_options!(opt)
97
+ # opt.separator ''
98
+ # opt.separator 'Options:'
99
+ # opt.on("--rspec", "Force rspec mode (checks for RAILS_ROOT/spec by default)") { |v| options[:rspec] = true }
100
+ # end
101
+ end
102
+
103
+ module Rails
104
+ module Generator
105
+ class GeneratedAttribute
106
+ def default_value
107
+ @default_value ||= case type
108
+ when :int, :integer then "\"1\""
109
+ when :float then "\"1.5\""
110
+ when :decimal then "\"9.99\""
111
+ when :datetime, :timestamp, :time then "Time.now"
112
+ when :date then "Date.today"
113
+ when :string then "\"MyString\""
114
+ when :text then "\"MyText\""
115
+ when :boolean then "false"
116
+ else
117
+ ""
118
+ end
119
+ end
120
+ def default_options
121
+ case type
122
+ when :decimal
123
+ ", :precision => 8, :scale => 2"
124
+ else
125
+ ""
126
+ end
127
+ end
128
+ def input_type
129
+ @input_type ||= case type
130
+ when :text then "textarea"
131
+ when :boolean then "check_box"
132
+ else
133
+ "input"
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,19 @@
1
+ jQuery.ajaxSetup({
2
+ beforeSend: function(xhr) {
3
+ xhr.setRequestHeader("Accept", "text/javascript");
4
+ }
5
+ });
6
+
7
+ $(function(){
8
+ $('.order_by a, .pagination a').livequery('click', function() {
9
+ $('#results').load(this.href + '');
10
+ return false;
11
+ });
12
+
13
+ $('#search').livequery(function(){
14
+ $(this).ajaxForm({target: '#results'});
15
+ });
16
+ $('.toggle-block').click(function(){
17
+ $(this).parents('.block').children('.sidebar-block').toggle();
18
+ });
19
+ });
@@ -0,0 +1,8 @@
1
+ class <%= controller_class_name %>Controller < InheritedResources::Base
2
+ respond_to :html, :xml, :js, :json
3
+ protected
4
+ def collection
5
+ @search = end_of_association_chain.search(params[:search])
6
+ @<%= plural_name %> ||= @search.paginate(:page => params[:page], :per_page => 10)
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ module <%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,15 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %>, :force => true do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.default_options %>
6
+ <% end -%>
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :<%= table_name %>
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,23 @@
1
+ #results
2
+ %table.table
3
+ %tr
4
+ <% for attribute in attributes -%>
5
+ %th.order_by<%= (attribute == attributes.first) ? ".first" : "" %>= order @search, :by => :<%= attribute.name %>
6
+ <% end -%>
7
+ %th.last
8
+ - <%= plural_name %>.each do |<%= singular_name %>|
9
+ %tr{:class => cycle('odd', 'even')}
10
+ <%- for attribute in attributes %>
11
+ %td= h <%= singular_name %>.<%= attribute.name %>
12
+ <%- end -%>
13
+ %td.last
14
+ = link_to 'Show', resource_url(<%= singular_name %>)
15
+ = link_to 'Edit', edit_resource_url(<%= singular_name %>)
16
+ = link_to 'Destroy', resource_url(<%= singular_name %>), :confirm => 'Are you sure?', :method => :delete
17
+
18
+ .actions-bar
19
+ = will_paginate <%= plural_name %>
20
+
21
+ .clear
22
+
23
+
@@ -0,0 +1,4 @@
1
+ - f.inputs do
2
+ <%- for attribute in attributes -%>
3
+ = f.input :<%= attribute.name %>
4
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ - semantic_form_for @search, :html => {:class => 'search', :id => 'search' } do |f|
2
+ - f.inputs do
3
+ <%- for attribute in attributes -%>
4
+ = f.input :<%= attribute.name %>_like, :label => '<%= attribute.name.humanize %>', :required => false
5
+ <%- end -%>
6
+ = f.submit "Search"
7
+ = link_to 'Cancel', "#", :class => 'toggle-block'
@@ -0,0 +1,8 @@
1
+ - block "Editing <%= singular_name.underscore.humanize %>" do
2
+ - semantic_form_for(@<%= singular_name %>, :url => resource_url, :html => { :method => :put}) do |f|
3
+ = render :partial => "form", :locals => { :f => f }
4
+ = f.buttons
5
+
6
+ - content_for :actions do
7
+ = sidebar_link 'Show', resource_url
8
+ = sidebar_link 'View All', collection_url
@@ -0,0 +1,10 @@
1
+ - javascript 'common'
2
+
3
+ - block '<%= plural_name.underscore.humanize %>' do
4
+ = render :partial => '<%= plural_name %>', :object => @<%= plural_name %>
5
+
6
+ - content_for :actions do
7
+ = sidebar_link 'New <%= singular_name.underscore.humanize %>', new_resource_url
8
+
9
+ - content_for :search do
10
+ = render :partial => 'search'
@@ -0,0 +1 @@
1
+ = render :partial => '<%= plural_name %>', :object => @<%= plural_name %>
@@ -0,0 +1,7 @@
1
+ - block "New <%= singular_name.underscore.humanize %>" do
2
+ - semantic_form_for(@<%= singular_name %>, :url => collection_url) do |f|
3
+ = render :partial => "form", :locals => { :f => f }
4
+ = f.buttons
5
+
6
+ - content_for :actions do
7
+ = sidebar_link 'View All', collection_url
@@ -0,0 +1,9 @@
1
+ - block "<%= singular_name.underscore.humanize %>" do
2
+ - show_for @<%= singular_name %> do |<%= singular_name %>|
3
+ <% for attribute in attributes %>
4
+ = <%= singular_name %>.attribute :<%= attribute.name %>
5
+ <% end -%>
6
+
7
+ - content_for :actions do
8
+ = sidebar_link 'Edit', edit_resource_url
9
+ = sidebar_link 'View All', collection_url
data/rails/init.rb ADDED
File without changes
data/rails_template.rb ADDED
@@ -0,0 +1,218 @@
1
+ # Delete unnecessary files
2
+ run "rm README"
3
+ run "rm public/index.html"
4
+ run "rm public/favicon.ico"
5
+ run "rm public/robots.txt"
6
+ run "rm -f public/javascripts/*"
7
+ file 'public/javascripts/application.js', ''
8
+ # Set up git repository
9
+ git :init
10
+
11
+ # Copy database.yml for distribution use
12
+ run "cp config/database.yml config/database.yml.example"
13
+ run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
14
+ run %{find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore}
15
+ file '.gitignore', <<-END
16
+ doc/api
17
+ doc/app
18
+ .DS_Store
19
+ config/database.yml
20
+ db/*.sqlite3
21
+ db/schema.rb
22
+ tmp/**/*
23
+ log/*.log
24
+ nbproject/
25
+ *.sw?
26
+ db/sphinx
27
+ public/system
28
+ index/
29
+
30
+ END
31
+
32
+ gem 'inherited_resources', :source => 'http://gemcutter.org', :version => '~> 1.0.0'
33
+ gem 'formtastic', :source => 'http://gemcutter.org'
34
+ gem 'web-app-theme', :source => 'http://gemcutter.org', :lib => false
35
+ gem 'haml'
36
+ gem 'searchlogic', :version => '~> 2.3.6'
37
+ gem 'validation_reflection'
38
+ gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter.org'
39
+ # Testing
40
+ gem 'rspec', :lib => false
41
+ gem 'rspec-rails', :lib => false
42
+ gem 'remarkable_rails', :lib => false
43
+ gem 'factory_girl', :lib => 'factory_girl', :source => 'http://gemcutter.org'
44
+
45
+ rake("gems:install")
46
+
47
+ plugin 'jrails', :git => "git://github.com/aaronchi/jrails.git"
48
+ plugin 'hoptoad_notifier', :git => "git://github.com/thoughtbot/hoptoad_notifier.git"
49
+ plugin 'base-generators', :git => "git://github.com/lucasefe/base-generators.git"
50
+
51
+ # Download JQuery
52
+ run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js > public/javascripts/jquery.js"
53
+ run "curl -L http://github.com/malsup/form/raw/master/jquery.form.js?v2.40 > public/javascripts/jquery.form.js"
54
+ run "curl -L http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js > public/javascripts/jquery-ui.js"
55
+ run "curl -L http://github.com/aaronchi/jrails/raw/master/javascripts/jrails.js > public/javascripts/jrails.js"
56
+ run "curl -L http://github.com/brandonaaron/livequery/raw/master/jquery.livequery.js > public/javascripts/jquery.livequery.js"
57
+
58
+ # UTF-8
59
+ run "curl -L http://gist.github.com/raw/271196/def21fbdbbcc55b0e636cd381f87d0b8c144eea1/enforce_utf8.rb > config/initializers/enforce_utf8.rb"
60
+
61
+ rake('db:sessions:create')
62
+ initializer 'session_store.rb', <<-END
63
+ ActionController::Base.session = { :session_key => '_#{(1..6).map { |x| (65 + rand(26)).chr }.join}_session', :secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}' }
64
+ ActionController::Base.session_store = :active_record_store
65
+ END
66
+ initializer 'hoptoad.rb',
67
+ %q{HoptoadNotifier.configure do |config|
68
+ config.api_key = 'HOPTOAD-KEY'
69
+ end
70
+ }
71
+ initializer 'requires.rb',
72
+ %q{Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f|
73
+ require f
74
+ end
75
+ }
76
+
77
+ initializer 'load_settings.rb', %q(APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")[RAILS_ENV].symbolize_keys)
78
+ file 'config/settings.yml', %q(
79
+ development: &non_production_settings
80
+ site_name: App From Hell!
81
+ admin_email: some@example.com
82
+
83
+ test:
84
+ <<: *non_production_settings
85
+
86
+ staging:
87
+ <<: *non_production_settings
88
+
89
+ production:
90
+ <<: *non_production_settings
91
+ )
92
+ capify!
93
+
94
+ file 'config/deploy.rb',
95
+ %q{set :stages, %w(staging production)
96
+ set :default_stage, 'staging'
97
+ require 'capistrano/ext/multistage'
98
+
99
+ before "deploy:setup", "db:password"
100
+
101
+ desc "Run this after every successful deployment"
102
+ task :after_default do
103
+ cleanup
104
+ end
105
+ end
106
+
107
+ namespace :db do
108
+ desc "Create database password in shared path"
109
+ task :password do
110
+ set :db_password, Proc.new { Capistrano::CLI.password_prompt("Remote database password: ") }
111
+ run "mkdir -p #{shared_path}/config"
112
+ put db_password, "#{shared_path}/config/dbpassword"
113
+ end
114
+ end
115
+ }
116
+
117
+ file 'config/deploy/staging.rb',
118
+ %q{# For migrations
119
+ set :rails_env, 'staging'
120
+
121
+ # Who are we?
122
+ set :application, 'CHANGEME'
123
+ set :repository, "git@192.168.101.154:/var/git/#{application}.git"
124
+ set :scm, "git"
125
+ set :deploy_via, :remote_cache
126
+ set :branch, "staging"
127
+
128
+ # Where to deploy to?
129
+ role :web, "staging.example.com"
130
+ role :app, "staging.example.com"
131
+ role :db, "staging.example.com", :primary => true
132
+
133
+ # Deploy details
134
+ set :user, "#{application}"
135
+ set :deploy_to, "/var/apps/#{application}"
136
+ set :use_sudo, false
137
+ set :checkout, 'export'
138
+ }
139
+
140
+ file 'config/deploy/production.rb',
141
+ %q{# For migrations
142
+ set :rails_env, 'production'
143
+
144
+ # Who are we?
145
+ set :application, 'CHANGEME'
146
+ set :repository, "git@192.168.101.154:/var/git/#{application}.git"
147
+ set :scm, "git"
148
+ set :deploy_via, :remote_cache
149
+
150
+ set :branch, "production"
151
+
152
+ # Where to deploy to?
153
+ role :web, "production.example.com"
154
+ role :app, "production.example.com"
155
+ role :db, "production.example.com", :primary => true
156
+
157
+ # Deploy details
158
+ set :user, "#{application}"
159
+ set :deploy_to, "/var/apps/#{application}"
160
+ set :use_sudo, false
161
+ set :checkout, 'export'
162
+ }
163
+
164
+ # Commit all work so far to the repository
165
+ git :add => '.'
166
+ git :commit => "-a -m 'Initial commit'"
167
+
168
+ generate("base_bootstrap application")
169
+ generate("rspec")
170
+ generate("theme --no-layout --theme=reidb-greenish")
171
+ generate("formtastic")
172
+ file 'public/stylesheets/formtastic_changes.css',
173
+ %q(form.formtastic.search fieldset {
174
+ margin-bottom: 0.5em;
175
+ }
176
+
177
+ form.formtastic.search fieldset legend {
178
+ font-size: 1.3em;
179
+ margin-bottom: 0.5em;
180
+ }
181
+ form.formtastic.search {
182
+ background-color: #F1F1F1;
183
+ padding: .5em;
184
+ margin-bottom: 0.5em;
185
+ }
186
+
187
+ .toggle {
188
+ cursor: pointer;
189
+ text-decoration: underline;
190
+ }
191
+ )
192
+ file 'lib/tasks/bootstrap.rake',
193
+ %q(namespace :app do
194
+ namespace :development do
195
+ desc "Resets the environment!"
196
+ task :reset => [ "db:drop", "db:create", "db:migrate", :bootstrap ]
197
+ desc "Bootstrap"
198
+ task :bootstrap => [ :environment ]
199
+ end
200
+ namespace :staging do
201
+ desc "Resets the environment!"
202
+ task :reset => [ "db:drop", "db:create", "db:migrate", :bootstrap ]
203
+ desc "Bootstrap"
204
+ task :bootstrap => [ :environment ]
205
+ end
206
+ namespace :production do
207
+ desc "Resets the environment!"
208
+ task :reset => [ "db:drop", "db:create", "db:migrate", :bootstrap ]
209
+ desc "Bootstrap"
210
+ task :bootstrap => [ :environment ]
211
+ end
212
+ end
213
+
214
+ desc "Alias de app:development:reset"
215
+ task :adr => [ "app:development:reset" ]
216
+ )
217
+ # Success!
218
+ puts "Initial Commit!"
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :scaffold_it do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ScaffoldItTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: base-generators
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Lucas Efe
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-26 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: BaseGenerators tries to ease the pain of starting a new app from scratch by automating tasks with generators.
22
+ email: lucasefe@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.textile
29
+ files:
30
+ - .gitignore
31
+ - MIT-LICENSE
32
+ - README.textile
33
+ - Rakefile
34
+ - VERSION
35
+ - base-generators.gemspec
36
+ - generators/base_bootstrap/base_bootstrap_generator.rb
37
+ - generators/base_bootstrap/templates/_block.html.haml
38
+ - generators/base_bootstrap/templates/_block_form.html.haml
39
+ - generators/base_bootstrap/templates/_flashes.html.haml
40
+ - generators/base_bootstrap/templates/_header.html.haml
41
+ - generators/base_bootstrap/templates/_secondary_navigation.html.haml
42
+ - generators/base_bootstrap/templates/_sidebar.html.haml
43
+ - generators/base_bootstrap/templates/base_helper.rb
44
+ - generators/base_bootstrap/templates/layout.html.haml
45
+ - generators/base_scaffold/base_scaffold_generator.rb
46
+ - generators/base_scaffold/templates/common.js
47
+ - generators/base_scaffold/templates/controller.rb
48
+ - generators/base_scaffold/templates/helper.rb
49
+ - generators/base_scaffold/templates/migration.rb
50
+ - generators/base_scaffold/templates/model.rb
51
+ - generators/base_scaffold/templates/view__collection.haml
52
+ - generators/base_scaffold/templates/view__form.haml
53
+ - generators/base_scaffold/templates/view__search.haml
54
+ - generators/base_scaffold/templates/view_edit.haml
55
+ - generators/base_scaffold/templates/view_index.haml
56
+ - generators/base_scaffold/templates/view_index.js.haml
57
+ - generators/base_scaffold/templates/view_new.haml
58
+ - generators/base_scaffold/templates/view_show.haml
59
+ - rails/init.rb
60
+ - rails_template.rb
61
+ - tasks/scaffold_it_tasks.rake
62
+ - test/scaffold_it_test.rb
63
+ - test/test_helper.rb
64
+ - uninstall.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/lucasefe/base-generators
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Rails Generators using SearchLogic, Formtastic, jquery and many more.
95
+ test_files:
96
+ - test/scaffold_it_test.rb
97
+ - test/test_helper.rb