ramix 0.1.1 → 0.1.2

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/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'thor', '~> 0.14.6'
3
+ gem 'thor', '~> 0.14.6'
4
+ gem 'hpricot'
@@ -1,20 +1,58 @@
1
1
  = ramix
2
2
 
3
- Ramix is a command-line tool for initializing a new rails application.Just the same as rails but adding more additional options.
3
+ Ramix is a command-line tool for initializing a new rails application. Just the same as rails but adding more additional options.
4
4
 
5
5
  similar project: {rails_wizard}[https://github.com/intridea/rails_wizard] {rails_apps_composer}[https://github.com/RailsApps/rails_apps_composer]
6
6
 
7
+ === Why?
8
+
9
+ When i initialize a new rails application, i always need to find a authentication solution, remove unused index page, replace some other template languages, do some code hack in special rails version and so on. Of course, rails `-m` can do this, but if i need to do some small change, i must create a new template or use 'ask' in the template. The template will be long and unmaintainable. Ramix just wrapped 'rails app_generator' and also used template, so it can help you.
10
+
7
11
  === Usage
8
12
 
9
13
  The usage like <tt>rails new APP_PATH</tt>
10
14
 
11
- ramix new ~/demo --mongoid
15
+ ramix new ~/demo
16
+
17
+ Will create a new rails application with authentication(devise and omniauth), new-index page.
18
+
19
+
20
+ ramix new ~/demo -n mongoid -l haml
21
+
22
+ Will use mongoid as default database and use haml as default template.
12
23
 
13
24
  type
14
25
 
15
26
  ramix -h
16
27
 
17
- You will find all options supported.
28
+ You will find all options supported
29
+
30
+ General options:
31
+ -H, [--home=HOME] # Generate a home controller and view.
32
+ # Default: home
33
+ [--skip-home] # Don't use home option.
34
+
35
+ Nosql options:
36
+ -n, [--nosql=NOSQL] # Preconfigure for selected nosql database (options: mongoid/).
37
+
38
+ Authentication options:
39
+ -a, [--auth=AUTH] # Preconfigure for selected authentication(options: devise/).
40
+ # Default: devise
41
+ [--skip-auth] # Don't use auth option.
42
+ -A, [--omniauth=one two three] # OmniAuth is a flexible authentication system utilizing Rack middleware.
43
+ # Default: google facebook twitter
44
+ [--skip-omniauth] # Don't use omniauth option.
45
+
46
+ Source options:
47
+ -c, [--china] # Special the chinese source path of Gemfile.
48
+
49
+ Front-end options:
50
+ -F, [--front=FRONT] # Preconfigure for selected front-end template or plugin(options: bootstrap/h5bp/).Note that h5bp refer to html5-boilerplate.
51
+ # Default: bootstrap
52
+ [--skip-front] # Don't use front option.
53
+
54
+ Template language options:
55
+ -l, [--lang=LANG] # Preconfigure for selected template language(options: haml/slim/).
18
56
 
19
57
  === Getting Started
20
58
 
@@ -1,6 +1,7 @@
1
1
  require 'rubygems' if RUBY_VERSION < '1.9'
2
2
 
3
3
  begin
4
+ require 'rails/version'
4
5
  require 'rails/generators'
5
6
  require 'rails/generators/rails/app/app_generator'
6
7
  rescue LoadError
@@ -8,4 +9,9 @@ rescue LoadError
8
9
  exit
9
10
  end
10
11
 
12
+ if Rails::VERSION::MAJOR < 3
13
+ puts "Sorry, ramix only support rails version above 3."
14
+ exit
15
+ end
16
+
11
17
  require 'ramix/app_generator'
@@ -9,17 +9,22 @@ module Ramix
9
9
  @@templates = {}
10
10
 
11
11
  Dir.entries(Ramix::Template::DIR_PATH).each do |name|
12
- next unless name =~ /.rb$/
13
- name = File.basename(name, '.rb')
14
- template = Ramix::Template.new(name)
15
- @@templates[name] = template
16
- options = { :group => :ramix }
12
+ next unless name =~ /.rb$/
13
+ name = File.basename(name, '.rb')
14
+ template = Ramix::Template.new(name)
15
+ @@templates[template.name] = template
16
+ options = {}
17
+
17
18
  Ramix::Template::THOR_CLASS_OPTION.each do |opt|
18
19
  options[opt.to_sym] = template.send(opt)
19
20
  end
20
- send 'class_option', name.to_sym, options
21
+
22
+ send 'class_option', template.name.to_sym, options
23
+ unless template.type == "boolean" or template.default == false
24
+ send 'class_option', "skip_#{template.name}".to_sym, :type => :boolean, :default => false, :desc => "Don't use #{template.name} option.", :group => template.group
25
+ end
21
26
  end
22
-
27
+
23
28
  # Overwrite class options help. Merge class options form rails
24
29
  def self.class_options_help(shell, groups={})
25
30
  Rails::Generators::AppGenerator.class_options_help( Thor::Shell::Basic.new )
@@ -43,7 +48,7 @@ module Ramix
43
48
  # According to the options and class_options to build template
44
49
  def build_template(opts, class_options)
45
50
  Ramix::Builder.new do
46
- class_options.each { |name, args| import @@templates[name], args }
51
+ class_options.each { |name, args| import @@templates[name], args unless @@templates[name].nil? or class_options["skip_#{name}".to_sym] }
47
52
  end.run
48
53
  end
49
54
 
@@ -57,7 +62,7 @@ module Ramix
57
62
  # if the template recipe has some dependence options then add these into the opts.
58
63
  def insert_dependence_options(opts, class_options)
59
64
  class_options.each do |name, args|
60
- next if @@templates[name].dependence.nil?
65
+ next if @@templates[name].nil? or @@templates[name].dependence.nil?
61
66
  @@templates[name].dependence.each{ |d| opts << d }
62
67
  end
63
68
  end
@@ -3,7 +3,6 @@ require 'ramix/helpers'
3
3
  module Ramix
4
4
 
5
5
  # Ramix::Builder be responsible for adding some useful methods on the top or the bottom of template.
6
- #
7
6
  class Builder
8
7
 
9
8
  def initialize(default_template_path = nil, &block)
@@ -21,9 +20,11 @@ module Ramix
21
20
  def run
22
21
  begin
23
22
  File.open(@template_path, "a+") do |file|
23
+ file.write preparation_methods
24
24
  file.write rails_version
25
25
  file.write callback_functions
26
26
  @import.each{ |template| file.write template.call }
27
+ file.write before_callbacks
27
28
  file.write callbacks
28
29
  end
29
30
  rescue Exception => e
@@ -2,6 +2,14 @@ module Ramix
2
2
  # A set of helper methods will append to the template
3
3
  module Helpers
4
4
 
5
+ def preparation_methods
6
+ <<-TEMPLATE
7
+ def say_wizard(text)
8
+ say "******" + text + "******"
9
+ end
10
+ TEMPLATE
11
+ end
12
+
5
13
  def rails_version
6
14
  <<-TEMPLATE
7
15
  # Check the version of your rails gem
@@ -18,13 +26,38 @@ module Ramix
18
26
  def after_bundler(&block)
19
27
  @after_bundler_blocks << block
20
28
  end
29
+ @after_everything_blocks = []
30
+ def after_everything(&block)
31
+ @after_everything_blocks << block
32
+ end
21
33
  TEMPLATE
22
34
  end
23
35
 
36
+ def before_callbacks
37
+ <<-TEMPLATE
38
+ if File.exist?('config/initializers/wrap_parameters.rb') and RUBY_VERSION < '1.9'
39
+ gsub_file 'config/initializers/wrap_parameters.rb', "wrap_parameters format: [:json]", "wrap_parameters format => [:json]"
40
+ end
41
+
42
+ # WARNING: This version of mysql2 (0.3.11) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
43
+ # WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
44
+ case rails_version
45
+ when /3.0/
46
+ gsub_file 'Gemfile', "gem 'mysql2'", "gem 'mysql2', '~>0.2.18'"
47
+ end
48
+
49
+ # Use unicorn as the web server
50
+ say_wizard('Use unicorn as the web server')
51
+ gsub_file 'Gemfile', "# gem 'unicorn'", "gem 'unicorn'"
52
+ TEMPLATE
53
+ end
54
+
24
55
  def callbacks
25
56
  <<-TEMPLATE
57
+ say_wizard 'Install bundle'
26
58
  run 'bundle install'
27
59
  @after_bundler_blocks.each{ |b| b.call }
60
+ @after_everything_blocks.each{ |b| b.call }
28
61
  TEMPLATE
29
62
  end
30
63
 
@@ -4,7 +4,7 @@ module Ramix
4
4
  class Template
5
5
 
6
6
  DIR_PATH = File.expand_path(File.dirname(__FILE__) + '/../../recipes')
7
- THOR_CLASS_OPTION = %w(desc required default aliases type banner)
7
+ THOR_CLASS_OPTION = %w(desc required default aliases type banner group)
8
8
  SELF_ATTRIBUTE = %w(dependence)
9
9
  ATTRIBUTE = THOR_CLASS_OPTION + SELF_ATTRIBUTE
10
10
 
@@ -30,9 +30,14 @@ module Ramix
30
30
  end
31
31
  RUBY
32
32
  end
33
-
33
+
34
34
  def output(*args)
35
- "# >====================== [#{name}] =======================<" + @output + "\n\n"
35
+ out_buffer = "# >====================== [#{name}] =======================<\n\n"
36
+ out_buffer << "instance_variable_set '@#{name}', #{args.dup.pop.inspect}\n\n" if args
37
+ <<-OUTPUT
38
+ #{out_buffer}
39
+ #{@output}
40
+ OUTPUT
36
41
  end
37
42
 
38
43
  end
@@ -2,7 +2,7 @@ module Ramix
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ramix}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Thierry Zires}]
12
- s.date = %q{2012-02-01}
12
+ s.date = %q{2012-02-08}
13
13
  s.description = %q{Ramix is a command-line tool for initializing a new rails application.Just the same as rails but adding more additional options.}
