prigner 0.1.0 → 0.1.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.
Files changed (34) hide show
  1. data/CHANGELOG +123 -200
  2. data/{README.mkd → README.rdoc} +36 -42
  3. data/Rakefile +140 -112
  4. data/lib/prigner/cli/copy.rb +39 -0
  5. data/lib/prigner/cli/new.rb +10 -8
  6. data/lib/prigner/extensions.rb +17 -2
  7. data/lib/prigner/template.rb +2 -24
  8. data/lib/prigner.rb +46 -10
  9. data/prigner.gemspec +27 -30
  10. data/test/fixtures/templates/shared/templates/ruby/sinatra/models/README.mkd +2 -0
  11. data/test/fixtures/templates/shared/templates/ruby/sinatra/models/Rakefile +7 -0
  12. data/test/fixtures/templates/shared/templates/ruby/sinatra/models/empty_test.rb +21 -0
  13. data/test/fixtures/templates/shared/templates/ruby/sinatra/models/module.rb +6 -0
  14. data/test/fixtures/templates/shared/templates/ruby/sinatra/specfile +18 -0
  15. data/test/fixtures/templates/user/.prigner/sources +1 -0
  16. data/test/helpers.rb +36 -1
  17. data/test/spec_test.rb +1 -1
  18. data/test/template_test.rb +7 -9
  19. metadata +30 -32
  20. /data/test/fixtures/templates/shared/{ruby → templates/ruby}/default/README.mkd +0 -0
  21. /data/test/fixtures/templates/shared/{ruby → templates/ruby}/default/models/README.mkd +0 -0
  22. /data/test/fixtures/templates/shared/{ruby → templates/ruby}/default/models/Rakefile +0 -0
  23. /data/test/fixtures/templates/shared/{ruby → templates/ruby}/default/models/empty_test.rb +0 -0
  24. /data/test/fixtures/templates/shared/{ruby → templates/ruby}/default/models/module.rb +0 -0
  25. /data/test/fixtures/templates/shared/{ruby → templates/ruby}/default/specfile +0 -0
  26. /data/test/fixtures/templates/user/{bash → .prigner/templates/bash}/default/specfile +0 -0
  27. /data/test/fixtures/templates/user/{ruby → .prigner/templates/ruby}/program/models/README.erb +0 -0
  28. /data/test/fixtures/templates/user/{ruby → .prigner/templates/ruby}/program/models/cli.rb.erb +0 -0
  29. /data/test/fixtures/templates/user/{ruby → .prigner/templates/ruby}/program/models/module.rb.erb +0 -0
  30. /data/test/fixtures/templates/user/{ruby → .prigner/templates/ruby}/program/models/program.rb.erb +0 -0
  31. /data/test/fixtures/templates/user/{ruby → .prigner/templates/ruby}/program/specfile +0 -0
  32. /data/test/fixtures/templates/user/{vim → .prigner/templates/vim}/default/specfile +0 -0
  33. /data/test/fixtures/templates/user/{vim → .prigner/templates/vim}/plugin/specfile +0 -0
  34. /data/test/fixtures/templates/user/{vim → .prigner/templates/vim}/syntax/specfile +0 -0
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rake/clean"
2
2
  require "lib/prigner"
3
3
 
4
- # Helpers
4
+ # Configurations
5
5
  # =============================================================================
6
6
 
7
7
  def rdoc(*args)
@@ -24,120 +24,125 @@ def test(pattern)
24
24
  end
25
25
  end
26
26
 
27
+ def git(cmd, *args)
28
+ `git #{cmd.to_s.gsub('_','-')} #{args.join(' ')}`
29
+ end
30
+
27
31
  def manifest
28
- @manifest ||= `git ls-files`.split("\n").sort.reject do |out|
32
+ @manifest ||= git(:ls_files).split("\n").sort.reject do |out|
29
33
  out =~ /^\./ || out =~ /^doc/
30
34
  end.map do |file|
31
35
  " #{file.inspect}"
32
36
  end.join(",\n")
33
37
  end
34
38
 
