bravo-generators 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.gitignore +17 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +23 -0
  6. data/Rakefile +2 -0
  7. data/bravo-generators.gemspec +17 -0
  8. data/lib/generators/bravo.rb +28 -0
  9. data/lib/generators/bravo/config/USAGE +23 -0
  10. data/lib/generators/bravo/config/config_generator.rb +24 -0
  11. data/lib/generators/bravo/config/templates/config.yml +8 -0
  12. data/lib/generators/bravo/config/templates/load_config.rb +2 -0
  13. data/lib/generators/bravo/layout/USAGE +25 -0
  14. data/lib/generators/bravo/layout/layout_generator.rb +29 -0
  15. data/lib/generators/bravo/layout/templates/error_messages_helper.rb +23 -0
  16. data/lib/generators/bravo/layout/templates/layout.html.erb +19 -0
  17. data/lib/generators/bravo/layout/templates/layout.html.haml +21 -0
  18. data/lib/generators/bravo/layout/templates/layout_helper.rb +22 -0
  19. data/lib/generators/bravo/layout/templates/stylesheet.css +83 -0
  20. data/lib/generators/bravo/layout/templates/stylesheet.sass +73 -0
  21. data/lib/generators/bravo/scaffold/USAGE +51 -0
  22. data/lib/generators/bravo/scaffold/scaffold_generator.rb +318 -0
  23. data/lib/generators/bravo/scaffold/templates/actions/create.rb +8 -0
  24. data/lib/generators/bravo/scaffold/templates/actions/destroy.rb +5 -0
  25. data/lib/generators/bravo/scaffold/templates/actions/edit.rb +3 -0
  26. data/lib/generators/bravo/scaffold/templates/actions/index.rb +3 -0
  27. data/lib/generators/bravo/scaffold/templates/actions/new.rb +3 -0
  28. data/lib/generators/bravo/scaffold/templates/actions/show.rb +3 -0
  29. data/lib/generators/bravo/scaffold/templates/actions/update.rb +8 -0
  30. data/lib/generators/bravo/scaffold/templates/controller.rb +3 -0
  31. data/lib/generators/bravo/scaffold/templates/fixtures.yml +9 -0
  32. data/lib/generators/bravo/scaffold/templates/helper.rb +2 -0
  33. data/lib/generators/bravo/scaffold/templates/migration.rb +16 -0
  34. data/lib/generators/bravo/scaffold/templates/model.rb +4 -0
  35. data/lib/generators/bravo/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  36. data/lib/generators/bravo/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  37. data/lib/generators/bravo/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  38. data/lib/generators/bravo/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  39. data/lib/generators/bravo/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  40. data/lib/generators/bravo/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  41. data/lib/generators/bravo/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  42. data/lib/generators/bravo/scaffold/templates/tests/rspec/controller.rb +8 -0
  43. data/lib/generators/bravo/scaffold/templates/tests/rspec/model.rb +7 -0
  44. data/lib/generators/bravo/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  45. data/lib/generators/bravo/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  46. data/lib/generators/bravo/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  47. data/lib/generators/bravo/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  48. data/lib/generators/bravo/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  49. data/lib/generators/bravo/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  50. data/lib/generators/bravo/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  51. data/lib/generators/bravo/scaffold/templates/tests/shoulda/controller.rb +5 -0
  52. data/lib/generators/bravo/scaffold/templates/tests/shoulda/model.rb +7 -0
  53. data/lib/generators/bravo/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  54. data/lib/generators/bravo/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  55. data/lib/generators/bravo/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  56. data/lib/generators/bravo/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  57. data/lib/generators/bravo/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  58. data/lib/generators/bravo/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  59. data/lib/generators/bravo/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  60. data/lib/generators/bravo/scaffold/templates/tests/testunit/controller.rb +5 -0
  61. data/lib/generators/bravo/scaffold/templates/tests/testunit/model.rb +7 -0
  62. data/lib/generators/bravo/scaffold/templates/views/erb/_form.html.erb +10 -0
  63. data/lib/generators/bravo/scaffold/templates/views/erb/edit.html.erb +14 -0
  64. data/lib/generators/bravo/scaffold/templates/views/erb/index.html.erb +29 -0
  65. data/lib/generators/bravo/scaffold/templates/views/erb/new.html.erb +7 -0
  66. data/lib/generators/bravo/scaffold/templates/views/erb/show.html.erb +20 -0
  67. data/lib/generators/bravo/scaffold/templates/views/haml/_form.html.haml +9 -0
  68. data/lib/generators/bravo/scaffold/templates/views/haml/edit.html.haml +14 -0
  69. data/lib/generators/bravo/scaffold/templates/views/haml/index.html.haml +25 -0
  70. data/lib/generators/bravo/scaffold/templates/views/haml/new.html.haml +7 -0
  71. data/lib/generators/bravo/scaffold/templates/views/haml/show.html.haml +20 -0
  72. metadata +128 -0
