ramix 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'thor', '~> 0.14.6'
4
+ gem 'railties'
5
+
6
+ group :development do
7
+ gem "yard", "~> 0.6.0"
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.6.4"
10
+ gem "rcov", ">= 0"
11
+ gem "reek", "~> 1.2.8"
12
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Thierry Zires
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.
@@ -0,0 +1,39 @@
1
+ = ramix
2
+
3
+ Ramix is a command-line tool for initializing a new rails application.Just the same as rails but adding more additional options.
4
+
5
+ similar project: {rails_wizard}[https://github.com/intridea/rails_wizard] {rails_apps_composer}[https://github.com/RailsApps/rails_apps_composer]
6
+
7
+ === Usage
8
+
9
+ The usage like <tt>rails new APP_PATH</tt>
10
+
11
+ ramix new ~/demo --mongoid
12
+
13
+ type
14
+
15
+ ramix -h
16
+
17
+ You will find all options supported.
18
+
19
+ === Getting Started
20
+
21
+
22
+ gem install ramix
23
+
24
+
25
+ == Contributing to ramix
26
+
27
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
28
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
29
+ * Fork the project
30
+ * Start a feature/bugfix branch
31
+ * Commit and push until you are happy with your contribution
32
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
33
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2011 Thierry Zires. See LICENSE.txt for
38
+ further details.
39
+
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
17
+ require 'ramix/version'
18
+ Jeweler::Tasks.new do |gem|
19
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
20
+ gem.name = "ramix"
21
+ gem.version = Ramix::VERSION::STRING
22
+ gem.homepage = "http://github.com/zires/ramix"
23
+ gem.license = "MIT"
24
+ gem.summary = %Q{new rails application generator}
25
+ gem.description = %Q{Ramix is a command-line tool for initializing a new rails application.Just the same as rails but adding more additional options.}
26
+ gem.email = "zshuaibin@gmail.com"
27
+ gem.authors = ["Thierry Zires"]
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ require 'rcov/rcovtask'
40
+ Rcov::RcovTask.new do |test|
41
+ test.libs << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ test.rcov_opts << '--exclude "gems/*"'
45
+ end
46
+
47
+ require 'reek/rake/task'
48
+ Reek::Rake::Task.new do |t|
49
+ t.fail_on_error = true
50
+ t.verbose = false
51
+ t.source_files = 'lib/**/*.rb'
52
+ end
53
+
54
+ task :default => :test
55
+
56
+ require 'yard'
57
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'ramix/commands'
@@ -0,0 +1,11 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+
3
+ begin
4
+ require 'rails/generators'
5
+ require 'rails/generators/rails/app/app_generator'
6
+ rescue LoadError
7
+ puts "**Note** Rails is not available. Type `gem install rails` to install rails."
8
+ exit
9
+ end
10
+
11
+ require 'ramix/app_generator'
@@ -0,0 +1,66 @@
1
+ require 'ramix/template'
2
+ require 'ramix/builder'
3
+
4
+ module Ramix
5
+ class AppGenerator < Thor::Group
6
+
7
+ argument :app_path, :type => :string
8
+
9
+ @@templates = {}
10
+
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 }
17
+ Ramix::Template::THOR_CLASS_OPTION.each do |opt|
18
+ options[opt.to_sym] = template.send(opt)
19
+ end
20
+ send 'class_option', name.to_sym, options
21
+ end
22
+
23
+ # Overwrite class options help. Merge class options form rails
24
+ def self.class_options_help(shell, groups={})
25
+ Rails::Generators::AppGenerator.class_options_help( Thor::Shell::Basic.new )
26
+ super(Thor::Shell::Basic.new, groups) #TODO - use color shell
27
+ end
28
+
29
+ def initialize(args, opts, config)
30
+ raise Thor::Error, "Application path should be given. For details run: ramix --help" if args[0].blank?
31
+ super
32
+ add_template_option opts, options
33
+ # Invoke the rails application generator
34
+ invoke Rails::Generators::AppGenerator
35
+ end
36
+
37
+ protected
38
+
39
+ def self.banner#:nodoc:
40
+ "ramix new APP_PATH [options]"
41
+ end
42
+
43
+ # According to the options and class_options to build template
44
+ def build_template(opts, class_options)
45
+ Ramix::Builder.new do
46
+ class_options.each { |name, args| import @@templates[name], args }
47
+ end.run
48
+ end
49
+
50
+ # Add '-m' #{template} in the ARGV
51
+ def add_template_option(opts, class_options)
52
+ insert_dependence_options(opts, class_options)
53
+ opts << '-m'
54
+ opts << build_template(opts, class_options)
55
+ end
56
+
57
+ # if the template recipe has some dependence options then add these into the opts.
58
+ def insert_dependence_options(opts, class_options)
59
+ class_options.each do |name, args|
60
+ next if @@templates[name].dependence.nil?
61
+ @@templates[name].dependence.each{ |d| opts << d }
62
+ end
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,46 @@
1
+ require 'ramix/helpers'
2
+
3
+ module Ramix
4
+
5
+ # Ramix::Builder be responsible for adding some useful methods on the top or the bottom of template.
6
+ #
7
+ class Builder
8
+
9
+ def initialize(default_template_path = nil, &block)
10
+ @template_path = default_template_path || tempfile_path
11
+ @import = []
12
+ instance_eval(&block) if block_given?
13
+ end
14
+
15
+ def import(template, *args)
16
+ @import << proc { template.output(*args) }
17
+ end
18
+
19
+ # Write some useful methods and the content of recipe in the file.
20
+ # Return the path of the template.
21
+ def run
22
+ begin
23
+ File.open(@template_path, "a+") do |file|
24
+ file.write rails_version
25
+ file.write callback_functions
26
+ @import.each{ |template| file.write template.call }
27
+ file.write callbacks
28
+ end
29
+ rescue Exception => e
30
+ puts "Create template #{@template} error~~ #{e.message}"
31
+ end
32
+ @template_path
33
+ end
34
+
35
+ private
36
+
37
+ def tempfile_path
38
+ require 'tempfile'
39
+ Tempfile.new('template').path
40
+ end
41
+
42
+ include Ramix::Helpers
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,12 @@
1
+ ARGV << '--help' if ARGV.empty?
2
+
3
+ # The first argument must be 'new' else return the help message.
4
+ if ARGV.first == "new"
5
+ ARGV.shift
6
+ else
7
+ ARGV.clear
8
+ ARGV << '--help'
9
+ end
10
+
11
+ require 'ramix'
12
+ Ramix::AppGenerator.start
@@ -0,0 +1,33 @@
1
+ module Ramix
2
+ # A set of helper methods will append to the template
3
+ module Helpers
4
+
5
+ def rails_version
6
+ <<-TEMPLATE
7
+ # Check the version of your rails gem
8
+ # Only support above 3.0
9
+ def rails_version
10
+ [Rails::VERSION::MAJOR, Rails::VERSION::MINOR].join('.')
11
+ end
12
+ TEMPLATE
13
+ end
14
+
15
+ def callback_functions
16
+ <<-TEMPLATE
17
+ @after_bundler_blocks = []
18
+ def after_bundler(&block)
19
+ @after_bundler_blocks << block
20
+ end
21
+ TEMPLATE
22
+ end
23
+
24
+ def callbacks
25
+ <<-TEMPLATE
26
+ run 'bundle install'
27
+ @after_bundler_blocks.each{ |b| b.call }
28
+ TEMPLATE
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+
3
+ module Ramix
4
+ class Template
5
+
6
+ DIR_PATH = File.expand_path(File.dirname(__FILE__) + '/../../recipes')
7
+ THOR_CLASS_OPTION = %w(desc required default aliases type banner)
8
+ SELF_ATTRIBUTE = %w(dependence)
9
+ ATTRIBUTE = THOR_CLASS_OPTION + SELF_ATTRIBUTE
10
+
11
+ def initialize(name, path = nil)
12
+ @name = name
13
+ @path = path || DIR_PATH
14
+ begin
15
+ draft, attribute, @output = File.read( File.join(@path, name + '.rb') ).split('---')
16
+ @attribute = YAML.load(attribute)
17
+ rescue
18
+ @attribute, @output = {}, "\n\ngem '#{name}'"
19
+ end
20
+ end
21
+
22
+ def name
23
+ @attribute['name'] || @name
24
+ end
25
+
26
+ ATTRIBUTE.each do |attr|
27
+ class_eval <<-RUBY
28
+ def #{attr}
29
+ @attribute['#{attr}']
30
+ end
31
+ RUBY
32
+ end
33
+
34
+ def output(*args)
35
+ "# >====================== [#{name}] =======================<" + @output + "\n\n"
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ module Ramix
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+ PRE = nil
7
+
8
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: 'china'
3
+ desc: 'Special the chinese source path of Gemfile.'
4
+ type: 'boolean'
5
+ ---
6
+
7
+ gsub_file 'Gemfile', "source 'http://rubygems.org'", "source 'http://ruby.taobao.org/'"
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: 'recipe'
3
+ desc: 'Just a test recipe for ramix.'
4
+ type: 'boolean'
5
+ ---
6
+
7
+ "recipe body"
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: 'recipe'
3
+ desc: 'Just a test recipe for ramix.'
4
+ type: 'boolean'
5
+ dependence: ['-O']
6
+ ---
7
+ "recipe body"
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'ramix'
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ class TestBuilder < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @f = File.new(File.expand_path( File.dirname(__FILE__) + '/fixtures/template.rb' ), 'w+')
7
+ @recipe = Ramix::Template.new('recipe', File.expand_path( File.dirname(__FILE__) + '/fixtures' ))
8
+ @b = Ramix::Builder.new(@f.path)
9
+ end
10
+
11
+ def teardown
12
+ require 'fileutils'
13
+ FileUtils.rm @f.path, :force => true
14
+ end
15
+
16
+ def test_run
17
+ @b.import @recipe
18
+ path = @b.run
19
+ assert_match /"recipe body"/, @f.read
20
+ assert_equal @f.path, path
21
+ end
22
+
23
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class TestTemplate < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @recipe_exist = Ramix::Template.new('recipe', File.expand_path( File.dirname(__FILE__) + '/fixtures' ))
7
+ @recipe_exist_with_diff_name = Ramix::Template.new('diff_recipe', File.expand_path( File.dirname(__FILE__) + '/fixtures' ))
8
+ @recipe_not_exist = Ramix::Template.new('test')
9
+ end
10
+
11
+ def test_name
12
+ assert_equal 'recipe', @recipe_exist.name
13
+ assert_equal 'recipe', @recipe_exist_with_diff_name.name
14
+ assert_equal 'test', @recipe_not_exist.name
15
+ end
16
+
17
+ def test_output
18
+ assert_equal "# >====================== [test] =======================<\n\ngem 'test'\n\n", @recipe_not_exist.output
19
+ assert_equal "# >====================== [recipe] =======================<\r\n\"recipe body\"\n\n", @recipe_exist.output
20
+ end
21
+
22
+ def test_respond_to_attributes
23
+ Ramix::Template::ATTRIBUTE.each do |attr|
24
+ assert_respond_to( @recipe_exist, attr )
25
+ end
26
+ end
27
+
28
+ def test_desc
29
+ assert_equal 'Just a test recipe for ramix.', @recipe_exist.desc
30
+ end
31
+
32
+ def test_dependence
33
+ assert_equal ['-O'], @recipe_exist.dependence
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ramix
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Thierry Zires
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 43
28
+ segments:
29
+ - 0
30
+ - 14
31
+ - 6
32
+ version: 0.14.6
33
+ version_requirements: *id001
34
+ name: thor
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: railties
49
+ prerelease: false
50
+ - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 7
58
+ segments:
59
+ - 0
60
+ - 6
61
+ - 0
62
+ version: 0.6.0
63
+ version_requirements: *id003
64
+ name: yard
65
+ prerelease: false
66
+ - !ruby/object:Gem::Dependency
67
+ type: :development
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 23
74
+ segments:
75
+ - 1
76
+ - 0
77
+ - 0
78
+ version: 1.0.0
79
+ version_requirements: *id004
80
+ name: bundler
81
+ prerelease: false
82
+ - !ruby/object:Gem::Dependency
83
+ type: :development
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 7
90
+ segments:
91
+ - 1
92
+ - 6
93
+ - 4
94
+ version: 1.6.4
95
+ version_requirements: *id005
96
+ name: jeweler
97
+ prerelease: false
98
+ - !ruby/object:Gem::Dependency
99
+ type: :development
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ version_requirements: *id006
110
+ name: rcov
111
+ prerelease: false
112
+ - !ruby/object:Gem::Dependency
113
+ type: :development
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ hash: 15
120
+ segments:
121
+ - 1
122
+ - 2
123
+ - 8
124
+ version: 1.2.8
125
+ version_requirements: *id007
126
+ name: reek
127
+ prerelease: false
128
+ description: Ramix is a command-line tool for initializing a new rails application.Just the same as rails but adding more additional options.
129
+ email: zshuaibin@gmail.com
130
+ executables:
131
+ - ramix
132
+ extensions: []
133
+
134
+ extra_rdoc_files:
135
+ - LICENSE.txt
136
+ - README.rdoc
137
+ files:
138
+ - .document
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.rdoc
142
+ - Rakefile
143
+ - bin/ramix
144
+ - lib/ramix.rb
145
+ - lib/ramix/app_generator.rb
146
+ - lib/ramix/builder.rb
147
+ - lib/ramix/commands.rb
148
+ - lib/ramix/helpers.rb
149
+ - lib/ramix/template.rb
150
+ - lib/ramix/version.rb
151
+ - recipes/china.rb
152
+ - recipes/mongoid.rb
153
+ - test/fixtures/diff_recipe.rb
154
+ - test/fixtures/recipe.rb
155
+ - test/helper.rb
156
+ - test/test_builder.rb
157
+ - test/test_template.rb
158
+ homepage: http://github.com/zires/ramix
159
+ licenses:
160
+ - MIT
161
+ post_install_message:
162
+ rdoc_options: []
163
+
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ hash: 3
172
+ segments:
173
+ - 0
174
+ version: "0"
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ hash: 3
181
+ segments:
182
+ - 0
183
+ version: "0"
184
+ requirements: []
185
+
186
+ rubyforge_project:
187
+ rubygems_version: 1.8.6
188
+ signing_key:
189
+ specification_version: 3
190
+ summary: new rails application generator
191
+ test_files: []
192
+