39
+ def version
40
+ @version ||= Prigner.version
41
+ end
42
+
43
+ def tag
44
+ git(:tag).split("\n").last
45
+ end
46
+
47
+ def release_notes
48
+ @release_notes ||= Pathname.new("v#{spec.version}.rdoc")
49
+ end
50
+
35
51
  def log
36
- @log ||= `git log --date=short --format='%d;%cd;%s;%b;'`
52
+ yaml = git :log,
53
+ "--date=short",
54
+ "--format='- head: %d%n date: %cd%n summary: %s%n notes: \"%n%b\"%n'"
55
+ YAML.load(yaml)
37
56
  end
38
57
 
39
- def version
40
- @version ||= Prigner.version
58
+ def specfile
59
+ @specfile ||= Pathname.new("prigner.gemspec")
60
+ end
61
+
62
+ def spec
63
+ @spec ||= eval(specfile.read)
41
64
  end
42
65
 
43
- def gemspec
44
- @gemspec ||= Struct.new(:spec, :file).new
45
- @gemspec.file ||= Pathname.new("prigner.gemspec")
46
- @gemspec.spec ||= eval @gemspec.file.read
47
- @gemspec
66
+ def package_path
67
+ specfile.dirname.join("pkg").join("#{File.basename(spec.file_name, '.*')}")
68
+ end
69
+
70
+ def package(ext = "")
71
+ specfile.dirname.join("#{package_path}#{ext}")
48
72
  end
49
73
 
50
74
  # Documentation
51
75
  # =============================================================================
52
76
 
53
- namespace :doc do
77
+ CLOBBER << FileList["doc/*"]
78
+
79
+ file "doc/api/index.html" => FileList["lib/**/*.rb", "README.rdoc", "CHANGELOG"] do |filespec|
80
+ rm_rf "doc"
81
+ rdoc "--op", "doc/api",
82
+ "--charset", "utf8",
83
+ "--main", "'Prigner'",
84
+ "--title", "'Prigner v#{version.tag} API Documentation'",
85
+ "--inline-source",
86
+ "--promiscuous",
87
+ "--line-numbers",
88
+ filespec.prerequisites.join(" ")
89
+ end
54
90
 
55
- CLOBBER << FileList["doc/*"]
91
+ desc "Build API documentation (doc/api)."
92
+ task :doc => "doc/api/index.html"
56
93
 
57
- file "doc/api/index.html" => FileList["lib/**/*.rb", "README.mkd", "CHANGELOG"] do |filespec|
58
- rm_rf "doc"
59
- rdoc "--op", "doc/api",
60
- "--charset", "utf8",
61
- "--main", "'Prigner'",
62
- "--title", "'Prigner v#{version.tag} API Documentation'",
63
- "--inline-source",
64
- "--promiscuous",
65
- "--line-numbers",
66
- filespec.prerequisites.join(" ")
67
- end
68
-
69
- desc "Build API documentation (doc/api)"
70
- task :api => "doc/api/index.html"
94
+ desc "Build CHANGELOG file."
95
+ task :changelog do
96
+ open("CHANGELOG", "w+") do |changelog|
97
+ title = lambda do |charlevel, text|
98
+ text << "\n" << charlevel
99
+ end
71
100
 
72
- desc "Creates/updates CHANGELOG file."
73
- task :changelog do |spec|
74
- historic = {}
75
- text = ""
101
+ changelog << "= #{Prigner::Version} - Changelog"
76
102
 
77
- log.scan(/(.*?);(.*?);(.*?);(.*?);/m) do |tag, date, subject, content|
78
-
79
- historic[date] = {
80
- :release => "#{date} #{tag.match(/(v\d\..*)/im) ? tag : nil}",
81
- :changes => []
82
- } unless historic.has_key? date
103
+ historic = log.group_by { |entry| entry["date"] }
83
104
 
84
- historic[date][:changes] << "\n* #{subject}\n"
85
- historic[date][:changes] << content.gsub(/(.*?)\n/m){"\n #{$1}\n"} unless content.empty?
86
- end
105
+ historic.keys.sort.reverse.map do |date|
106
+ changelog << "\n\n" << "== #{date}" << "\n"
87
107
 
