piv 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Mark Ryall
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a 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
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ = piv
2
+
3
+ a simple and extensible command line file generator
4
+
5
+ == rationale
6
+
7
+ * command line tools are almost always faster than any gui or web interface
8
+ * the idea of using a code generator to generate as much of itself as possible is appealing
9
+
10
+ == installation
11
+
12
+ at this stage, you need to clone the repository and put the bin directory on the path. i'll turn this into a gem as soon as piv can generate a gemspec.
13
+
14
+ == usage
15
+
16
+ piv ruby foo
17
+
18
+ this will create a foo ruby project together with the standard folders and files that i'd usually create for a ruby project
19
+
20
+ == ruby flavour
21
+
22
+ once you've generated a ruby project you can use various generators
23
+
24
+ piv class foo bar baz
25
+
26
+ this will create a Foo::Bar::Baz class, an associated spec and open both in a text editor (hardcoded to sublime text 2 at the moment)
27
+
28
+ piv module foo bar baz
29
+
30
+ this will create a module instead of a class and a spec and open both in a text editor
31
+
32
+ piv destroy foo bar baz
33
+
34
+ this will destroy Foo::Bar::Baz (and any associated files)
35
+
36
+ == future plans
37
+
38
+ * add gem related commands for ruby flavour
39
+ * add other flavours (clojure? python? make up a whole new language?)
40
+ * editor should be configurable
41
+ * write some damn specs
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'gemesis/rake'
3
+ rescue Exception
4
+ puts "gemesis related tasks will only be available if you 'gem install gemesis'"
5
+ end
6
+
7
+ desc 'execute specifications'
8
+ task :test do
9
+ sh 'rspec spec'
10
+ end
data/bin/piv ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ $: << File.dirname(__FILE__)+'/../lib'
4
+
5
+ require 'yaml'
6
+
7
+ unless File.exist? '.piv'
8
+ require 'piv'
9
+ include Piv
10
+ generate_project ARGV.shift, ARGV.shift
11
+ end
12
+
13
+ config = YAML.load_file '.piv'
14
+ require 'piv/'+config['flavour']
15
+ include Piv.const_get config['flavour'].classify
16
+
17
+ generator = ARGV.shift
18
+ method_name = "generate_#{generator}"
19
+ unless respond_to? method_name
20
+ puts "Unknown generator #{generator}"
21
+ exit 1
22
+ end
23
+ self.send method_name, *ARGV
@@ -0,0 +1,58 @@
1
+ require 'fileutils'
2
+
3
+ module Piv
4
+ require 'piv/monkey_patching'
5
+
6
+ include FileUtils
7
+
8
+ def generate_project flavour, name
9
+ directory name do |dir|
10
+ dir.file '.gitignore'
11
+ dir.file '.piv', {'flavour' => flavour}.to_yaml
12
+ system 'git init' unless File.exist? '.git'
13
+ require 'piv/'+flavour
14
+ extend Piv.const_get flavour.classify
15
+ generate_init if respond_to? :generate_init
16
+ end
17
+ end
18
+
19
+ def directory path
20
+ full_path = File.join path
21
+ mkdir_p File.join full_path
22
+ Dir.chdir full_path do
23
+ yield self if block_given?
24
+ end
25
+ end
26
+
27
+ def file path, content=''
28
+ File.open path, 'w' do |f|
29
+ f.puts content
30
+ end unless File.exist? path
31
+ system "subl #{path}"
32
+ end
33
+
34
+ def license
35
+ <<EOF
36
+ Copyright (c) #{Date.today.year} YOUR NAME
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ "Software"), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
52
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
53
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
54
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
55
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56
+ EOF
57
+ end
58
+ end
@@ -0,0 +1,11 @@
1
+ class String
2
+ def classify
3
+ self.split('_').map(&:capitalize).join
4
+ end
5
+ end
6
+
7
+ class Array
8
+ def classify
9
+ self.map.map(&:classify).join('::')
10
+ end
11
+ end
@@ -0,0 +1,69 @@
1
+ require 'piv'
2
+
3
+ module Piv::Ruby
4
+ include Piv
5
+
6
+ def generate_init *ignored
7
+ directory 'lib'
8
+ directory 'spec'
9
+ file '.gemtest'
10
+ file 'Rakefile'
11
+ file 'Gemfile'
12
+ file 'README.rdoc'
13
+ file 'HISTORY.rdoc'
14
+ file 'MIT-LICENSE', license
15
+ end
16
+
17
+ def generate_destroy *names
18
+ rm "lib/#{names.join '/'}.rb"
19
+ rm "spec/#{names.join '/'}_spec.rb"
20
+ end
21
+
22
+ def generate_class *names
23
+ generate_ruby 'class', names
24
+ end
25
+
26
+ def generate_module *names
27
+ generate_ruby 'module', names
28
+ end
29
+
30
+ def generate_gem name
31
+ file 'gemspec', %{
32
+ Gem::Specification.new do |spec|
33
+ spec.name = '#{name}'
34
+ spec.version = '0.0.1'
35
+ spec.summary = 'SUMMARY'
36
+ spec.description = <<-EOF
37
+ DESCRIPTION
38
+ EOF
39
+ spec.authors << 'YOUR NAME'
40
+ spec.email = 'YOUR EMAIL'
41
+ spec.homepage = 'http://HOMEPAGE'
42
+ spec.files = Dir['lib/**/*'] + Dir['spec/**/*'] + Dir['bin/*'] + ['README.rdoc', 'MIT-LICENSE', 'HISTORY.rdoc', 'Rakefile', '.gemtest']
43
+ spec.executables << 'EXECUTABLE'
44
+
45
+ spec.add_development_dependency 'rake', '~>0.8'
46
+ spec.add_development_dependency 'gemesis', '~>0'
47
+ spec.add_development_dependency 'rspec', '~>2'
48
+ end
49
+ }
50
+
51
+ end
52
+ private
53
+ def generate_ruby thing, names
54
+ name, dirs = names.last, names.slice(0...-1)
55
+ directory ['lib', *dirs] do |dir|
56
+ dir.file "#{name}.rb", <<EOF
57
+ #{thing} #{names.classify}
58
+ end
59
+ EOF
60
+ end
61
+ directory ['spec', *dirs] do |dir|
62
+ dir.file "#{name}_spec.rb", <<EOF
63
+ describe #{names.classify}
64
+ it 'should ...'
65
+ end
66
+ EOF
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ describe Piv::MonkeyPatching
2
+ it 'should ...'
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Piv::Ruby
2
+ it 'should ...'
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Piv
2
+ it 'should ...'
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: piv
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Mark Ryall
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-13 00:00:00 +10:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "0.8"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: gemesis
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: "2"
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: |
50
+ a simple and extensible command line file generator
51
+
52
+ email: mark@ryall.name
53
+ executables:
54
+ - piv
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - lib/piv/monkey_patching.rb
61
+ - lib/piv/ruby.rb
62
+ - lib/piv.rb
63
+ - spec/piv/monkey_patching_spec.rb
64
+ - spec/piv/ruby_spec.rb
65
+ - spec/piv_spec.rb
66
+ - bin/piv
67
+ - README.rdoc
68
+ - MIT-LICENSE
69
+ - HISTORY.rdoc
70
+ - Rakefile
71
+ - .gemtest
72
+ has_rdoc: true
73
+ homepage: https://github.com/markryall/piv
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.5.2
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: the ultimate command line productivity tool
100
+ test_files: []
101
+