boilerplater 0.1 → 0.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/bp +25 -29
- data/lib/boilerplater.rb +1 -0
- data/lib/cmd.rb +93 -0
- data/lib/parser.rb +9 -1
- metadata +51 -34
data/bin/bp
CHANGED
@@ -1,43 +1,39 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
require '
|
4
|
+
require 'trollop'
|
5
5
|
|
6
6
|
$:.unshift File::expand_path(File.join(File.dirname(__FILE__), '..'))
|
7
7
|
|
8
8
|
require 'lib/boilerplater.rb'
|
9
|
+
require 'lib/cmd.rb'
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
optparse = OptionParser.new do |opts|
|
13
|
-
opts.on( '-s', '--search BOILERPLATE', 'Search for specific boilerplate') do |keyword|
|
14
|
-
puts BoilerPlater.search keyword
|
15
|
-
exit 0
|
16
|
-
end
|
17
|
-
opts.on '-u', '--use ID', 'Download and install specific boilerplate' do |id|
|
18
|
-
options[:id] = id
|
19
|
-
end
|
20
|
-
opts.on '-p', '--prefix PREFIX', 'Use prefix for installation' do |prefix|
|
21
|
-
options[:prefix] = prefix
|
22
|
-
end
|
23
|
-
opts.on('-h', '--help') { options[:help] = true }
|
11
|
+
opts = Trollop::options do
|
12
|
+
opt :prefix, "Prefix for boilerplate files", :short => 'p', :default => '.'
|
24
13
|
end
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
if ARGV[0].nil?
|
16
|
+
puts 'Usage: bp command [id|alias|action] [options]'
|
17
|
+
puts
|
18
|
+
puts "Commands:\n\n"
|
19
|
+
puts ' bp list - List all boilerplates'
|
20
|
+
puts ' bp search [name] - Search for boilerplate'
|
21
|
+
puts ' bp show [id|alias] - Show boilerplate details'
|
22
|
+
puts ' bp use [id|alias] - Apply boilerplate'
|
23
|
+
puts ' bp alias create [id] [name] - Create alias for boilerplate'
|
24
|
+
puts ' bp alias delete [name] - Delete alias'
|
25
|
+
puts ' bp alias list - List all aliases'
|
26
|
+
puts
|
27
|
+
system("#{__FILE__} --help")
|
31
28
|
end
|
32
29
|
|
33
|
-
|
34
|
-
b.prefix = options[:prefix] || '.'
|
35
|
-
end
|
30
|
+
exit(0) if opts[:help]
|
36
31
|
|
37
|
-
|
38
|
-
BoilerPlater.
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
puts case ARGV[0]
|
33
|
+
when 'list' then BoilerPlater::Cmd.list
|
34
|
+
when 'search' then BoilerPlater::Cmd.search(ARGV[1])
|
35
|
+
when 'show' then BoilerPlater::Cmd.show(ARGV[1])
|
36
|
+
when 'use' then BoilerPlater::Cmd.use(ARGV[1], opts)
|
37
|
+
when 'alias' then BoilerPlater::Cmd.alias(ARGV[1], ARGV[2], ARGV[3])
|
38
|
+
else ''
|
42
39
|
end
|
43
|
-
|
data/lib/boilerplater.rb
CHANGED
data/lib/cmd.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class String
|
4
|
+
# colorization
|
5
|
+
def colorize(text, color_code)
|
6
|
+
"\e[#{color_code}m#{text}\e[0m"
|
7
|
+
end
|
8
|
+
|
9
|
+
def red; colorize(self, 31); end
|
10
|
+
def green; colorize(self, 32); end
|
11
|
+
def yellow; colorize(self, 33); end
|
12
|
+
def pink; colorize(self, 35); end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
module BoilerPlater
|
17
|
+
|
18
|
+
module Cmd
|
19
|
+
|
20
|
+
def self.search(keyword)
|
21
|
+
BoilerPlater.search(keyword)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.list
|
25
|
+
BoilerPlater.list.map { |k, v| "#{v}: #{k}" }.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.show(id)
|
29
|
+
data = BoilerPlater.show(find_alias(id))
|
30
|
+
"\nDescription: #{data['description']}\n" +
|
31
|
+
"Author: #{data['user']['login']}\n" +
|
32
|
+
"URL: #{data['url']}\n" +
|
33
|
+
"\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.use(id, opts)
|
37
|
+
BoilerPlater.setup do |bp|
|
38
|
+
bp.prefix = opts[:prefix]
|
39
|
+
end
|
40
|
+
id = find_alias(id)
|
41
|
+
puts
|
42
|
+
puts "Setting up new project using %s\n\n" % BoilerPlater.show(id)['description']
|
43
|
+
BoilerPlater.sections(BoilerPlater.get(id)).each do |part|
|
44
|
+
puts ' [%-8s] %s' % [(part.content? ? 'create '.green : 'download'.yellow), part.path]
|
45
|
+
part.download_content! unless part.content?
|
46
|
+
if part.exists?
|
47
|
+
print ' File already exists, overwrite? [y,N]: '
|
48
|
+
part.save! if STDIN.gets.chop.strip == 'Y'
|
49
|
+
else
|
50
|
+
part.save!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
"\ndone.\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.alias(action, gist_id, name)
|
57
|
+
result = case action
|
58
|
+
when 'create' then alias_create(gist_id, name)
|
59
|
+
when 'delete' then alias_delete(name=gist_id)
|
60
|
+
when 'list' then return aliases.map { |gist, n| "#{n}: #{gist}" }.join("\n")
|
61
|
+
end
|
62
|
+
"Alias '#{name}' was #{!result ? 'not' : ''}#{action}d."
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.alias_create(gist_id, name)
|
66
|
+
return if find_alias(name) == gist_id
|
67
|
+
update_aliases(aliases << [gist_id, name])
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.find_alias(name)
|
71
|
+
res = aliases.find { |k, v| v == name.strip }
|
72
|
+
res ? res.first : name
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.alias_delete(name)
|
76
|
+
update_aliases(aliases.delete_if { |k, v| v == name })
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.aliases
|
80
|
+
File.exists?(alias_file) ? YAML::load_file(alias_file) : []
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.alias_file
|
84
|
+
File.join(ENV['HOME'], '.bp_aliases.yaml')
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.update_aliases(arr)
|
88
|
+
File.open(alias_file, 'w') { |f| YAML::dump(arr, f) }
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/parser.rb
CHANGED
@@ -14,6 +14,10 @@ module BoilerPlater
|
|
14
14
|
Gist.read(gist_id)
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.show(gist_id)
|
18
|
+
JSON.parse(open(Gist::GIST_URL % gist_id).read)
|
19
|
+
end
|
20
|
+
|
17
21
|
def self.use(gist_id)
|
18
22
|
BoilerPlater.sections(get(gist_id)).each do |f|
|
19
23
|
f.download_content! unless f.content?
|
@@ -26,7 +30,7 @@ module BoilerPlater
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def self.search(name)
|
29
|
-
list.find { |k, v| v =~ /#{name}/ }.
|
33
|
+
list.find { |k, v| v =~ /#{name}/ }.join(' | ')
|
30
34
|
end
|
31
35
|
|
32
36
|
def self.sections(content)
|
@@ -81,6 +85,10 @@ module BoilerPlater
|
|
81
85
|
File.join(BoilerPlater.config.prefix || '.', File.dirname(@file), File.basename(@file))
|
82
86
|
end
|
83
87
|
|
88
|
+
def exists?
|
89
|
+
File.exists? path
|
90
|
+
end
|
91
|
+
|
84
92
|
def download_content!
|
85
93
|
@content = open(metadata[:url]).read
|
86
94
|
end
|
metadata
CHANGED
@@ -1,66 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: boilerplater
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Michal Fojtik
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2012-08-06 00:00:00 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
15
20
|
name: gist
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
30
33
|
description: Speed up your development using prepared boiler plate templates
|
31
|
-
email:
|
34
|
+
email:
|
32
35
|
- mi@mifo.sk
|
33
|
-
executables:
|
36
|
+
executables:
|
34
37
|
- bp
|
35
38
|
extensions: []
|
39
|
+
|
36
40
|
extra_rdoc_files: []
|
37
|
-
|
41
|
+
|
42
|
+
files:
|
38
43
|
- bin/bp
|
39
44
|
- lib/boilerplater.rb
|
45
|
+
- lib/cmd.rb
|
40
46
|
- lib/parser.rb
|
41
47
|
homepage: http://github.com/mifo/boilerplater
|
42
|
-
licenses:
|
48
|
+
licenses:
|
43
49
|
- MIT
|
44
50
|
post_install_message:
|
45
51
|
rdoc_options: []
|
46
|
-
|
52
|
+
|
53
|
+
require_paths:
|
47
54
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
56
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
65
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 23
|
70
|
+
segments:
|
71
|
+
- 1
|
72
|
+
- 3
|
73
|
+
- 6
|
59
74
|
version: 1.3.6
|
60
75
|
requirements: []
|
76
|
+
|
61
77
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.8.
|
78
|
+
rubygems_version: 1.8.15
|
63
79
|
signing_key:
|
64
80
|
specification_version: 3
|
65
81
|
summary: Simple boiler plate system to bootstrap dev of new applications
|
66
82
|
test_files: []
|
83
|
+
|