88
- historic.keys.sort.reverse.each do |date|
89
- entry = historic[date]
90
- puts "Adding historic from date #{date} ..."
91
- text << <<-end_text.gsub(/^[ ]{8}/,'')
92
- #{entry[:release]}
93
- #{"-" * entry[:release].size}
94
- #{entry[:changes]}
95
- end_text
108
+ for entry in historic[date]
109
+ notes = entry["notes"]
110
+ changelog << "\n* #{entry["summary"]}."
111
+ unless notes.empty?
112
+ changelog << notes.strip.gsub(/([\*-].*?)/){ "\n #{$1}" }
113
+ end
114
+ end
96
115
  end
97
116
 
98
- File.open("CHANGELOG", "w+") { |changelog| changelog << text }
99
- puts "Historic has #{historic.keys.size} entry dates"
100
- puts "Successfully updated CHANGELOG file"
117
+ puts "Successfully updated the CHANGELOG file with #{historic.keys.size} dates."
101
118
  end
102
-
103
119
  end
104
120
 
121
+ file "CHANGELOG" => :changelog
122
+
105
123
  # Versioning
106
124
  # =============================================================================
107
125
 
108
- namespace :version do
109
-
110
- major, minor, patch, build = version.tag.split(".").map{ |key| key.to_i } << 0
111
-
112
- desc "Dump major version"
113
- task :major do
114
- version.tag = "#{major+=1}.0.0"
115
- version.save!
116
- puts version.to_hash.to_yaml
117
- end
118
-
119
- desc "Dump minor version"
120
- task :minor do
121
- version.tag = "#{major}.#{minor+=1}.0"
122
- version.save!
123
- puts version.to_hash.to_yaml
124
- end
126
+ desc "Dump version (current v#{version.tag})."
127
+ task :version, [:counter,:release] do |spec, args|
128
+ numbering = version.numbering
129
+ tagnames = %w[major minor patch]
125
130
 
126
- desc "Dump patch version"
127
- task :patch do
128
- version.tag = "#{major}.#{minor}.#{patch+=1}"
129
- version.save!
130
- puts version.to_hash.to_yaml
131
+ if index = tagnames.index(args[:counter])
132
+ numbering[index] += 1
133
+ numbering.fill(0, (index + 1)..-1)
134
+ else
135
+ numbering[-1] += 1
131
136
  end
132
137
 
133
- desc "Dump build version"
134
- task :build do
135
- version.tag = "#{major}.#{minor}.#{patch}.#{build+=1}"
136
- version.save!
137
- puts version.to_hash.to_yaml
138
- end
138
+ numbering[-1] = "#{numbering[-1]}#{args[:release]}"
139
+ version.tag = numbering.join(".")
140
+ version.save!
141
+ puts version.to_hash.to_yaml
142
+ end
139
143
 
140
- desc "Update version date (current #{version.date})"
144
+ namespace :version do
145
+ desc "Update version date (current #{version.date})."
141
146
  task :date, [:date] do |spec, args|
142
147
  require "parsedate"
143
148
  require "date"
@@ -148,58 +153,81 @@ namespace :version do
148
153
  end
149
154
  end
150
155
 
151
- task :version => "version:build"
152
-
153
- # RubyGems
156
+ # Packaging
154
157
  # =============================================================================
155
158
 
156
- namespace :gem do
159
+ CLOBBER << FileList["#{package_path.dirname}/*"]
157
160
 
158
- file gemspec.file => FileList["{lib,test}/**", "Rakefile"] do
159
- spec = gemspec.file.read
161
+ task :tagged do
162
+ abort "The version #{version.tag} is not tagged, yet." unless tag[1..-1] == version.tag
163
+ end
160
164
 
161
- puts "Updating version ..."
162
- spec.sub! /spec\.version\s*=\s*".*?"/, "spec.version = #{version.tag.inspect}"
165
+ file specfile => FileList["{bin,lib,test}/**", "Rakefile"] do
166
+ spec = specfile.read
163
167
 
164
- puts "Updating date of version ..."
165
- spec.sub! /spec\.date\s*=\s*".*?"/, "spec.date = #{version.date.to_s.inspect}"
168
+ puts "Updating version ..."
169
+ spec.sub! /spec\.version\s*=\s*".*?"/, "spec.version = #{version.tag.inspect}"
166
170
 
