prigner 0.1.0

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 (52) hide show
  1. data/CHANGELOG +248 -0
  2. data/COPYING +21 -0
  3. data/README.mkd +90 -0
  4. data/Rakefile +211 -0
  5. data/bin/prign +65 -0
  6. data/lib/prigner/builder.rb +51 -0
  7. data/lib/prigner/cli/copy.rb +0 -0
  8. data/lib/prigner/cli/list.rb +54 -0
  9. data/lib/prigner/cli/new.rb +96 -0
  10. data/lib/prigner/cli.rb +102 -0
  11. data/lib/prigner/extensions.rb +67 -0
  12. data/lib/prigner/model.rb +97 -0
  13. data/lib/prigner/project.rb +71 -0
  14. data/lib/prigner/template.rb +148 -0
  15. data/lib/prigner.rb +186 -0
  16. data/prigner.gemspec +120 -0
  17. data/share/templates/ruby/default/models/CHANGELOG +13 -0
  18. data/share/templates/ruby/default/models/COPYING +21 -0
  19. data/share/templates/ruby/default/models/README.rdoc +4 -0
  20. data/share/templates/ruby/default/models/module.rb +5 -0
  21. data/share/templates/ruby/default/specfile +16 -0
  22. data/share/templates/ruby/gem/models/CHANGELOG +13 -0
  23. data/share/templates/ruby/gem/models/COPYING +21 -0
  24. data/share/templates/ruby/gem/models/README.mkd +5 -0
  25. data/share/templates/ruby/gem/models/Rakefile +213 -0
  26. data/share/templates/ruby/gem/models/empty_test.rb +16 -0
  27. data/share/templates/ruby/gem/models/gemspec +67 -0
  28. data/share/templates/ruby/gem/models/module.rb +71 -0
  29. data/share/templates/ruby/gem/specfile +20 -0
  30. data/test/builder_test.rb +38 -0
  31. data/test/fixtures/model.rb.erb +12 -0
  32. data/test/fixtures/templates/shared/ruby/default/README.mkd +2 -0
  33. data/test/fixtures/templates/shared/ruby/default/models/README.mkd +2 -0
  34. data/test/fixtures/templates/shared/ruby/default/models/Rakefile +7 -0
  35. data/test/fixtures/templates/shared/ruby/default/models/empty_test.rb +21 -0
  36. data/test/fixtures/templates/shared/ruby/default/models/module.rb +6 -0
  37. data/test/fixtures/templates/shared/ruby/default/specfile +18 -0
  38. data/test/fixtures/templates/user/bash/default/specfile +0 -0
  39. data/test/fixtures/templates/user/ruby/program/models/README.erb +2 -0
  40. data/test/fixtures/templates/user/ruby/program/models/cli.rb.erb +5 -0
  41. data/test/fixtures/templates/user/ruby/program/models/module.rb.erb +6 -0
  42. data/test/fixtures/templates/user/ruby/program/models/program.rb.erb +3 -0
  43. data/test/fixtures/templates/user/ruby/program/specfile +18 -0
  44. data/test/fixtures/templates/user/vim/default/specfile +0 -0
  45. data/test/fixtures/templates/user/vim/plugin/specfile +0 -0
  46. data/test/fixtures/templates/user/vim/syntax/specfile +0 -0
  47. data/test/helpers.rb +22 -0
  48. data/test/model_test.rb +82 -0
  49. data/test/project_test.rb +46 -0
  50. data/test/spec_test.rb +64 -0
  51. data/test/template_test.rb +88 -0
  52. metadata +142 -0