14
14
  s.email = %q{zshuaibin@gmail.com}
15
15
  s.executables = [%q{ramix}]
@@ -32,8 +32,13 @@ Gem::Specification.new do |s|
32
32
  "lib/ramix/template.rb",
33
33
  "lib/ramix/version.rb",
34
34
  "ramix.gemspec",
35
+ "recipes/authentication.rb",
35
36
  "recipes/china.rb",
36
- "recipes/mongoid.rb",
37
+ "recipes/front_end.rb",
38
+ "recipes/home.rb",
39
+ "recipes/nosql.rb",
40
+ "recipes/omniauth.rb",
41
+ "recipes/template_language.rb",
37
42
  "test/fixtures/diff_recipe.rb",
38
43
  "test/fixtures/recipe.rb",
39
44
  "test/helper.rb",
@@ -51,11 +56,14 @@ Gem::Specification.new do |s|
51
56
 
52
57
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
58
  s.add_runtime_dependency(%q<thor>, ["~> 0.14.6"])
59
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
54
60
  else
55
61
  s.add_dependency(%q<thor>, ["~> 0.14.6"])
62
+ s.add_dependency(%q<hpricot>, [">= 0"])
56
63
  end
57
64
  else
58
65
  s.add_dependency(%q<thor>, ["~> 0.14.6"])