167
- puts "Updating file list ..."
168
- spec.sub! /spec\.files\s*=\s*\[.*?\]/m, "spec.files = [\n#{manifest}\n ]"
171
+ puts "Updating date of version ..."
172
+ spec.sub! /spec\.date\s*=\s*".*?"/, "spec.date = #{version.date.to_s.inspect}"
169
173
 
170
- gemspec.file.open("w+") { |file| file << spec }
174
+ puts "Updating file list ..."
175
+ spec.sub! /spec\.files\s*=\s*\[.*?\]/m, "spec.files = [\n#{manifest}\n ]"
171
176
 
172
- puts "Successfully update #{gemspec.file} file"
173
- end
177
+ specfile.open("w+") { |file| file << spec }
174
178
 
175
- desc "Build gem package #{gemspec.spec.file_name}"
176
- task :build => gemspec.file do
177
- sh "gem build #{gemspec.file}"
178
- end
179
+ puts "Successfully update #{specfile} file"
180
+ end
179
181
 
180
- desc "Deploy gem package to RubyGems.org"
181
- task :deploy => :build do
182
- sh "gem push #{gemspec.spec.file_name}"
183
- end
182
+ directory package_path.to_s
183
+
184
+ file package(".gem") => [ specfile, package_path.dirname ] do |file|
185
+ sh "gem build #{specfile}"
186
+ mv spec.file_name, file.prerequisites.last
187
+ end
184
188
 
185
- desc "Install gem package #{gemspec.spec.file_name}"
186
- task :install => :build do
187
- sh "gem install #{gemspec.spec.file_name} --local"
189
+ file package(".tar.gz") => [ specfile, package_path ] do |file|
190
+ spec.files.each do |source|
191
+ package_path.join(source).dirname.mkpath
192
+ cp source, package_path.join(source)
188
193
  end
194
+ cd package_path.dirname do
195
+ sh "tar czvf #{package(".tar.gz").basename} #{package_path.basename}/*"
196
+ end
197
+ end
189
198
 
190
- desc "Uninstall gem package #{gemspec.spec.file_name}"
191
- task :uninstall do
192
- sh "gem uninstall #{gemspec.spec.name} --version #{gemspec.spec.version}"
199
+ desc "Build packages."
200
+ task :package => [package(".gem"), package(".tar.gz")]
201
+
202
+ desc "Release gem package to repositories."
203
+ task :release => [ :tagged, :package ] do
204
+ sh "gem push #{package('.gem')}"
205
+ { :release => ".gem", :file => ".tar.gz" }.each do |file, ext|
206
+ sh "rubyforge add_#{file}",
207
+ "#{spec.rubyforge_project}",
208
+ "#{spec.name} #{spec.version} #{package(ext)}"
209
+ end
210
+ if release_notes.exist?
211
+ sh "rubyforge add_news 'Prigner v#{spec.version} released' '#{release_notes.read}'"
193
212
  end
213
+ end
214
+
215
+ desc "Install gem package #{spec.file_name}."
216
+ task :install => :package do
217
+ sh "gem install #{package('.gem')} --local"
218
+ end
194
219
 
220
+ desc "Uninstall gem package #{spec.file_name}."
221
+ task :uninstall do
222
+ sh "gem uninstall #{spec.name} --version #{spec.version}"
195
223
  end
196
224
 
197
- task :gem => "gem:build"
225
+ task :gem => package(".gem")
198
226
 
199
227
  # Test
200
228
  # =============================================================================
201
229
 
202
- desc "Run tests"
230
+ desc "Run tests."
203
231
  task :test, [:pattern] do |spec, args|
204
232
  test(args[:pattern] ? "test/#{args[:pattern]}_test.rb" : "test/*_test.rb")
205
233
  end
@@ -207,5 +235,5 @@ end
207
235
  # Default
208
236
  # =============================================================================
209
237
 
