rag 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  /vendor
4
4
  /tmp
5
5
  /rfrom
6
+ *.gem
data/Gemfile CHANGED
@@ -1,8 +1,14 @@
1
1
  source :rubygems
2
2
 
3
- #gem 'tagen', :path => '/home/guten/dev/rb/tagen', :require => 'tagen/core'
4
- gem 'tagen', '~>1.0.0', :require => 'tagen/core'
5
- gem 'pa', '~>1.0.0'
3
+ gem 'tagen', '~>1.1.0', :require => 'tagen/core'
4
+ #gem 'tagen', :path => '/home/guten/dev/one/tagen', :require => 'tagen/core'
5
+
6
+ #gem 'pa', '~>1.1.0'
7
+ gem 'pa', :path => '/home/guten/dev/one/pa'
8
+
9
+ #gem 'optimism', '~>3.0.0'
10
+ gem 'optimism', :path => '/home/guten/dev/one/optimism'
11
+
6
12
  gem 'thor', '~>0.14.0'
7
13
 
8
14
  group :development do
@@ -10,5 +16,3 @@ group :development do
10
16
  gem 'watchr'
11
17
  gem 'yard'
12
18
  end
13
-
14
- #gemspec
data/Gemfile.lock CHANGED
@@ -1,32 +1,44 @@
1
+ PATH
2
+ remote: /home/guten/dev/one/optimism
3
+ specs:
4
+ optimism (3.1.0)
5
+ hike (~> 1.2.0)
6
+
7
+ PATH
8
+ remote: /home/guten/dev/one/pa
9
+ specs:
10
+ pa (1.1.4)
11
+
1
12
  GEM
2
13
  remote: http://rubygems.org/
3
14
  specs:
4
- activesupport (3.0.8)
5
- diff-lcs (1.1.2)
6
- pa (1.0.0)
7
- pd (1.0.1)
8
- rspec (2.5.0)
9
- rspec-core (~> 2.5.0)
10
- rspec-expectations (~> 2.5.0)
11
- rspec-mocks (~> 2.5.0)
12
- rspec-core (2.5.1)
13
- rspec-expectations (2.5.0)
15
+ activesupport (3.1.3)
16
+ multi_json (~> 1.0)
17
+ diff-lcs (1.1.3)
18
+ hike (1.2.1)
19
+ multi_json (1.0.4)
20
+ rspec (2.8.0)
21
+ rspec-core (~> 2.8.0)
22
+ rspec-expectations (~> 2.8.0)
23
+ rspec-mocks (~> 2.8.0)
24
+ rspec-core (2.8.0)
25
+ rspec-expectations (2.8.0)
14
26
  diff-lcs (~> 1.1.2)
15
- rspec-mocks (2.5.0)
16
- tagen (1.0.2)
17
- activesupport
18
- pd
27
+ rspec-mocks (2.8.0)
28
+ tagen (1.1.2)
29
+ activesupport (~> 3.1.0)
19
30
  thor (0.14.6)
20
31
  watchr (0.7)
21
- yard (0.6.5)
32
+ yard (0.7.5)
22
33
 
23
34
  PLATFORMS
24
35
  ruby
25
36
 
26
37
  DEPENDENCIES
27
- pa (~> 1.0.0)
38
+ optimism!
39
+ pa!
28
40
  rspec
29
- tagen (~> 1.0.0)
41
+ tagen (~> 1.1.0)
30
42
  thor (~> 0.14.0)
31
43
  watchr
32
44
  yard
data/README.md CHANGED
@@ -1,18 +1,21 @@
1
1
  Rag, a project helper
2
2
  =====================
3
3
 