@@ -0,0 +1,17 @@
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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bravo-generators.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Camel Song
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # Bravo Generators
2
+
3
+ My personal Rails generator scripts inspired by [nifty-generators]
4
+
5
+ ## Dependency
6
+
7
+ * Ruby 1.9.2+
8
+ * Rails ~> 3.1
9
+
10
+ ## Setup Guide
11
+ Add the gem to your Gemfile.
12
+
13
+ gem "bravo-generators", :group => :development
14
+
15
+ ## Contributing
16
+
17
+ 1. Fork it
18
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
19
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
20
+ 4. Push to the branch (`git push origin my-new-feature`)
21
+ 5. Create new Pull Request
22
+
23
+ [nifty-generators]: https://github.com/ryanb/nifty-generators
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["Camel Song"]
4
+ gem.email = ["neosoyn@gmail.com"]
5
+ gem.description = %q{A collection of useful Rails generator scripts for scaffolding, layout files, and more.}
6
+ gem.summary = %q{A collection of useful Rails generator scripts}
7
+ gem.homepage = "https://github.com/camelsong/bravo-generators"
8
+
9
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
10
+ gem.files = `git ls-files`.split("\n")
11
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ gem.name = "bravo-generators"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = "0.1.1"
15
+
16
+ gem.add_development_dependency 'rails', '~> 3.1'
17
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Bravo
4
+ module Generators
5
+ class Base < Rails::Generators::Base #:nodoc:
6
+ def self.source_root
7
+ @_bravo_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'bravo', generator_name, 'templates'))
8
+ end
9
+
10
+ def self.banner
11
+ "rails generate bravo:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
+
14
+ private
15
+
16
+ def add_gem(name, options = {})
17
+ gemfile_content = File.read(destination_path("Gemfile"))
18
+ File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
19
+ gem name, options unless gemfile_content.include? name
20
+ end
21
+
22
+ def print_usage
23
+ self.class.help(Thor::Base.shell.new)
24
+ exit
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ Description:
2
+ The bravo_config generator creates YAML file in your config
3
+ directory and an initializer to load this config. The config has a
4
+ separate section for each environment. This is a great place to put
5
+ any config settings you don't want in your app.
6
+
7
+ The config is loaded into a constant called APP_CONFIG by default,
8
+ this changes depending on the name you choose to pass the generator.
9
+ Use this constant to access the config settings like this.
10
+
11
+ APP_CONFIG[:some_setting]
12
+
13
+
14
+ Examples:
15
+ rails generate bravo:config
16
+
17
+ Config: config/app_config.yml
18
+ Initializer: config/initializers/load_app_config.rb
19
+
20
+ rails generate bravo:config passwords
21
+
22
+ Config: config/passwords_config.yml
23
+ Initializer: config/initializers/load_passwords_config.rb
@@ -0,0 +1,24 @@
1
+ require 'generators/bravo'
2
+
3
+ module Bravo
4
+ module Generators
5
+ class ConfigGenerator < Base
6
+ argument :config_name, :type => :string, :default => 'app', :banner => 'config_name'
7
+
8
+ def create_config
9
+ template "load_config.rb", "config/initializers/load_#{file_name}_config.rb"
10
+ copy_file "config.yml", "config/#{file_name}_config.yml"
11
+ end
12
+
13
+ private
14
+
15
+ def file_name
16
+ config_name.underscore
17
+ end
18
+
19
+ def constant_name
20
+ config_name.underscore.upcase
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ development:
2
+ domain: localhost:3000
3
+
4
+ test:
5
+ domain: test.host
6
+
7
+ production:
8
+ domain: example.com
@@ -0,0 +1,2 @@
1
+ raw_config = File.read("#{Rails.root}/config/<%= file_name %>_config.yml")
2
+ <%= constant_name %>_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys
@@ -0,0 +1,25 @@
1
+ Description:
2
+ The bravo_layout generator creates a basic layout, stylesheet and
3
+ helper which will give some structure to a starting Rails app.
4
+
5
+ The generator takes one argument which will be the name of the
6
+ layout and stylesheet files. If no argument is passed then it defaults
7
+ to "application".
8
+
9
+ The helper module includes some methods which can be called in any
10
+ template or partial to set variables to be used in the layout, such as
11
+ page title and javascript/stylesheet includes.
12
+
13
+ Examples:
14
+ rails generate bravo:layout
15
+
16
+ Layout: app/views/layouts/application.html.erb
17
+ Stylesheet: public/stylesheets/application.css
18
+ Helper: app/helpers/layout_helper.rb
19
+
20
+
21
+ rails generate bravo:layout admin
22
+
23
+ Layout: app/views/layouts/admin.html.erb
24
+ Stylesheet: public/stylesheets/admin.css
25
+ Helper: app/helpers/layout_helper.rb
@@ -0,0 +1,29 @@
1
+ require 'generators/bravo'
2
+
3
+ module Bravo
4
+ module Generators
5
+ class LayoutGenerator < Base
6
+ argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
7
+
8
+ class_option :haml, :desc => 'Generate HAML for view, and SASS for stylesheet.', :type => :boolean
9
+
10
+ def create_layout
11
+ if options.haml?
12
+ template 'layout.html.haml', "app/views/layouts/#{file_name}.html.haml"
13
+ copy_file 'stylesheet.sass', "public/stylesheets/sass/#{file_name}.sass"
14
+ else
15
+ template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
16
+ copy_file 'stylesheet.css', "public/stylesheets/#{file_name}.css"
17
+ end
18
+ copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
19
+ copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
20
+ end
21
+
22
+ private
23
+
24
+ def file_name
25
+ layout_name.underscore
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module ErrorMessagesHelper
2
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
3
+ def error_messages_for(*objects)
4
+ options = objects.extract_options!
5
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
6
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
7
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
8
+ unless messages.empty?
9
+ content_tag(:div, :class => "error_messages") do
10
+ list_items = messages.map { |msg| content_tag(:li, msg.html_safe) }
11
+ content_tag(:h2, options[:header_message].html_safe) + content_tag(:p, options[:message].html_safe) + content_tag(:ul, list_items.join.html_safe)
12
+ end
13
+ end
14
+ end
15
+
16
+ module FormBuilderAdditions
17
+ def error_messages(options = {})
18
+ @template.error_messages_for(@object, options)
19
+ end
20
+ end
21
+ end
22
+
23
+ ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
5
+ <%%= stylesheet_link_tag "<%= file_name %>" %>
6
+ <%%= javascript_include_tag :defaults %>
7
+ <%%= csrf_meta_tag %>
8
+ <%%= yield(:head) %>
9
+ </head>
10
+ <body>
11
+ <div id="container">
12
+ <%% flash.each do |name, msg| %>
13
+ <%%= content_tag :div, msg, :id => "flash_#{name}" %>
14
+ <%% end %>
15
+ <%%= content_tag :h1, yield(:title) if show_title? %>
16
+ <%%= yield %>
17
+ </div>
18
+ </body>
19
+ </html>
@@ -0,0 +1,21 @@
1
+ !!!
2
+ %html
3
+
4
+ %head
5
+ %title
6
+ = content_for?(:title) ? yield(:title) : "Untitled"
7
+ %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
8
+ = stylesheet_link_tag "<%= file_name %>"
9
+ = javascript_include_tag :defaults
10
+ = csrf_meta_tag
11
+ = yield(:head)
12
+
13
+ %body
14
+ #container
15
+ - flash.each do |name, msg|
16
+ = content_tag :div, msg, :id => "flash_#{name}"
17
+
18
+ - if show_title?
19
+ %h1= yield(:title)
20
+
21
+ = yield
@@ -0,0 +1,22 @@
1
+ # These helper methods can be called in your template to set variables to be used in the layout
2
+ # This module should be included in all views globally,
3
+ # to do so you may need to add this line to your ApplicationController
4
+ # helper :layout
5
+ module LayoutHelper
6
+ def title(page_title, show_title = true)
7
+ content_for(:title) { h(page_title.to_s) }
8
+ @show_title = show_title
9
+ end
10
+
11
+ def show_title?
12
+ @show_title
13
+ end
14
+
15
+ def stylesheet(*args)
16
+ content_for(:head) { stylesheet_link_tag(*args) }
17
+ end
18
+
19
+ def javascript(*args)
20
+ content_for(:head) { javascript_include_tag(*args) }
21
+ end
22
+ end
@@ -0,0 +1,83 @@
1
+ html, body {
2
+ background-color: #4B7399;
3
+ font-family: Verdana, Helvetica, Arial;
4
+ font-size: 14px;
5
+ }
6
+
7
+ a img {
8
+ border: none;
9
+ }
10
+
11
+ a {
12
+ color: #0000FF;
13
+ }
14
+
15
+ .clear {
16
+ clear: both;
17
+ height: 0;
18
+ overflow: hidden;
19
+ }
20
+
21
+ #container {
22
+ width: 75%;
23
+ margin: 0 auto;
24
+ background-color: #FFF;
25
+ padding: 20px 40px;
26
+ border: solid 1px black;
27
+ margin-top: 20px;
28
+ }
29
+
30
+ #flash_notice, #flash_error, #flash_alert {
31
+ padding: 5px 8px;
32
+ margin: 10px 0;
33
+ }
34
+
35
+ #flash_notice {
36
+ background-color: #CFC;
37
+ border: solid 1px #6C6;
38
+ }
39
+
40
+ #flash_error, #flash_alert {
41
+ background-color: #FCC;
42
+ border: solid 1px #C66;
43
+ }
44
+
45
+ .error_messages {
46
+ width: 400px;
47
+ border: 2px solid #CF0000;
48
+ padding: 0px;
49
+ padding-bottom: 12px;
50
+ margin-bottom: 20px;
51
+ background-color: #f0f0f0;
52
+ font-size: 12px;
53
+ }
54
+
55
+ .error_messages h2 {
56
+ text-align: left;
57
+ font-weight: bold;
58
+ padding: 5px 10px;
59
+ font-size: 12px;
60
+ margin: 0;
61
+ background-color: #c00;
62
+ color: #fff;
63
+ }
64
+
65
+ .error_messages p {
66
+ margin: 8px 10px;
67
+ }
68
+
69
+ .error_messages ul {
70
+ margin: 0;
71
+ }
72
+
73
+ .field_with_errors {
74
+ display: inline;
75
+ }
76
+
77
+ form .field, form .actions {
78
+ margin: 10px 0;
79
+ }
80
+
81
+ form label {
82
+ display: block;
83
+ }
@@ -0,0 +1,73 @@
1
+ $primary_color: #4b7399
2
+
3
+ body
4
+ background-color: $primary_color
5
+ font:
6
+ family: Verdana, Helvetica, Arial
7
+ size: 14px
8
+
9
+ a
10
+ color: blue
11
+ img
12
+ border: none
13
+
14
+ .clear
15
+ clear: both
16
+ height: 0
17
+ overflow: hidden
18
+
19
+ #container
20
+ width: 75%
21
+ margin: 0 auto
22
+ background: white
23
+ padding: 20px 40px
24
+ border: solid 1px black
25
+ margin-top: 20px
26
+
27
+ #flash_notice,
28
+ #flash_error,
29
+ #flash_alert
30
+ padding: 5px 8px
31
+ margin: 10px 0
32
+
33
+ #flash_notice
34
+ background-color: #ccffcc
35
+ border: solid 1px #66cc66
36
+
37
+ #flash_error,
38
+ #flash_alert
39
+ background-color: #ffcccc
40
+ border: solid 1px #cc6666
41
+
42
+ .error_messages
43
+ width: 400px
44
+ border: 2px solid #cf0000
45
+ padding: 0
46
+ padding-bottom: 12px
47
+ margin-bottom: 20px
48
+ background-color: #f0f0f0
49
+ font:
50
+ size: 12px
51
+ h2
52
+ text-align: left
53
+ padding: 5px 5px 5px 15px
54
+ margin: 0
55
+ font:
56
+ weight: bold
57
+ size: 12px
58
+ background-color: #cc0000
59
+ color: white
60
+ p
61
+ margin: 8px 10px
62
+ ul
63
+ margin: 0
64
+
65
+ .field_with_errors
66
+ display: inline
67
+
68
+ form .field,
69
+ form .actions
70
+ margin: 10px 0
71
+
72
+ form label
73
+ display: block