66
+ s.add_dependency(%q<hpricot>, [">= 0"])
59
67
  end
60
68
  end
61
69
 
@@ -0,0 +1,62 @@
1
+ ---
2
+ name: 'auth'
3
+ aliases: '-a'
4
+ desc: 'Preconfigure for selected authentication(options: devise/).'
5
+ type: 'string'
6
+ default: 'devise'
7
+ group: 'authentication'
8
+ ---
9
+
10
+ case @auth
11
+ when 'devise'
12
+ say_wizard "Install devise gem"
13
+ case rails_version
14
+ when /3.0/ then gem 'devise', '~> 1.5.3'
15
+ when /3.1/, /3.2/ then gem 'devise', '>= 2.0.0'
16
+ end
17
+
18
+ after_bundler do
19
+ say_wizard "Run devise install generator"
20
+ generate 'devise:install'
21
+
22
+ say_wizard "Run devise model generator USER"
23
+ generate "devise user -f"
24
+ # Ensure you have flash messages in app/views/layouts/application.html.erb.
25
+ # For example:
26
+ # <p class="notice"><%= notice %></p>
27
+ # <p class="alert"><%= alert %></p>
28
+ insert_into_file "app/views/layouts/application.html.erb", :before => "<%= yield %>\n" do
29
+ <<-INSERT
30
+ <p class="notice"><%= notice %></p>
31
+ <p class="alert"><%= alert %></p>
32
+ INSERT
33
+ end
34
+
35
+ # Add sign_in, sign_out, and sign_up links to your layout template
36
+ insert_into_file "app/views/layouts/application.html.erb", :before => "<%= yield %>\n" do
37
+ <<-INSERT
38
+ <ul>
39
+ <% if user_signed_in? %>
40
+ <li>
41
+ <%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
42
+ </li>
43
+ <% else %>
44
+ <li>
45
+ <%= link_to('Login', new_user_session_path) %>
46
+ </li>
47
+ <% end %>
48
+ <% if user_signed_in? %>
49
+ <li>
50
+ <%= link_to('Edit registration', edit_user_registration_path) %>
51
+ </li>
52
+ <% else %>
53
+ <li>
54
+ <%= link_to('Register', new_user_registration_path) %>
55
+ </li>
56
+ <% end %>
57
+ </ul>
58
+ INSERT
59
+ end
60
+
61
+ end
62
+ end
@@ -1,7 +1,10 @@
1
1
  ---