210
- task :default => "test"
238
+ task :default => :test
211
239
 
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2010 Hallison Batista
2
+
3
+ require "prigner"
4
+
5
+ program = :prign
6
+ command = File.basename(__FILE__, ".rb")
7
+
8
+ begin
9
+ ARGV.options do |arguments|
10
+
11
+ arguments.summary_indent = " "
12
+ arguments.summary_width = 24
13
+ arguments.banner = <<-end_banner.gsub /^[ ]{6}/, ''
14
+ #{Prigner::Version}
15
+
16
+ Usage:
17
+ #{program} #{command} <namespace>[:template] <path>
18
+
19
+ Templates:
20
+ #{Prigner::CLI.templates.sort.join("\n" + arguments.summary_indent)}
21
+
22
+ end_banner
23
+
24
+ if ARGV.empty?
25
+ puts arguments
26
+ exit 0
27
+ else
28
+ arguments.parse!
29
+ end
30
+
31
+ end
32
+
33
+ rescue => error
34
+ puts "#{program}: #{command}: #{error.message} (#{error.class})"
35
+ puts "Try '#{program} #{command} -h' or '#{program} #{command} --help' for more information."
36
+ exit 1
37
+ end
38
+
39
+
@@ -22,8 +22,9 @@ begin
22
22
  end_banner
23
23
 
24
24
  unless ARGV.empty?
25
- name = ARGV.shift
26
- path = ARGV.shift unless name.nil?
25
+ arguments.parse!
26
+
27
+ name = ARGV.shift
27
28
 
28
29
  template = Prigner::Template.load(*name.split(":"))
29
30
 
@@ -52,12 +53,13 @@ begin
52
53
  end
53
54
  end
54
55
 
55
- unless path
56
- puts arguments
57
- exit 0
58
- end
59
-
60
- arguments.parse!
56
+ path = unless ARGV.empty?
57
+ arguments.parse!
58
+ path = ARGV.shift unless name.nil?
59
+ else
60
+ puts arguments
61
+ exit 0
62
+ end
61
63
 
62
64
  project = Prigner::Project.new(path)
63
65
  builder = Prigner::Builder.new(project, template)
@@ -58,9 +58,24 @@ class Struct
58
58
  end
59
59
 
60
60
  class Pathname
61
+ def get(file)
62
+ result = self.join(file.gsub(/^\/(.*?)$/){$1})
63
+ def result.to_s
64
+ return [self.inspect, self.read].join("\n")
65
+ end
66
+ result
67
+ end
68
+
69
+ alias read_body read
70
+
71
+ alias address expand_path
72
+
73
+ def port
74
+ nil
75
+ end
61
76
 
