rails-skeleton 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.
@@ -0,0 +1,23 @@
1
+ = RailsSkeleton
2
+
3
+ This repository contains various rails skeleton projects as branches,
4
+ and a gem to get the skeleton out of the closet.
5
+
6
+ == Usage
7
+
8
+ # rails-skeleton MyApp mysql
9
+
10
+ This clones the mysql branch in git://github.com/gudleik/rails-skeleton.git
11
+ If you want to use your own skeleton project, pass -r git-url:
12
+
13
+ # rails-skeleton MyApp mybranch -r git://github.com/you/my-rails-templates.git
14
+
15
+ rails-skeleton will perform these steps:
16
+
17
+ * Clone the repository
18
+ * Rename all occurrences of application name to MyApp (ie MyApp::Application)
19
+ * Run bundle install
20
+ * Generate a new secret token
21
+ * Reinitialize git repository (rm -rf .git && git init)
22
+ * Run git flow init on the new repository
23
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/rails-skeleton")
5
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/rails-skeleton/cli")
6
+
7
+ RailsSkeleton::CLI.execute(STDOUT, ARGV)
8
+
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rails-skeleton/client'
5
+ require 'rails-skeleton/string'
6
+
7
+ module RailsSkeleton
8
+
9
+ VERSION = "0.0.1"
10
+ DEFAULT_SKELETON_REPOSITORY = "git://github.com/gudleik/rails-skeleton.git"
11
+
12
+ end
@@ -0,0 +1,58 @@
1
+ require 'optparse'
2
+
3
+ module RailsSkeleton
4
+
5
+ #
6
+ # CLI is the Command-Line Interface class.
7
+ # This class parses the arguments from the command line
8
+ #
9
+ class CLI
10
+
11
+ # Reads parameters from +arguments+ and fires up the Botify::Client.
12
+ #
13
+ # == Parameters:
14
+ # stdout::
15
+ # Where to send output
16
+ # arguments::
17
+ # The arguments to parse
18
+ #
19
+ def self.execute(stdout, arguments=[])
20
+
21
+ # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
22
+ repos = RailsSkeleton::DEFAULT_SKELETON_REPOSITORY
23
+ mandatory_options = %w( )
24
+
25
+ parser = OptionParser.new do |opts|
26
+ opts.banner = <<-BANNER.gsub(/^ /,'')
27
+ RailsSkeleton -- Get that skeleton out of the closet
28
+
29
+ Usage: #{File.basename($0)} APP_NAME branch [options]
30
+
31
+ Options are:
32
+ BANNER
33
+ opts.separator ""
34
+ opts.on("-r", "--repos=URL", String, "Skeleton repository URL [#{repos}]") { |arg| repos = arg }
35
+ opts.on("-h", "--help", "Show this help message.") { stdout.puts opts; exit }
36
+ opts.on("-v", "--version", "Show version.") { stdout.puts "RailsSkeleton version #{RailsSkeleton::VERSION}"; exit }
37
+
38
+ opts.parse!(arguments)
39
+
40
+ if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
41
+ stdout.puts opts; exit
42
+ end
43
+ end
44
+
45
+
46
+ name = ARGV[0]
47
+ branch = ARGV[1]
48
+
49
+ unless name && branch
50
+ puts parser.to_s
51
+ exit
52
+ end
53
+
54
+ app = RailsSkeleton::Client.new(name, branch, repos)
55
+ app.lolcats
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,112 @@
1
+ module RailsSkeleton
2
+
3
+ class Client
4
+
5
+ def initialize(name, branch, repos = RailsSkeleton::DEFAULT_SKELETON_REPOSITORY)
6
+ @name = name
7
+ @app_name = @name.camelize
8
+ @branch = branch
9
+ @repository = repos
10
+ @path = name
11
+ end
12
+
13
+ def lolcats
14
+ sanity_check
15
+ clone
16
+ rename
17
+ bundler
18
+ generate_secret
19
+ copy_db_config
20
+ regit
21
+
22
+ puts "Successfully copied #{@repository/@branch} into #{@name.green}"
23
+ end
24
+
25
+ private
26
+
27
+ # Copy config/database.example.yml to config/database.yml
28
+ def copy_db_config
29
+ if File.exists?(File.join(@name, 'config', 'database.example.yml'))
30
+ run "Creating config/database.yml:" do
31
+ system "cp #{@name}/config/database.example.yml #{@name}/config/database.yml"
32
+ end
33
+ end
34
+ end
35
+
36
+ # Reinitialize git and run git flow init
37
+ def regit
38
+ run "Reinitializing git:" do
39
+ system "cd #{@name} && git init -q && git add . && git ci -qm 'Initial commit'"
40
+ system "cd #{@name} && git flow init"
41
+ end
42
+ end
43
+
44
+ def generate_secret
45
+ run "Generating secret token:" do
46
+ secret = `cd #{@name} && rake -s secret`.chomp
47
+ File.open(File.join(@name, 'config', 'initializers', 'secret_token.rb'), 'w') do |f|
48
+ f.puts "#{@app_name}::Application.config.secret_token = '#{secret}'"
49
+ end
50
+ end
51
+ end
52
+
53
+ # Replace of file
54
+ def replace_file(path, pattern, replacement)
55
+ return unless File.exist?(path)
56
+ text = File.read(path)
57
+ File.open(path, "w") { |f| f.puts text.gsub(pattern, replacement) }
58
+ end
59
+
60
+ # Replace old app name
61
+ def rename
62
+
63
+ files = [ 'config.ru', 'config/application.rb', 'Rakefile', 'config/environment.rb', 'config/environments/development.rb', 'config/environments/production.rb',
64
+ 'config/database.example.yml', 'config/environments/test.rb', 'config/initializers/secret_token.rb', 'config/initializers/session_store.rb', 'config/routes.rb' ]
65
+
66
+ run "Renaming application to #{@name}:" do
67
+ error "Unable to determine name of cloned repository!" unless original_name
68
+
69
+ files.each do |filename|
70
+ replace_file(File.join(@name, filename), original_name, @app_name)
71
+ end
72
+ end
73
+
74
+ replace_file File.join(@name, 'config', 'database.example.yml'), /dbname/, @app_name.downcase
75
+ end
76
+
77
+ def bundler
78
+ run "Installing gems:" do
79
+ system "cd #{@path} && bundle install --quiet"
80
+ end
81
+ end
82
+
83
+ def clone
84
+ run "Cloning repository into #{@name}:" do
85
+ system "git clone -q -b #{@branch} #{@repository} #{@name}"
86
+ system "rm -rf #{@name}/.git"
87
+ end
88
+ end
89
+
90
+ def run(msg, &block)
91
+ printf "%-45s", msg
92
+ yield if block_given?
93
+ print "OK\n".green
94
+ end
95
+
96
+ # Determine original application name
97
+ def original_name
98
+ @original_name ||= File.read(File.join(@path, 'config', 'environment.rb')).match(%r{(.*)::Application.initialize!})[1] rescue nil
99
+ end
100
+
101
+ def sanity_check
102
+ error("The directory #{@name.red} already exists!") if Dir.exists?(@name)
103
+ end
104
+
105
+ def error(msg)
106
+ puts "Error: ".red + msg
107
+ exit
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,19 @@
1
+ class String
2
+
3
+ # Adds coloring to strings
4
+ def red; colorize(self, "\e[1m\e[31m"); end
5
+ def green; colorize(self, "\e[1m\e[32m"); end
6
+ def dark_green; colorize(self, "\e[32m"); end
7
+ def yellow; colorize(self, "\e[1m\e[33m"); end
8
+ def blue; colorize(self, "\e[1m\e[34m"); end
9
+ def dark_blue; colorize(self, "\e[34m"); end
10
+ def pur; colorize(self, "\e[1m\e[35m"); end
11
+ def colorize(text, color_code) "#{color_code}#{text}\e[0m" end
12
+
13
+ # similar to ActiveSupport::Inflector.camelize
14
+ def camelize
15
+ self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
16
+ end
17
+
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-skeleton
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Gudleik Rasch
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-14 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Jumpstart new rails projects by cloning existing skeleton projects
22
+ email:
23
+ - gudleik@gmail.com
24
+ executables:
25
+ - rails-skeleton
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - bin/rails-skeleton
32
+ - lib/rails-skeleton/cli.rb
33
+ - lib/rails-skeleton/client.rb
34
+ - lib/rails-skeleton/string.rb
35
+ - lib/rails-skeleton.rb
36
+ - README.rdoc
37
+ has_rdoc: true
38
+ homepage: http://github.com/gudleik/rails-skeleton
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Copy rails skeleton projects into new projects
69
+ test_files: []
70
+