2
2
  name: 'china'
3
+ aliases: '-c'
3
4
  desc: 'Special the chinese source path of Gemfile.'
4
5
  type: 'boolean'
6
+ default: false
7
+ group: 'source'
5
8
  ---
6
-
9
+ say_wizard "Replace gemfile source"
7
10
  gsub_file 'Gemfile', "source 'http://rubygems.org'", "source 'http://ruby.taobao.org/'"
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: 'front'
3
+ aliases: '-F'
4
+ desc: 'Preconfigure for selected front-end template or plugin(options: bootstrap/h5bp/).Note that h5bp refer to html5-boilerplate.'
5
+ type: 'string'
6
+ default: 'bootstrap'
7
+ group: 'front-end'
8
+ ---
9
+ case @front
10
+ when "bootstrap"
11
+ case rails_version
12
+ when /3.1/, /3.2/
13
+ say_wizard "Install twitter-bootstrap-rails gem"
14
+ gem 'twitter-bootstrap-rails', :git => 'http://github.com/seyhunak/twitter-bootstrap-rails.git'
15
+ after_bundler do
16
+ say_wizard "Run twitter-bootstrap-rails install generator"
17
+ generate 'bootstrap:install'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: 'home'
3
+ aliases: '-H'
4
+ desc: 'Generate a home controller and view.'
5
+ type: 'string'
6
+ default: 'home'
7
+ group: 'general'
8
+ ---
9
+ say_wizard "Remove static files: index.html, rails.png"
10
+ remove_file 'public/index.html'
11
+
12
+ case rails_version
13
+ when /3.0/ then remove_file 'public/images/rails.png'
14
+ when /3.1/, /3.2/ then remove_file 'app/assets/images/rails.png'
15
+ end
16
+
17
+ after_bundler do
18
+ say_wizard "Generate #{@home} controller"
19
+ generate :controller, "#{@home} index"
20
+ gsub_file 'config/routes.rb', /get \"#{@home}\/index\"/, %Q(root :to => "#{@home}#index")
21
+ end
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: 'nosql'
3
+ aliases: '-n'
4
+ desc: 'Preconfigure for selected nosql database (options: mongoid/).'
5
+ dependence: ['-O']
6
+ type: 'string'
7
+ default: false
8
+ group: 'nosql'
9
+ ---
10
+
11
+ case @nosql
12
+ when 'mongoid'
13
+ say_wizard "Install mongoid gem"
14
+ case rails_version
15
+ when /3.0/ then gem 'mongoid', '2.2.5'
16
+ when /3.1/, /3.2/ then gem 'mongoid', '2.4.3'
17
+ end
18
+
19
+ gem 'bson_ext', '1.5.2'
20
+
21
+ after_bundler do
22
+ say_wizard "Generate mongoid config file and remove database.yml"
23
+ generate 'mongoid:config'
24
+ remove_file 'config/database.yml'
25
+ end
26
+ end
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: 'omniauth'
3
+ aliases: '-A'
4
+ desc: 'OmniAuth is a flexible authentication system utilizing Rack middleware.'
5
+ type: 'array'
6
+ group: 'authentication'
7
+ default: ['google', 'facebook', 'twitter']
8
+ ---
9
+
10
+ if @omniauth == ['china']
11
+ @omniauth = ['weibo', 'renren', 'douban', 'qzone']
12
+ end
13
+
14
+ say_wizard "Install omniauth gem"
15
+ gem 'omniauth'
16
+
17
+ @omniauth.each do |stratege|
18
+ say_wizard "Install omniauth #{stratege} gem"
19
+ case stratege
20
+ when 'renren'
21
+ gem "omniauth-renren", "~> 1.0.0.rc2.1"
22
+ else
23
+ gem "omniauth-#{stratege}"
24
+ end
25
+ end
26
+
27
+ after_bundler do
28
+ say_wizard "Generate authorization model"
29
+ generate :model, "Authorization provider:string user_id:integer uid:string -f"
30
+
31
+ case @auth
32
+ # For devise
33
+ when 'devise'
34
+ if @nosql
35
+ # == Mongoid
36
+ begin
37
+ inject_into_class "app/models/user.rb", 'User', " embeds_many :authorizations\n"
38
+ inject_into_class "app/models/authorization.rb", 'Authorization', " embedded_in :user, :inverse_of => :authorizations\n"
39
+ end if @nosql == 'mongoid'
40
+ else
41
+ # == ActiveRecord
42
+ inject_into_class "app/models/user.rb", 'User', " has_many :authorizations\n"
43
+ inject_into_class "app/models/authorization.rb", 'Authorization', " belongs_to :user\n"
44
+ end
45
+ gsub_file 'app/models/user.rb', /:recoverable, :rememberable, :trackable, :validatable/, ':recoverable, :rememberable, :trackable, :validatable, :omniauthable'
46
+
47
+ insert_into_file 'config/initializers/devise.rb', :before => "# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'\n" do
48
+ @omniauth.map do |stratege|
49
+ " config.omniauth :#{stratege}, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'"
50
+ end.join("\n")<<("\n")
51
+ end
52
+ else
53
+ # For general install
54
+ insert_into_file "app/views/layouts/application.html.erb", :before => "<%= yield %>\n" do
55
+ @omniauth.inject('') do |str, stratege|
56
+ str << "<%= link_to 'Sign in with #{stratege}', user_omniauth_authorize_path(:#{stratege}) %> "
57
+ end << "\n"
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: 'lang'
3
+ aliases: '-l'
4
+ desc: 'Preconfigure for selected template language(options: haml/slim/).'
5
+ type: 'string'
6
+ group: 'template language'
7
+ default: false
8
+ ---
9
+
10
+ case @lang
11
+ when 'haml'
12
+ say_wizard "Install haml gem"
13
+ gem "haml-rails"
14
+ after_everything do
15
+ say_wizard "Covert erb to haml"
16
+ inside('app/views/layouts') do
17
+ run('html2haml -e application.html.erb application.haml')
18
+ end
19
+ end
20
+ when 'slim'
21
+ say_wizard "Install slim gem"
22
+ # gem "slim-rails"
23
+ # TODO slim may have some problems. replace application.html.erb to application.slim
24
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thierry Zires
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-01 00:00:00 Z
18
+ date: 2012-02-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -33,6 +33,20 @@ dependencies:
33
33
  version_requirements: *id001