62
- def chpath(source, path)
63
- self.path.gsub(%r{#{source}}, path).to_path
77
+ def start
78
+ block_given? ? (yield self) : self
64
79
  end
65
80
 
66
81
  end
@@ -64,39 +64,17 @@ class Prigner::Template
64
64
  # Load template from shared directories. The shared path set the home user
65
65
  # directory and Prigner::Template shared files.
66
66
  def self.load(namespace, template = :default)
67
- shared_path.map do |source|
67
+ Prigner.shared_path.map do |source|
68
68
  path = "#{source}/#{namespace}/#{template}"
69
69
  return new(path) if File.exist? path
70
70
  end
71
71
  nil
72
72
  end
73
73
 
74
- # Look at user home and template shared path.
75
- def self.shared_path
76
- user_home_templates = File.join(user_home_basedir, "templates")
77
- [ user_home_templates, "#{Prigner::ROOT}/share/templates" ]
78
- end
79
-
80
- # User home.
81
- def self.user_home
82
- File.expand_path "~"
83
- rescue
84
- if File::ALT_SEPARATOR then
85
- "C:/"
86
- else
87
- "/"
88
- end
89
- end
90
-
91
- # User home base directory for Prigner files.
92
- def self.user_home_basedir
93
- File.join(user_home, ".prigner")
94
- end
95
-
96
74
  # Return all template paths placed in shared user or in project base
97
75
  # directory.
98
76
  def self.all_template_paths
99
- shared_path.map do |source|
77
+ Prigner.shared_path.map do |source|
100
78
  Dir.glob("#{source}/*/*")
101
79
  end.flatten.compact
102
80
  end
data/lib/prigner.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  #@ ---
2
2
  #@ :timestamp: 2009-07-16 14:05:16 -04:00
3
- #@ :date: 2010-10-18
4
- #@ :tag: 0.1.0
5
- #@ :milestone: Alpha
3
+ #@ :date: 2010-10-21
4
+ #@ :tag: 0.1.1
6
5
  # encoding: UTF-8
7
6
 
8
7
  # Copyright (c) 2009, 2010, Hallison Batista
@@ -28,6 +27,7 @@ module Prigner
28
27
  autoload :Project, "prigner/project"
29
28
  autoload :Model, "prigner/model"
30
29
  autoload :Template, "prigner/template"
30
+ autoload :Source, "prigner/source"
31
31
  autoload :Builder, "prigner/builder"
32
32
  autoload :CLI, "prigner/cli"
33
33
 
@@ -36,13 +36,17 @@ module Prigner
36
36
  @version ||= Version.current
37
37
  end
38
38
 
39
- class Version #:nodoc:
39
+ # The objective of this class is to implement various ideas proposed by the
40
+ # Semantic Versioning Specification (see reference[http://semver.org/]).
41
+ class Version
40
42
 
41
43
  FILE = Pathname.new(__FILE__).freeze
42
44
 
43
- attr_accessor :tag, :date, :milestone
45
+ attr_accessor :date, :tag
46
+
44
47
  attr_reader :timestamp
45
48
 
49
+ # Basic initialization of the attributes using a single hash.
46
50
  def initialize(attributes = {})
47
51
  attributes.each do |attribute, value|
48
52
  send("#{attribute}=", value) if respond_to? "#{attribute}="
@@ -50,17 +54,27 @@ module Prigner
50
54
  @timestamp = attributes[:timestamp]
51
55
  end
52
56
 
57
+ # The numbering of the major, minor and patch values.
58
+ def numbering
59
+ self.tag.split(".").map do |key|
60
+ if key.match(/^(\d{1,})(\w+).*$/)
61
+ [ $1.to_i, $2 ]
62
+ else
63
+ key.to_i
64
+ end
65
+ end.flatten
66
+ end
67
+
53
68
  def to_hash
54
- [:tag, :date, :milestone, :timestamp].inject({}) do |hash, key|
69
+ [:tag, :date, :timestamp].inject({}) do |hash, key|
55
70
  hash[key] = send(key)
56
71
  hash
57
72
  end
58
73
  end
59
74
 
60
75
  def save!
61
- @date = Date.today
62
76
  source = FILE.readlines
63
- source[0..4] = self.to_hash.to_yaml.to_s.gsub(/^/, '#@ ')
77
+ source[0..3] = self.to_hash.to_yaml.to_s.gsub(/^/, '#@ ')
64
78
  FILE.open("w+") do |file|
65
79
  file << source.join("")
66
80
  end
@@ -69,7 +83,7 @@ module Prigner
69
83
 
70
84
  class << self
71
85
  def current
72
- yaml = FILE.readlines[0..4].
86
+ yaml = FILE.readlines[0..3].
73
87
  join("").
74
88
  gsub(/\#@ /,'')
75
89
  new(YAML.load(yaml))
@@ -77,7 +91,7 @@ module Prigner
77
91
 
78
92
  def to_s
79
93
  name.match(/(.*?)::.*/)
80
- "#{$1} v#{current.tag}, #{current.date} (#{current.milestone})"
94
+ "#{$1} v#{current.tag} (#{current.date})"
81
95
  end
82
96
  end # self
83
97
 
@@ -182,5 +196,27 @@ module Prigner
182
196
 
183
197
  end
184
198
 
199
+ # Look at user home and template shared path.
200
+ def self.shared_path
201
+ user_home_templates = File.join(user_home_basedir, "templates")
202
+ [ user_home_templates, "#{Prigner::ROOT}/share/templates" ]
203
+ end
204
+
205
+ # User home base directory for Prigner files.
206
+ def self.user_home_basedir
207
+ File.join(user_home, ".prigner")
208
+ end
209
+
210
+ # User home.
211
+ def self.user_home
212
+ File.expand_path(ENV["HOME"])
213
+ rescue
214
+ if File::ALT_SEPARATOR then
215
+ "C:/"
216
+ else
217
+ "/"
218
+ end
219
+ end
220
+
185
221
  end # Prigner
186
222