4
- **Homepage**: [https://github.com/GutenYe/rag](https://github.com/GutenYe/rag) <br/>
5
- **Author**: Guten <br/>
6
- **License**: MIT-LICENSE <br/>
7
- **Documentation**: [http://rubydoc.info/gems/rag/frames](http://rubydoc.info/gems/rag/frames) <br/>
8
- **Issue Tracker**: [https://github.com/GutenYe/rag/issues](https://github.com/GutenYe/rag/issues) <br/>
4
+ | Homepage: | https://github.com/GutenYe/rag |
5
+ |----------------|---------------------------------------|
6
+ | Author: | Guten |
7
+ | License: | MIT-LICENSE |
8
+ | Documentation: | http://rubydoc.info/gems/rag/frames |
9
+ | Issue Tracker: | https://github.com/GutenYe/rag/issues |
9
10
 
10
- Overview
11
- --------
11
+ a project helper, include create, develop, test and release.
12
12
 
13
- a project helper, include create, develop, test, release.
13
+ Features
14
+ --------
14
15
 
15
- depends Gemfile.
16
+ * easy to extend.
17
+ * use thor as default task DSL.
18
+ * with vim support. see resources
16
19
 
17
20
  Usage
18
21
  -----
@@ -26,14 +29,6 @@ Usage
26
29
 
27
30
  rag release # build gem and push to Ruygems
28
31
 
29
-
30
- Features
31
- --------
32
-
33
- * easy to extend.
34
- * use thor as default task DSL.
35
- * with vim support. see resources
36
-
37
32
  Configuration
38
33
  -------------
39
34
 
@@ -68,7 +63,7 @@ in Ragfile
68
63
 
69
64
  require 'rag/foo'
70
65
 
71
- avaliable variable for writing extension. they are read from .gemspec file
66
+ available variable for writing extension. they are read from .gemspec file
72
67
 
73
68
  Rc.o.project # project name
74
69
  Rc.o.version
@@ -77,34 +72,33 @@ avaliable variable for writing extension. they are read from .gemspec file
77
72
  Template
78
73
  --------
79
74
 
80
- from system-level: GEM(rag)/template and user-level: ~/.rag/template
75
+ template path: ~/.rag/
81
76
 
82
- template/foo/a.erb
77
+ ~/.rag/foo/a.erb
83
78
 
84
79
  <%=project%>
85
80
 
86
81
  local variables in erb file are from ~/.ragrc and APP/.ragrc
87
82
 
88
- default template see {file:template/default.readme}
89
-
90
- Contributing
91
- -------------
92
-
93
- * report bugs/featues to issue tracker.
94
- * fork it and pull a request.
95
- * improve documentation.
96
- * feel free to post any ideas.
97
-
98
83
  Install
99
84
  ----------
100
85
 
101
- gem install --no-wrappers rag
102
- gem update --no-wrappers rag
86
+ gem install rag
103
87
 
104
- or you can write `gem: --no-wrappers` into ~/.gemrc file, then
88
+ Note on Patches/Pull Requests
89
+ -----------------------------
105
90
 
106
- gem install rag
107
- gem update rag
91
+ 1. Fork the project.
92
+ 2. Make your feature addition or bug fix.
93
+ 3. Add tests for it. This is important so I don't break it in a future version unintentionally.
94
+ 4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
95
+ 5. Send me a pull request. Bonus points for topic branches.
96
+ 6. Coding Style Guide: https://gist.github.com/1105334
97
+
98
+ Contributors
99
+ ------------
100
+
101
+ * [contributors](https://github.com/GutenYe/rag/contributors)
108
102
 
109
103
  Resources
110
104
  ---------
@@ -115,4 +109,13 @@ Resources
115
109
 
116
110
  Copyright
117
111
  ---------
118
- Copyright &copy; 2011 by Guten. this library released under MIT-LICENSE, See {file:LICENSE} for futher details.
112
+
113
+ (the MIT License)
114
+
115
+ Copyright (c) 2011 Guten
116
+
117
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
118
+
119
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
120
+
121
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/rag CHANGED
@@ -1,20 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative "../lib/rag"
3
2
 
4
- # default plugin
5
- require_relative "../lib/rag/new"
6
- require_relative "../lib/rag/gem"
7
- require_relative "../lib/rag/doc"
8
- require_relative "../lib/rag/test"
3
+ require_relative "../lib/rag"
9
4
 
10
5
  # load Ragfile
11
- if Pa.exists? "Ragfile"
6
+ if Pa.exists?("Ragfile")
12
7
  load "Ragfile"
13
8
  end
14
9
 
15
10
  # load tasks/*.rag
16
- Pa.glob 'tasks/*.rag' do |pa|
11
+ Pa.glob("tasks/*.rag") { |pa|
17
12
  load pa.path
13
+ }
14
+
15
+ begin
16
+ Rag.start
17
+ rescue Rag::RagError => e
18
+ Rag.ui.error e.message
19
+ Rag.ui.debug e.backtrace.join("\n")
20
+ exit 1
21
+ rescue Interrupt => e
22
+ Rag.ui.error "\nQuitting..."
23
+ Rag.ui.debug e.backtrace.join("\n")
24
+ exit 1
18
25
  end
19
26
 
20
- Rag.start
@@ -1,8 +1,8 @@
1
- author: XX
2
- email: XX
3
- license: XX
1
+ author = 'XX'
2
+ email = 'XX'
3
+ license = 'XX'
4
4
 
5
5
  github:
6
- username: XX
6
+ username = 'XX'
7
7
 
8
- # vim: filetype=yaml
8
+ # vim: filetype=ruby
data/lib/rag.rb CHANGED
@@ -1,8 +1,42 @@
1
- require "tagen/core"
2
- require "pa"
3
- require "thor"
1
+ libdir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
+
4
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
5
+ require "bundler/setup"
6
+ Bundler.require
4
7
 
5
8
  class Rag < Thor
9
+ Error = Class.new Exception
10
+ RagError = Class.new Exception
11
+
12
+ autoload :VERSION, "rag/version"
13
+ autoload :UI, "rag/ui"
14
+ autoload :Util, "rag/util"
15
+
16
+ Rc = Optimism.require "rag/rc", "~/.ragrc"
17
+
18
+ include Thor::Actions
19
+
20
+ class_option "no-color", :type => :boolean, :banner => "Disable colorization in output"
21
+ class_option "verbose", :type => :boolean, :banner => "Enable verbose output mode", :aliases => "-V"
22
+
23
+ class << self
24
+ attr_accessor :ui
25
+
26
+ def ui
27
+ @ui ||= UI::Base.new
28
+ end
29
+ end
30
+
31
+ def initialize(*)
32
+ super
33
+ the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
34
+ Rag.ui = UI::Shell.new(the_shell)
35
+ Rag.ui.debug! if options["verbose"]
36
+ end
6
37
  end
7
38
 
8
- require_relative "rag/rc"
39
+ require "rag/new"
40
+ require "rag/gem"
41
+ require "rag/test"
42
+ require "rag/doc"
data/lib/rag/gem.rb CHANGED
@@ -1,23 +1,21 @@
1
1
  class Rag < Thor
2
-
3
2
  desc "release", "release this gem to RubyGems.org"
4
3
  def release
5
- system "gem build #{Rc.o.project}.gemspec", :verbose
6
- system "gem push #{Rc.o.project}-#{Rc.o.version}.gem", :verbose
7
- Pa.rm "#{Rc.o.project}-#{Rc.o.version}.gem", verbose: true
4
+ system "gem build #{Rc.o.project}.gemspec", :verbose => true
5
+ system "gem push #{Rc.o.project}-#{Rc.o.version}.gem", :verbose => true
6
+ Pa.rm "#{Rc.o.project}-#{Rc.o.version}.gem", :verbose => true
8
7
  end
9
8
 
10
9
  desc "install", "install this gem to your system"
11
10
  def install
12
11
  sudo = Process.uid == 0 ? "" : "sudo"
13
- system "gem build #{Rc.o.project}.gemspec", :verbose
14
- system "#{sudo} gem install #{Rc.o.project}-#{Rc.o.version}.gem", :verbose
15
- Pa.rm "#{Rc.o.project}-#{Rc.o.version}.gem", verbose: true
12
+ system "gem build #{Rc.o.project}.gemspec", :verbose => true
13
+ system "#{sudo} gem install #{Rc.o.project}-#{Rc.o.version}.gem", :verbose => true
14
+ Pa.rm "#{Rc.o.project}-#{Rc.o.version}.gem", :verbose => true
16
15
  end
17
16
 
18
17
  desc "build", "build this gem at current directory "
19
18
  def build
20
- system "gem build #{Rc.o.project}.gemspec", :verbose
19
+ system "gem build #{Rc.o.project}.gemspec", :verbose => true
21
20
  end
22
-
23
21
  end
data/lib/rag/new.rb CHANGED
@@ -1,39 +1,156 @@
1
- require_relative "new/project"
2
-
3
- class Rag < Thor
4
- desc "new <project_name> or new .", "create a new project or use current directory"
5
- method_option "author", type: :string, banner: "NAME", desc: "the project's author name"
6
- method_option "email", type: :string, desc: "author's email address"
7
- method_option "template", type: :string, default: "default", banner: "NAME", desc: "which template to use"
8
- method_option "name", type: :string, banner: "NAME", desc: "rag new . [--name hello] default from File.basename(cur_path)"
9
- method_option "list", type: :boolean, desc: "list templates", aliaes: %w(-l)
10
- def new name
11
- if options.list?
12
- Project.list_templates
13
- end
14
-
15
- check_first_time
16
-
17
- Project.create name, options
1
+ class Rag # ::Project
2
+ =begin
3
+
4
+ == ERB support variables
5
+ * project # the name of your project, provided by `rag new <project_name>"
6
+ * others from .ragrc
7
+
8
+ == Configrauton
9
+
10
+ + ~/.ragrc
11
+ + APP/.ragrc
12
+ + from cmdline
13
+
14
+ you can use arbitrary name in .ragrc, then you can use then in template file.
15
+
16
+ =end
17
+ class Project
18
+ class << self
19
+ def create(*args)
20
+ Project.new(*args).create
21
+ end
22
+ end
23
+
24
+ attr_reader :options, :template, :app_path
25
+ def initialize(template, app_path, o={})
26
+ @template = template
27
+ @options = o
28
+ o["name"] ||= Pa.absolute(app_path).fname
29
+ o["class_name"] ||= o["name"].capitalize
30
+ @app_path = Pa(app_path)
31
+ end
32
+
33
+ def create
34
+ create_project_directory
35
+ if @app_path == "."
36
+ copy_files
37
+ else
38
+ copy_files :overwrite => true
39
+ end
40
+ end
41
+
42
+ private
43
+ def create_project_directory
44
+ if @app_path == "."
45
+ return
46
+ elsif app_path.exists?
47
+ puts "dest directory `#{app_path}' already existing"
48
+ exit
49
+ else
50
+ Pa.mkdir app_path
51
+ end
52
+ end
53
+
54
+ def template_path
55
+ pa1 = Pa("#{Rc.p.home}/#{template}")
56
+ return pa1.p if pa1.exists?
57
+
58
+ raise Error, "can't find template -- #{template}"
59
+ end
60
+
61
+ def copy_files(o={})
62
+ Pa.each_r template_path do |pa, relative, e|
63
+ # skip *~
64
+ next if pa.fn2 =~ /~$/
65
+
66
+ # convert __project__ to options["name"]
67
+ dest = app_path.join(relative.gsub(/__project__/, options["name"]))
68
+ path_msg = relative.gsub(/__project__/, options["name"]).gsub(/\.erb$/,"")
69
+
70
+ # skip directory not file
71
+ next if dest.exists? and dest.directory?
72
+
73
+ if not o[:overwrite] and (dest.exists? or dest.sub(/\.erb$/, "").exists?)
74
+ print "Overwrite #{path_msg}? [yna] "
75
+ case $stdin.gets.rstrip
76
+ when "y"
77
+ puts "[overwrite] #{path_msg}"
78
+ copy_file pa, dest, o
79
+ when "a"
80
+ puts "[overwrite] #{path_msg}"
81
+ o[:overwrite] = true
82
+ copy_file pa, dest, o
83
+ when "q"
84
+ exit
85
+ else
86
+ puts "[skip] #{path_msg}"
87
+ next
88
+ end
89
+ elsif o[:overwrite] and dest.exists?
90
+ puts "[overwrite] #{path_msg}"
91
+ copy_file pa, dest, o
92
+ else
93
+ # classify: file dir/
94
+ puts "[create] #{path_msg}" + (dest.directory? ? "/" : "")
95
+ copy_file pa, dest, o
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ # not rescurive copy
102
+ def copy_file(src, dest, o)
103
+ if src.e == "erb"
104
+ copy_erb_file src, dest.sub(/\.erb$/,"")
105
+ else
106
+ Pa.cp src, dest, o.merge(special: true)
107
+ end
108
+ end
109
+
110
+ def copy_erb_file(src, dest)
111
+ result = Util::ERB.new(File.read(src.p)).result(binding, get_erb_config)
112
+ File.write dest.p, result
113
+ dest.chmod(src.stat.mode)
114
+ end
115
+
116
+ def get_erb_config
117
+ config = Optimism.require(Rc.p.apprc.p, Rc.p.homerc.p) + Optimism[options]
118
+ config["project"] = options["name"]
119
+ config["klass"] = options["class_name"]
120
+ config["template"] = @template
121
+
122
+ config._data
123
+ end
124
+ end
125
+ end
126
+
127
+ class Rag < Thor
128
+ desc "new <template> <app_path>", "create a new project"
129
+ method_option "name", :aliases => "-n", :type => :string, :banner => "NAME", :desc => "another name"
130
+ method_option "class_name", :aliases => "-c", :type => :string, :banner => "CLASS_NAME", :desc => "another class name"
131
+ def new(template, app_path)
132
+ check_first_time!
133
+
134
+ Project.create template.dup, app_path.dup, options.dup
18
135
  end
19
136
 
20
- private
21
- def check_first_time
137
+ private
138
+ def check_first_time!
22
139
  return unless first_time?
23
140
 
24
141
  puts "first time run rag"
25
- (Rc.pa.data+'/home_config').each do |src|
26
- dest = '~/' + src.b.sub(/^_/, '.')
142
+ Pa.each("#{Rc.p.data}/home_config") { |src|
143
+ dest = "~/" + src.b.sub(/^_/, ".")
27
144
  puts "[create] #{dest.short}"
28
145
  Pa.cp src, dest
29
- end
146
+ }
147
+
30
148
  puts "exit."
31
149
  puts "please edit ~/.ragrc config file, then run rag again"
32
150
  exit
33
151
  end
34
152
 
35
153
  def first_time?
36
- Rc.pa.config.exists? ? false : true
154
+ Rc.p.homerc.exists? ? false : true
37
155
  end
38
-
39
156
  end