data/CHANGELOG ADDED
@@ -0,0 +1,248 @@
1
+ 2010-10-16
2
+ -----------
3
+
4
+ * Adding of templates for Ruby projects
5
+
6
+ * Command for create a new project
7
+
8
+ * Status for CLI commands and fixes in builder test
9
+
10
+ * Improvements in builder
11
+
12
+ * All methods returns the path and the state information.
13
+
14
+ * Removing of PWD from paths.
15
+
16
+ 2010-10-15
17
+ -----------
18
+
19
+ * Small improvements in tasks and gemspec updates
20
+
21
+ * Updates in changelog file
22
+
23
+ * Fixes in the task to update changelog file
24
+
25
+ * Updates in date of version
26
+
27
+ * Adding of task to handle date of version
28
+
29
+ * Changes in the path to shared templates
30
+
31
+ * Updates in the informations
32
+
33
+ * Improvements in template and new CLI commands
34
+
35
+ * Show all templates for use in the CLI commands.
36
+
37
+ * RuntimeError when the CLI is unable to run a command.
38
+
39
+ * Adding list and new commands.
40
+
41
+ * Main executable
42
+
43
+ * Mask for template presentation
44
+
45
+ 2010-10-14
46
+ -----------
47
+
48
+ * Fixtures in handle exceptions in path and specfile
49
+
50
+ * Adjustments in exceptions for Specfile
51
+
52
+ * RubyGems
53
+
54
+ * Adjustments in the library path
55
+
56
+ 2010-10-13
57
+ -----------
58
+
59
+ * Removing conversion from string to pathname
60
+
61
+ 2010-09-29
62
+ -----------
63
+
64
+ * Fixes in the LOAD_PATH variable for requirements
65
+
66
+ * Configuration for RVM
67
+
68
+ * Unneeded files removed after builder test
69
+
70
+ * Errors fixed in load of the specfile
71
+
72
+ * Added the executable file in Gemspec
73
+
74
+ * Fixes in load the specfile without values
75
+
76
+ 2010-09-28
77
+ -----------
78
+
79
+ * Updates in Gemspec file
80
+
81
+ * Added new files
82
+
83
+ * Project class and CLI module have been separated from main file.
84
+
85
+ * A builder has been created for improve feedback in the CLI.
86
+
87
+ * Documentation.
88
+
89
+ * Several improves
90
+
91
+ * Add `specfile` in fixtures.
92
+
93
+ * Template methods have been improved:
94
+
95
+ * List all templates.
96
+
97
+ * Several query methods have been removed.
98
+
99
+ * Added method for list all template paths.
100
+
101
+ * All methods that build a project were removed for create a new
102
+
103
+ build class.
104
+
105
+ * Small fixes in empty values (nil).
106
+
107
+ * Documentation.
108
+
109
+ 2010-09-27
110
+ -----------
111
+
112
+ * Fixes in path to model file
113
+
114
+ * Fixes in the load of modules
115
+
116
+ * Sorting command list
117
+
118
+ * Command for list all templates
119
+
120
+ * Shared path to user templates
121
+
122
+ * Remove test index
123
+
124
+ 2010-09-26
125
+ -----------
126
+
127
+ * Added command-line interface
128
+
129
+ * Task to build Gem
130
+
131
+ 2010-09-25
132
+ -----------
133
+
134
+ * Listing all templates by namespace
135
+
136
+ * Template builds all model files
137
+
138
+ * Change SHARED_PATH to query method shared_path
139
+
140
+ 2010-09-23
141
+ -----------
142
+
143
+ * Added counter for all test names
144
+
145
+ * Template draw projects
146
+
147
+ * Updates in fixtures.
148
+
149
+ * Added binding class for filters in ERB model files.
150
+
151
+ * Documentation and changes in method names
152
+
153
+ * Fix in mapping of the models in the specfile
154
+
155
+ * Small improvements in tests
156
+
157
+ 2010-09-22
158
+ -----------
159
+
160
+ * Small fixes in source code and tests
161
+
162
+ * Fixes in converting Hash into Struct
163
+
164
+ * Fixes in tasks for tests
165
+
166
+ 2010-09-17
167
+ -----------
168
+
169
+ * Project has been remodelled
170
+
171
+ * Project renamed to Prigner.
172
+
173
+ * Start builder DSL.
174
+
175
+ * Spec class.
176
+
177
+ * Project class was simplified.
178
+
179
+ 2010-08-17
180
+ -----------
181
+
182
+ * Test for check the content written by model
183
+
184
+ * Template and models
185
+
186
+ * A template has many model files.
187
+
188
+ * The tests and fixtures for template and models have been added.
189
+
190
+ * Small improvements in code.
191
+
192
+ * Fixture for test model
193
+
194
+ * Revision in model for build contents
195
+
196
+ * The method _binding_ inside structs have been updated for public
197
+
198
+ access.
199
+
200
+ * Model only builds the content and draws a destination file.
201
+
202
+ 2010-08-16
203
+ -----------
204
+
205
+ * Fix error in parse an empty Hash to Struct
206
+
207
+ * Deleting temporary files
208
+
209
+ * Refactoring in template
210
+
211
+ * Load options from configuration file.
212
+
213
+ * The template is a simple directory tree.
214
+
215
+ * Basic model finished
216
+
217
+ * Tests and fixtures for model.
218
+
219
+ 2010-08-15
220
+ -----------
221
+
222
+ * Small improvements in code
223
+
224
+ 2010-08-14
225
+ -----------
226
+
227
+ * Basic template finished
228
+
229
+ * Tests and fixtures for templates.
230
+
231
+ * Fix in changelog task.
232
+
233
+ * Basic project finished
234
+
235
+ * Class for Ruby project is based in a simple directory path.
236
+
237
+ * Gemspec file.
238
+
239
+ * Several useful extensions.
240
+
241
+ * Tests.
242
+
243
+ * Tasks for development and publishing.
244
+
245
+ * Added basic files
246
+
247
+ * First commit
248
+
data/COPYING ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2009, 2010 Hallison Batista
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ 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 included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.mkd ADDED
@@ -0,0 +1,90 @@
1
+ Prigner
2
+ =======
3
+
4
+ Prigner is a Project Design Kit, that is, a tool which creates a conventional
5
+ structure for several projects as RubyGems, Websites, MVC application and
6
+ simple scripts. It is a DRY tool, because everything is based in templates. In
7
+ short, a project template engine.
8
+
9
+ Features
10
+ ========
11
+
12
+ * Load and create all directories and files from templates.
13
+ * Default Ruby project templates.
14
+ * Ruby Gem.
15
+ * A simple project using setup.
16
+ * Script file with or without directory structure.
17
+ * Add common tasks and libraries.
18
+ * Tests.
19
+ * Deploy.
20
+ * Code for versioning.
21
+
22
+ Installation
23
+ ============
24
+
25
+ First, install Prigner stable through Gem:
26
+
27
+ gem install prigner
28
+
29
+ Usage
30
+ =====
31
+
32
+ Prigner create the most common Ruby projects through templates shared. To
33
+ generate new Gem project, run command using the following syntax:
34
+
35
+ prign new ruby:gem foo
36
+
37
+ foo
38
+ |-- CHANGELOG
39
+ |-- COPYRIGHT
40
+ |-- README.mkd
41
+ |-- Rakefile
42
+ |-- bin
43
+ | `-- foo
44
+ |-- foo.gemspec
45
+ |-- lib
46
+ | |-- foo
47
+ | `-- foo.rb
48
+ `-- test
49
+ |-- fixtures
50
+ |-- foo_test.rb
51
+ `-- helper.rb
52
+
53
+ This command will generate 'foo' Gem project structure. Or, you maybe create a
54
+ Ruby script or a UNIX-like program.
55
+
56
+ prign new bash:script bar
57
+
58
+ bar
59
+ |-- bar
60
+ `-- barrc
61
+
62
+ prign new bash:program ducklet
63
+
64
+ ducklet
65
+ |-- bin
66
+ | `-- ducklet
67
+ `-- etc
68
+ `-- duckletrc
69
+
70
+ Templates
71
+ =========
72
+
73
+ Prigner offer the following templates:
74
+
75
+ * Ruby
76
+ * Default project based only library directory and common files as
77
+ README.rdoc, CHANGELOG
78
+ * Gem project that include library directory, main module, test and
79
+ directories for fixtures.
80
+ * Sinatra basic application.
81
+
82
+ Copyright
83
+ =========
84
+
85
+ Written by [Hallison Batista](http://hallisonbatista.com/whoiam).
86
+
87
+ Prigner is Copyright (C) 2010, [Codigorama](http://codigorama.com/products).
88
+
89
+ See COPYRIGHT file for more information about license.
90
+
data/Rakefile ADDED
@@ -0,0 +1,211 @@
1
+ require "rake/clean"
2
+ require "lib/prigner"
3
+
4
+ # Helpers
5
+ # =============================================================================
6
+
7
+ def rdoc(*args)
8
+ @rdoc ||= if Gem.available? "hanna"
9
+ ["hanna", "--fmt", "html", "--accessor", "option_accessor=RW", *args]
10
+ else
11
+ ["rdoc", *args]
12
+ end
13
+ sh @rdoc.join(" ")
14
+ end
15
+
16
+ def test(pattern)
17
+ testfiles = Dir[pattern]
18
+ if Gem.available? "turn"
19
+ sh [ "turn", *testfiles ].join(" ")
20
+ else
21
+ testfiles.each do |testfile|
22
+ sh "ruby #{testfile}"
23
+ end
24
+ end
25
+ end
26
+
27
+ def manifest
28
+ @manifest ||= `git ls-files`.split("\n").sort.reject do |out|
29
+ out =~ /^\./ || out =~ /^doc/
30
+ end.map do |file|
31
+ " #{file.inspect}"
32
+ end.join(",\n")
33
+ end
34
+
35
+ def log
36
+ @log ||= `git log --date=short --format='%d;%cd;%s;%b;'`
37
+ end
38
+
39
+ def version
40
+ @version ||= Prigner.version
41
+ end
42
+
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
48
+ end
49
+
50
+ # Documentation
51
+ # =============================================================================
52
+
53
+ namespace :doc do
54
+
55
+ CLOBBER << FileList["doc/*"]
56
+
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"
71
+
72
+ desc "Creates/updates CHANGELOG file."
73
+ task :changelog do |spec|
74
+ historic = {}
75
+ text = ""
76
+
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
83
+
84
+ historic[date][:changes] << "\n* #{subject}\n"
85
+ historic[date][:changes] << content.gsub(/(.*?)\n/m){"\n #{$1}\n"} unless content.empty?
86
+ end
87
+
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
96
+ end
97
+
98
+ File.open("CHANGELOG", "w+") { |changelog| changelog << text }
99
+ puts "Historic has #{historic.keys.size} entry dates"
100
+ puts "Successfully updated CHANGELOG file"
101
+ end
102
+
103
+ end
104
+
105
+ # Versioning
106
+ # =============================================================================
107
+
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
125
+
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
+ end
132
+
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
139
+
140
+ desc "Update version date (current #{version.date})"
141
+ task :date, [:date] do |spec, args|
142
+ require "parsedate"
143
+ require "date"
144
+ yyyy, mm, dd = ParseDate.parsedate(args[:date]).compact if args[:date]
145
+ version.date = (yyyy && mm && dd) ? Date.new(yyyy, mm, dd) : Date.today
146
+ version.save!
147
+ puts version.to_hash.to_yaml
148
+ end
149
+ end
150
+
151
+ task :version => "version:build"
152
+
153
+ # RubyGems
154
+ # =============================================================================
155
+
156
+ namespace :gem do
157
+
158
+ file gemspec.file => FileList["{lib,test}/**", "Rakefile"] do
159
+ spec = gemspec.file.read
160
+
161
+ puts "Updating version ..."
162
+ spec.sub! /spec\.version\s*=\s*".*?"/, "spec.version = #{version.tag.inspect}"
163
+
164
+ puts "Updating date of version ..."
165
+ spec.sub! /spec\.date\s*=\s*".*?"/, "spec.date = #{version.date.to_s.inspect}"
166
+
167
+ puts "Updating file list ..."
168
+ spec.sub! /spec\.files\s*=\s*\[.*?\]/m, "spec.files = [\n#{manifest}\n ]"
169
+
170
+ gemspec.file.open("w+") { |file| file << spec }
171
+
172
+ puts "Successfully update #{gemspec.file} file"
173
+ end
174
+
175
+ desc "Build gem package #{gemspec.spec.file_name}"
176
+ task :build => gemspec.file do
177
+ sh "gem build #{gemspec.file}"
178
+ end
179
+
180
+ desc "Deploy gem package to RubyGems.org"
181
+ task :deploy => :build do
182
+ sh "gem push #{gemspec.spec.file_name}"
183
+ end
184
+
185
+ desc "Install gem package #{gemspec.spec.file_name}"
186
+ task :install => :build do
187
+ sh "gem install #{gemspec.spec.file_name} --local"
188
+ end
189
+
190
+ desc "Uninstall gem package #{gemspec.spec.file_name}"
191
+ task :uninstall do
192
+ sh "gem uninstall #{gemspec.spec.name} --version #{gemspec.spec.version}"
193
+ end
194
+
195
+ end
196
+
197
+ task :gem => "gem:build"
198
+
199
+ # Test
200
+ # =============================================================================
201
+
202
+ desc "Run tests"
203
+ task :test, [:pattern] do |spec, args|
204
+ test(args[:pattern] ? "test/#{args[:pattern]}_test.rb" : "test/*_test.rb")
205
+ end
206
+
207
+ # Default
208
+ # =============================================================================
209
+
210
+ task :default => "test"
211
+
data/bin/prign ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (C) 2010 Hallison Batista
3
+ # encoding: UTF-8
4
+
5
+ require "prigner"
6
+
7
+ program = File.basename(__FILE__)
8
+
9
+ begin
10
+ Prigner::CLI.run *ARGV unless ARGV.empty? or ARGV.first =~ /^-.*$/
11
+
12
+ ARGV.options do |arguments|
13
+
14
+ arguments.summary_indent = " "
15
+ arguments.summary_width = 24
16
+ arguments.banner = <<-end_banner.gsub(/^[ ]{6}/, '')
17
+ #{Prigner::Version}
18
+
19
+ Usage:
20
+ #{program} <namespace>[:template] [path] [options]
21
+ #{program} <command> [command_options]
22
+ #{program} [options]
23
+
24
+ Commands:
25
+ #{Prigner::CLI.commands.join(", ")}
26
+
27
+ Run command with option "-h" or "--help" for more information.
28
+
29
+ end_banner
30
+
31
+ arguments.separator "Options:"
32
+
33
+ arguments.on("-c", "--commands", nil, "Show only command names.") do
34
+ puts Prigner::CLI.commands.join("\n")
35
+ end
36
+
37
+ arguments.on("-t", "--templates", nil, "Show only template names.") do
38
+ puts Prigner::CLI.templates.sort.join("\n")
39
+ end
40
+
41
+ arguments.on("-h", "--help", nil, "Show this message.") do
42
+ puts arguments
43
+ end
44
+
45
+ arguments.on("-v", "--version", nil, "Show version information.") do
46
+ puts Prigner::Version
47
+ end
48
+
49
+ arguments.separator ""
50
+
51
+ unless ARGV.empty?
52
+ arguments.parse!
53
+ else
54
+ puts arguments
55
+ exit 0
56
+ end
57
+ end
58
+
59
+ rescue => error
60
+ puts "#{program}: #{error.message} (#{error.class})"
61
+ puts "Try '#{program} -h' or '#{program} --help' for more information."
62
+ exit 1
63
+ end
64
+
65
+ # vim: filetype=ruby
@@ -0,0 +1,51 @@
1
+ # == The project builder
2
+ #
3
+ # The Builder class is a main handler of the projects and templates.
4
+ class Prigner::Builder
5
+
6
+ require "fileutils"
7
+
8
+ include FileUtils
9
+
10
+ attr_reader :project
11
+
12
+ attr_reader :template
13
+
14
+ # Build a new project based on a template.
15
+ def initialize(project, template)
16
+ @project, @template = project, template
17
+ end
18
+
19
+ def make_project_path #:yields: path, info
20
+ mkdir_p(@project.path)
21
+ { no_pwd(@project.path) => File.stat(@project.path) }
22
+ end
23
+
24
+ def make_project_directories #:yields: path, info
25
+ @template.directories.inject({}) do |hash, basedir|
26
+ directory = basedir.gsub(/\((.*?)\)/){ @project.send($1) }
27
+ path = File.join(@project.path, directory)
28
+ mkdir_p(path)
29
+ hash[no_pwd(path)] = File.stat(path)
30
+ hash
31
+ end
32
+ end
33
+
34
+ def make_project_files #:yields: path, info
35
+ @template.models.inject({}) do |hash, (model, basename)|
36
+ file = basename.gsub(/\((.*?)\)/){ project.send($1) }
37
+ path = File.join(@project.path, file)
38
+ model.binder = Prigner::Binder.new(@project, @template.options)
39
+ model.write(path)
40
+ hash[no_pwd(model.file_written)] = File.stat(model.file_written)
41
+ hash
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def no_pwd(path)
48
+ path.gsub("#{Dir.pwd}/", "")
49
+ end
50
+ end
51
+
File without changes