padrino-gen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +7 -0
  5. data/Rakefile +60 -0
  6. data/VERSION +1 -0
  7. data/bin/padrino-gen +5 -0
  8. data/lib/generators/actions.rb +81 -0
  9. data/lib/generators/base_app/.gitignore +7 -0
  10. data/lib/generators/base_app/Gemfile +13 -0
  11. data/lib/generators/base_app/config/dependencies.rb.tt +41 -0
  12. data/lib/generators/base_app/test/test_config.rb.tt +5 -0
  13. data/lib/generators/components/actions.rb +49 -0
  14. data/lib/generators/components/mocks/mocha_gen.rb +16 -0
  15. data/lib/generators/components/mocks/rr_gen.rb +16 -0
  16. data/lib/generators/components/orms/activerecord_gen.rb +60 -0
  17. data/lib/generators/components/orms/couchrest_gen.rb +29 -0
  18. data/lib/generators/components/orms/datamapper_gen.rb +27 -0
  19. data/lib/generators/components/orms/mongomapper_gen.rb +54 -0
  20. data/lib/generators/components/orms/sequel_gen.rb +28 -0
  21. data/lib/generators/components/renderers/erb_gen.rb +15 -0
  22. data/lib/generators/components/renderers/haml_gen.rb +16 -0
  23. data/lib/generators/components/scripts/jquery_gen.rb +15 -0
  24. data/lib/generators/components/scripts/prototype_gen.rb +16 -0
  25. data/lib/generators/components/scripts/rightjs_gen.rb +16 -0
  26. data/lib/generators/components/tests/bacon_test_gen.rb +27 -0
  27. data/lib/generators/components/tests/riot_test_gen.rb +27 -0
  28. data/lib/generators/components/tests/rspec_test_gen.rb +26 -0
  29. data/lib/generators/components/tests/shoulda_test_gen.rb +26 -0
  30. data/lib/generators/components/tests/testspec_test_gen.rb +26 -0
  31. data/lib/generators/skeleton.rb +53 -0
  32. data/lib/padrino-gen.rb +1 -0
  33. data/padrino-gen.gemspec +104 -0
  34. data/test/active_support_helpers.rb +7 -0
  35. data/test/helper.rb +73 -0
  36. data/test/test_skeleton_generator.rb +188 -0
  37. metadata +175 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Padrino
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.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = padrino-gen
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Padrino. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "padrino-gen"
8
+ gem.summary = "Generators for easily creating and building padrino applications"
9
+ gem.description = "Generators for easily creating and building padrino applications from the console"
10
+ gem.email = "nesquena@gmail.com"
11
+ gem.homepage = "http://github.com/padrino/padrino-gen"
12
+ gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
13
+ gem.add_runtime_dependency "sinatra", ">= 0.9.2"
14
+ gem.add_runtime_dependency "thor", ">= 0.11.8"
15
+ gem.add_runtime_dependency "bundler"
16
+ gem.add_development_dependency "haml", ">= 2.2.1"
17
+ gem.add_development_dependency "shoulda", ">= 0"
18
+ gem.add_development_dependency "mocha", ">= 0.9.7"
19
+ gem.add_development_dependency "rack-test", ">= 0.5.0"
20
+ gem.add_development_dependency "webrat", ">= 0.5.1"
21
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
+ end
23
+ Jeweler::GemcutterTasks.new
24
+ rescue LoadError
25
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
26
+ end
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+ rescue LoadError
43
+ task :rcov do
44
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
45
+ end
46
+ end
47
+
48
+ task :test => :check_dependencies
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "padrino-gen #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/padrino-gen ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ %w[rubygems activesupport thor].each { |gem| require gem }
3
+ require File.dirname(__FILE__) + "/../lib/padrino-gen"
4
+ arguments = ARGV.any? ? ARGV : ['-h']
5
+ Padrino::Generators::Skeleton.start(arguments)
@@ -0,0 +1,81 @@
1
+ module Padrino
2
+ module Generators
3
+ module Actions
4
+
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ # Performs the necessary generator for a given component choice
10
+ # execute_component_setup(:mock, 'rr')
11
+ def execute_component_setup(component, choice)
12
+ return true && say("Skipping generator for #{component} component...", :yellow) if choice.to_s == 'none'
13
+ say "Applying '#{choice}' (#{component})...", :yellow
14
+ self.class.send(:include, generator_module_for(choice, component))
15
+ send("setup_#{component}") if respond_to?("setup_#{component}")
16
+ end
17
+
18
+ # Prompts the user if necessary until a valid choice is returned for the component
19
+ # resolve_valid_choice(:mock) => 'rr'
20
+ def resolve_valid_choice(component)
21
+ available_string = self.class.available_choices_for(component).join(", ")
22
+ choice = options[component]
23
+ until valid_choice?(component, choice)
24
+ say("Option for --#{component} '#{choice}' is not available.", :red)
25
+ choice = ask("Please enter a valid option for #{component} (#{available_string}):")
26
+ end
27
+ choice
28
+ end
29
+
30
+ # Returns true if the option passed is a valid choice for component
31
+ # valid_option?(:mock, 'rr')
32
+ def valid_choice?(component, choice)
33
+ self.class.available_choices_for(component).include? choice.to_sym
34
+ end
35
+
36
+ # Returns the related module for a given component and option
37
+ # generator_module_for('rr', :mock)
38
+ def generator_module_for(choice, component)
39
+ "Padrino::Generators::Components::#{component.to_s.capitalize.pluralize}::#{choice.to_s.capitalize}Gen".constantize
40
+ end
41
+
42
+ # Creates a component_config file at the destination containing all component options
43
+ # Content is a yamlized version of a hash containing component name mapping to chosen value
44
+ def store_component_config(destination)
45
+ create_file(destination) do
46
+ self.class.component_types.inject({}) { |result, component|
47
+ result[component] = options[component].to_s; result
48
+ }.to_yaml
49
+ end
50
+ end
51
+
52
+ # Loads the component config back into a hash
53
+ # i.e retrieve_component_config(...) => { :mock => 'rr', :test => 'riot', ... }
54
+ def retrieve_component_config(target)
55
+ YAML.load_file(target)
56
+ end
57
+
58
+ module ClassMethods
59
+ # Defines a class option to allow a component to be chosen and add to component type list
60
+ # Also builds the available_choices hash of which component choices are supported
61
+ # component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda]
62
+ def component_option(name, caption, options = {})
63
+ (@component_types ||= []) << name
64
+ (@available_choices ||= Hash.new({}))[name] = options[:choices]
65
+ description = "The #{caption} component (#{options[:choices].join(', ')})"
66
+ class_option name, :default => options[:choices].first, :aliases => options[:aliases], :desc => description
67
+ end
68
+
69
+ # Returns the compiled list of component types which can be specified
70
+ def component_types
71
+ @component_types
72
+ end
73
+
74
+ # Returns the list of available choices for the given component (including none)
75
+ def available_choices_for(component)
76
+ @available_choices[component] + [:none]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ log/**/*
3
+ tmp/**/*
4
+ vendor/gems/gems
5
+ vendor/gems/specifications
6
+ vendor/gems/doc
7
+ vendor/gems/environment.rb
@@ -0,0 +1,13 @@
1
+ clear_sources
2
+ source 'http://gemcutter.org'
3
+ # Base requirements
4
+ gem 'sinatra'
5
+ gem 'padrino'
6
+ gem 'rack-flash'
7
+ gem 'warden'
8
+ gem 'bcrypt-ruby', :require_as => 'bcrypt'
9
+
10
+ # Component requirements
11
+
12
+ # Testing requirements
13
+ gem 'rack-test', :require_as => 'rack/test', :only => :testing
@@ -0,0 +1,41 @@
1
+ # Dependencies contains all required gems, helpers and core configuration
2
+
3
+ def app(&block)
4
+ <%= @class_name %>.class_eval(&block)
5
+ end
6
+
7
+ class <%= @class_name %> < Sinatra::Application
8
+ bundler_require_dependencies
9
+
10
+ # Required middleware
11
+ use Rack::Session::Cookie
12
+ use Rack::Flash
13
+
14
+ # Includes all necessary sinatra_more helpers
15
+ register SinatraMore::MarkupPlugin
16
+ register SinatraMore::RenderPlugin
17
+ register SinatraMore::MailerPlugin
18
+ register SinatraMore::RoutingPlugin
19
+
20
+ # Requires the initializer modules which configure specific components
21
+ Dir[File.dirname(__FILE__) + '/initializers/*.rb'].each do |file|
22
+ # Each initializer file contains a module called 'XxxxInitializer' (i.e HassleInitializer)
23
+ require file
24
+ file_class = File.basename(file, '.rb').classify
25
+ register "#{file_class}Initializer".constantize
26
+ end
27
+
28
+ # Returns the list of load paths for this sinatra application
29
+ def self.file_loading_paths
30
+ ["lib/**/*.rb", "app/helpers/**/*.rb", "app/routes/**/*.rb", "app/models/*.rb", "app/mailers/*.rb"]
31
+ end
32
+
33
+ # Require all the folders and files necessary to run the application
34
+ file_loading_paths.each { |load_path| Dir[root_path(load_path)].each { |file| require file } }
35
+
36
+ # Require Warden plugin below to allow User to be loaded
37
+ register SinatraMore::WardenPlugin
38
+
39
+ # Required helpers
40
+ helpers ViewHelpers
41
+ end
@@ -0,0 +1,5 @@
1
+ RACK_ENV = 'test' unless defined?(RACK_ENV)
2
+ require File.dirname(__FILE__) + "/../config/boot"
3
+ Bundler.require_env(:testing)
4
+
5
+ # Test configuration
@@ -0,0 +1,49 @@
1
+ module Padrino
2
+ module Generators
3
+ module Components
4
+ module Actions
5
+ # Adds all the specified gems into the Gemfile for bundler
6
+ # require_dependencies 'activerecord'
7
+ # require_dependencies 'mocha', 'bacon', :env => :testing
8
+ def require_dependencies(*gem_names)
9
+ options = gem_names.extract_options!
10
+ gem_names.reverse.each { |lib| insert_into_gemfile(lib, options) }
11
+ end
12
+
13
+ # Inserts a required gem into the Gemfile to add the bundler dependency
14
+ # insert_dependency_to_gemfile(name)
15
+ # insert_dependency_to_gemfile(name, :env => :testing)
16
+ def insert_into_gemfile(name, options={})
17
+ after_pattern = "# Component requirements\n"
18
+ after_pattern = "# #{options[:env].to_s.capitalize} requirements\n" if environment = options[:env]
19
+ include_text = "gem '#{name}'" << (environment ? ", :only => #{environment.inspect}" : "") << "\n"
20
+ options.merge!(:content => include_text, :after => after_pattern)
21
+ inject_into_file('Gemfile', options[:content], :after => options[:after])
22
+ end
23
+
24
+ # Injects the test class text into the test_config file for setting up the test gen
25
+ # insert_test_suite_setup('...CLASS_NAME...')
26
+ # => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @class_name), :after => "set :environment, :test\n")
27
+ def insert_test_suite_setup(suite_text, options={})
28
+ options.reverse_merge!(:path => "test/test_config.rb", :after => /Test configuration\n/)
29
+ inject_into_file(options[:path], suite_text.gsub(/CLASS_NAME/, @class_name), :after => options[:after])
30
+ end
31
+
32
+ # Injects the mock library include into the test class in test_config for setting up mock gen
33
+ # insert_mock_library_include('Mocha::API')
34
+ # => inject_into_file("test/test_config.rb", " include Mocha::API\n", :after => /class.*?\n/)
35
+ def insert_mocking_include(library_name, options={})
36
+ options.reverse_merge!(:indent => 2, :after => /class.*?\n/, :path => "test/test_config.rb")
37
+ include_text = indent_spaces(options[:indent]) + "include #{library_name}\n"
38
+ inject_into_file(options[:path], include_text, :after => options[:after])
39
+ end
40
+
41
+ # Returns space characters of given count
42
+ # indent_spaces(2)
43
+ def indent_spaces(count)
44
+ ' ' * count
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ module Padrino
2
+ module Generators
3
+ module Components
4
+ module Mocks
5
+
6
+ module MochaGen
7
+ def setup_mock
8
+ require_dependencies 'mocha', :env => :testing
9
+ insert_mocking_include "Mocha::API", :path => "test/test_config.rb"
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Padrino
2
+ module Generators
3
+ module Components
4
+ module Mocks
5
+
6
+ module RrGen
7
+ def setup_mock
8
+ require_dependencies 'rr', :env => :testing
9
+ insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,60 @@
1
+ module Padrino
2
+ module Generators
3
+ module Components
4
+ module Orms
5
+
6
+ module ActiverecordGen
7
+
8
+ AR = (<<-AR).gsub(/^ {10}/, '')
9
+ module ActiveRecordInitializer
10
+ def self.registered(app)
11
+ app.configure :development do
12
+ ActiveRecord::Base.establish_connection(
13
+ :adapter => 'sqlite3',
14
+ :database => 'your_dev_db_here'
15
+ )
16
+ end
17
+
18
+ app.configure :production do
19
+ ActiveRecord::Base.establish_connection(
20
+ :adapter => 'sqlite3',
21
+ :database => 'your_production_db_here'
22
+ )
23
+ end
24
+
25
+ app.configure :test do
26
+ ActiveRecord::Base.establish_connection(
27
+ :adapter => 'sqlite3',
28
+ :database => 'your_test_db_here'
29
+ )
30
+ end
31
+ end
32
+ end
33
+ AR
34
+
35
+ RAKE = (<<-RAKE).gsub(/^ {10}/, '')
36
+ require 'sinatra/base'
37
+ require 'active_record'
38
+
39
+ namespace :db do
40
+ desc "Migrate the database"
41
+ task(:migrate) do
42
+ load 'config/boot.rb'
43
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
44
+ ActiveRecord::Migration.verbose = true
45
+ ActiveRecord::Migrator.migrate("db/migrate")
46
+ end
47
+ end
48
+ RAKE
49
+
50
+
51
+ def setup_orm
52
+ require_dependencies 'activerecord'
53
+ create_file("config/initializers/active_record.rb", AR)
54
+ create_file("Rakefile", RAKE)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ module Padrino
2
+ module Generators
3
+ module Components
4
+ module Orms
5
+
6
+ module CouchrestGen
7
+
8
+ COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '')
9
+ module CouchRestInitializer
10
+ def self.registered(app)
11
+ app.configure(:development) { set :couchdb, CouchRest.database!('your_dev_db_here') }
12
+ app.configure(:production) { set :couchdb, CouchRest.database!('your_production_db_here') }
13
+ app.configure(:test) { set :couchdb, CouchRest.database!('your_test_db_here') }
14
+ end
15
+ end
16
+ COUCHREST
17
+
18
+
19
+ def setup_orm
20
+ require_dependencies 'couchrest'
21
+ create_file("config/initializers/couch_rest.rb", COUCHREST)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
29
+