bootstrap-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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bootstrap-generators.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bootstrap-generators/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bootstrap-generators"
7
+ s.version = Bootstrap::Generators::VERSION
8
+ s.authors = ["Décio Ferreira"]
9
+ s.email = ["decio.ferreira@decioferreira.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Bootstrap-generators provides Twitter Bootstrap generators for Rails 3.}
12
+ s.description = %q{Bootstrap-generators provides Twitter Bootstrap generators for Rails 3. Bootstrap is a toolkit from Twitter designed to kickstart development of webapps and sites. Checkout http://twitter.github.com/bootstrap.}
13
+
14
+ s.rubyforge_project = "bootstrap-generators"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+
25
+ s.add_dependency 'railties', '~> 3.0'
26
+ s.add_development_dependency 'rails', '~> 3.0'
27
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails/generators'
2
+
3
+ module Bootstrap
4
+ module Generators; end
5
+ end
6
+
7
+ Rails::Generators.hidden_namespaces << 'rails'
8
+ Rails::Generators.hidden_namespaces << 'erb:controller' << 'erb:scaffold'
9
+
@@ -0,0 +1,5 @@
1
+ module Bootstrap
2
+ module Generators
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module Erb
2
+ module Generators
3
+ module TemplatePath
4
+ def source_root
5
+ File.expand_path(File.join(File.dirname(__FILE__), 'erb', generator_name, 'templates'))
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,11 @@
1
+ require 'generators/erb'
2
+ require 'rails/generators/erb/controller/controller_generator'
3
+
4
+ module Erb
5
+ module Generators
6
+ class ControllerGenerator
7
+ extend TemplatePath
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,25 @@
1
+ require 'generators/erb'
2
+ require 'rails/generators/erb/scaffold/scaffold_generator'
3
+
4
+ module Erb
5
+ module Generators
6
+ class ScaffoldGenerator
7
+ extend TemplatePath
8
+
9
+ hook_for :form_builder, :as => :scaffold
10
+
11
+ def copy_form_file
12
+ if options[:form_builder].nil?
13
+ filename = filename_with_extensions("_form")
14
+ template filename, File.join("app/views", controller_file_path, filename)
15
+ end
16
+ end
17
+
18
+ protected
19
+ def available_views
20
+ %w(index edit show new)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,59 @@
1
+ TestApp.routes.draw do |map|
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get :short
20
+ # post :toggle
21
+ # end
22
+ #
23
+ # collection do
24
+ # get :sold
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get :recent, :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id(.:format)))'
58
+ end
59
+
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class Erb::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
4
+ destination File.join(Rails.root)
5
+ tests Rails::Generators::ControllerGenerator
6
+ arguments %w(Account foo bar --template-engine erb)
7
+
8
+ setup :prepare_destination
9
+ setup :copy_routes
10
+
11
+ test "should invoke template engine" do
12
+ run_generator
13
+ assert_file "app/views/account/foo.html.erb", %r(app/views/account/foo\.html\.erb)
14
+ assert_file "app/views/account/bar.html.erb", %r(app/views/account/bar\.html\.erb)
15
+ end
16
+ end
17
+
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class Erb::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
4
+ destination File.join(Rails.root)
5
+ tests Rails::Generators::ScaffoldGenerator
6
+ arguments %w(product_line title:string price:integer --template-engine erb)
7
+
8
+ setup :prepare_destination
9
+ setup :copy_routes
10
+
11
+ test "should invoke template engine" do
12
+ run_generator
13
+
14
+ %w(index edit new show _form).each { |view| assert_file "app/views/product_lines/#{view}.html.erb" }
15
+ assert_no_file "app/views/layouts/product_lines.html.erb"
16
+ end
17
+
18
+ test "should revoke template engine" do
19
+ run_generator
20
+ run_generator ["product_line"], :behavior => :revoke
21
+
22
+ assert_no_file "app/views/product_lines"
23
+ assert_no_file "app/views/layouts/product_lines.html.erb"
24
+ end
25
+
26
+ test "should invoke form builder" do
27
+ run_generator %w(product_line title:string price:integer --template-engine erb --form-builder some-form-builder)
28
+ assert_no_file "app/views/product_lines/_form.html.erb"
29
+ end
30
+ end
31
+
@@ -0,0 +1,74 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'test/unit'
5
+ require 'rails/all'
6
+ require 'rails/generators'
7
+ require 'rails/generators/test_case'
8
+
9
+ class TestApp < Rails::Application
10
+ config.root = File.dirname(__FILE__)
11
+ end
12
+ Rails.application = TestApp
13
+
14
+ module Rails
15
+ def self.root
16
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
17
+ end
18
+ end
19
+ Rails.application.config.root = Rails.root
20
+
21
+ # Call configure to load the settings from
22
+ # Rails.application.config.generators to Rails::Generators
23
+ Rails::Generators.configure!
24
+
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ def copy_routes
28
+ routes = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb'))
29
+ destination = File.join(Rails.root, "config")
30
+ FileUtils.mkdir_p(destination)
31
+ FileUtils.cp File.expand_path(routes), destination
32
+ end
33
+
34
+ # Asserts the given class exists in the given content. When a block is given,
35
+ # it yields the content of the class.
36
+ #
37
+ # assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
38
+ # assert_class "AccountsControllerTest", controller_test do |klass|
39
+ # assert_match /context "index action"/, klass
40
+ # end
41
+ # end
42
+ #
43
+ def assert_class(klass, content)
44
+ assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
45
+ yield $2.strip if block_given?
46
+ end
47
+
48
+ def generator_list
49
+ {
50
+ :rails => ['scaffold', 'controller'],
51
+ :erb => ['scaffold'],
52
+ }
53
+ end
54
+
55
+ def path_prefix(name)
56
+ case name
57
+ when :rails
58
+ 'rails/generators'
59
+ else
60
+ 'generators'
61
+ end
62
+ end
63
+
64
+ def require_generators(generator_list)
65
+ generator_list.each do |name, generators|
66
+ generators.each do |generator_name|
67
+ require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
68
+ end
69
+ end
70
+ end
71
+ alias :require_generator :require_generators
72
+
73
+ require_generators generator_list
74
+
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap-generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Décio Ferreira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &2153240880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153240880
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &2153240100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2153240100
36
+ description: Bootstrap-generators provides Twitter Bootstrap generators for Rails
37
+ 3. Bootstrap is a toolkit from Twitter designed to kickstart development of webapps
38
+ and sites. Checkout http://twitter.github.com/bootstrap.
39
+ email:
40
+ - decio.ferreira@decioferreira.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - Rakefile
48
+ - bootstrap-generators.gemspec
49
+ - lib/bootstrap-generators.rb
50
+ - lib/bootstrap-generators/version.rb
51
+ - lib/generators/erb.rb
52
+ - lib/generators/erb/controller/controller_generator.rb
53
+ - lib/generators/erb/controller/templates/view.html.erb
54
+ - lib/generators/erb/scaffold/scaffold_generator.rb
55
+ - lib/generators/erb/scaffold/templates/_form.html.erb
56
+ - lib/generators/erb/scaffold/templates/edit.html.erb
57
+ - lib/generators/erb/scaffold/templates/index.html.erb
58
+ - lib/generators/erb/scaffold/templates/new.html.erb
59
+ - lib/generators/erb/scaffold/templates/show.html.erb
60
+ - test/fixtures/routes.rb
61
+ - test/lib/generators/erb/controller_generator_test.rb
62
+ - test/lib/generators/erb/scaffold_generator_test.rb
63
+ - test/test_helper.rb
64
+ homepage: ''
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: bootstrap-generators
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Bootstrap-generators provides Twitter Bootstrap generators for Rails 3.
88
+ test_files:
89
+ - test/fixtures/routes.rb
90
+ - test/lib/generators/erb/controller_generator_test.rb
91
+ - test/lib/generators/erb/scaffold_generator_test.rb
92
+ - test/test_helper.rb