ricque 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/bin/ricque CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.push File.expand_path("../../lib", __FILE__)
3
3
 
4
- require 'active_support/inflector'
5
- require 'fileutils'
6
4
  require File.expand_path("../../lib/ricque", __FILE__)
7
5
 
6
+ Ricque.initialize!
7
+
8
8
  case ARGV[0]
9
9
  when 'new'
10
10
  if ARGV[1].nil?
@@ -13,37 +13,20 @@ when 'new'
13
13
  end
14
14
  app_name = ARGV[1].underscore
15
15
 
16
- camelized_app_name = app_name.camelize
17
- dashesized_app_name = app_name.dasherize
18
-
19
- root_path = File.expand_path("../..", __FILE__)
20
- template_path = File.join root_path, 'lib', 'template', '.'
21
-
22
- current_path = File.expand_path(".")
23
-
24
- app_path = File.join(current_path, dashesized_app_name)
25
-
26
- puts "Creating path #{app_path}"
27
- if Dir.exists?(app_path)
28
- puts "Path #{app_path} already exists"
16
+ begin
17
+ Ricque::AppGenerator
18
+ .new(app_name)
19
+ .create!
20
+ rescue Exception => ex
21
+ puts "\n"
22
+ puts "=" * 70
23
+ puts "FATAL ERROR\n\n"
24
+ puts "The following error occurred while trying to create the app:\n"
25
+ puts "\tError: #{ex}"
26
+ puts "\tBacktrace: \n\t\t#{ex.backtrace.join("\n\t\t")}"
29
27
  exit 1
30
28
  end
31
- Dir.mkdir app_path
32
-
33
- Dir.chdir(app_path) do
34
- puts "Copying files"
35
- FileUtils.cp_r template_path, ".", :preserve => true
36
- puts "Renaming file content"
37
- `grep -Irl "Ricque" . | xargs sed -i '' 's/Ricque/#{camelized_app_name}/g'`
38
- `grep -Irl "ricque" . | xargs sed -i '' 's/ricque/#{dashesized_app_name}/g'`
39
- `grep -Irl "{RICQUE_VERSION}" . | xargs sed -i '' 's/{RICQUE_VERSION}/#{Ricque::VERSION}/g'`
40
- puts "Renaming files"
41
- FileUtils.mv 'lib/ricque', "lib/#{dashesized_app_name}"
42
- FileUtils.mv "lib/ricque.rb", "lib/#{dashesized_app_name}.rb"
43
- FileUtils.mv "lib/tasks/ricque.rake", "lib/tasks/#{dashesized_app_name}.rake"
44
- end
45
-
46
- puts "Application created on path #{app_path}"
29
+
47
30
  else
48
31
  puts "Usage: ricque new [app_name]"
49
32
  end
@@ -0,0 +1,57 @@
1
+ module Ricque
2
+ class AppGenerator
3
+ def initialize app_name, path=File.expand_path('.')
4
+ @app_name = app_name
5
+ @path = path
6
+ end
7
+
8
+ def app_path
9
+ File.join(@path, dashesized_app_name)
10
+ end
11
+
12
+ def camelized_app_name
13
+ @app_name.camelize
14
+ end
15
+
16
+ def dashesized_app_name
17
+ @app_name.dasherize
18
+ end
19
+
20
+ def template_path
21
+ Ricque.template_path
22
+ end
23
+
24
+ def create!
25
+ create_path
26
+ copy_files
27
+ puts "Application created on path #{app_path}"
28
+ end
29
+
30
+ private
31
+
32
+ def create_path
33
+ puts "Creating path #{app_path}"
34
+ if Dir.exists?(app_path)
35
+ puts "Path #{app_path} already exists"
36
+ raise ArgumentError, "Path #{app_path} already exists"
37
+ end
38
+
39
+ Dir.mkdir app_path
40
+ end
41
+
42
+ def copy_files
43
+ Dir.chdir(app_path) do
44
+ puts "Copying files"
45
+ FileUtils.cp_r template_path, ".", :preserve => true
46
+ puts "Renaming file content"
47
+ `grep -Irl "Ricque" . | xargs sed -i '' 's/Ricque/#{camelized_app_name}/g'`
48
+ `grep -Irl "ricque" . | xargs sed -i '' 's/ricque/#{dashesized_app_name}/g'`
49
+ `grep -Irl "{RICQUE_VERSION}" . | xargs sed -i '' 's/{RICQUE_VERSION}/#{Ricque::VERSION}/g'`
50
+ puts "Renaming files"
51
+ FileUtils.mv 'lib/ricque', "lib/#{dashesized_app_name}"
52
+ FileUtils.mv "lib/ricque.rb", "lib/#{dashesized_app_name}.rb"
53
+ FileUtils.mv "lib/tasks/ricque.rake", "lib/tasks/#{dashesized_app_name}.rake"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Ricque
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/ricque.rb CHANGED
@@ -1,5 +1,29 @@
1
- require_relative 'ricque/version'
1
+ require 'rubygems'
2
+ require 'active_support/inflector'
3
+ require 'fileutils'
2
4
 
3
5
  module Ricque
4
-
6
+ def self.root
7
+ ::File.expand_path('../..', __FILE__)
8
+ end
9
+
10
+ def self.template_path
11
+ ::File.join(root, 'lib', 'template', '.')
12
+ end
13
+
14
+ def self.lib_path
15
+ ::File.join(::File.expand_path("lib/ricque", self.root), '**', '*.rb')
16
+ end
17
+
18
+ def self.initialize!
19
+ load_path lib_path
20
+ end
21
+
22
+ private
23
+
24
+ def self.load_path path
25
+ files = ::Dir[path]
26
+ files.each { |file| load file }
27
+ nil
28
+ end
5
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ricque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000Z
12
+ date: 2013-01-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70287626466960 !ruby/object:Gem::Requirement
16
+ requirement: &70213412739500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 3.2.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70287626466960
24
+ version_requirements: *70213412739500
25
25
  description: Ricque is a generator of Ruby applications with bootstrap similar to
26
26
  Rails' bootstrap
27
27
  email:
@@ -31,6 +31,7 @@ executables:
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - lib/ricque/app_generator.rb
34
35
  - lib/ricque/version.rb
35
36
  - lib/ricque.rb
36
37
  - lib/template/.gitignore