34
34
  name: thor
35
35
  prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ type: :runtime
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ version_requirements: *id002
48
+ name: hpricot
49
+ prerelease: false
36
50
  description: Ramix is a command-line tool for initializing a new rails application.Just the same as rails but adding more additional options.
37
51
  email: zshuaibin@gmail.com
38
52
  executables:
@@ -57,8 +71,13 @@ files:
57
71
  - lib/ramix/template.rb
58
72
  - lib/ramix/version.rb
59
73
  - ramix.gemspec
74
+ - recipes/authentication.rb
60
75
  - recipes/china.rb
61
- - recipes/mongoid.rb
76
+ - recipes/front_end.rb
77
+ - recipes/home.rb
78
+ - recipes/nosql.rb
79
+ - recipes/omniauth.rb
80
+ - recipes/template_language.rb
62
81
  - test/fixtures/diff_recipe.rb
63
82
  - test/fixtures/recipe.rb
64
83
  - test/helper.rb
@@ -1,18 +0,0 @@
1
- ---
2
- name: 'mongoid'
3
- desc: 'Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby.'
4
- dependence: ['-O']
5
- type: 'boolean'
6
- ---
7
-
8
- case rails_version
9
- when /3.0/ then gem 'mongoid', '2.0.2'
10
- when /3.1/ then gem 'mongoid', '2.3.4'
11
- end
12
-
13
- gem 'bson_ext', '1.5.2'
14
-
15
- after_bundler do
16
- generate 'mongoid:config'
17
- remove_file 'config/database.yml'
18
- end