quik 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,34 +1,33 @@
1
- require 'hoe'
2
- require './lib/quik/version.rb'
3
-
4
- Hoe.spec 'quik' do
5
-
6
- self.version = Quik::VERSION
7
-
8
- self.summary = 'quik - ruby quick starter template script wizard .:. the missing code generator'
9
- self.description = summary
10
-
11
- self.urls = ['https://github.com/rubylibs/quik']
12
-
13
- self.author = 'Gerald Bauer'
14
- self.email = 'ruby-talk@ruby-lang.org'
15
-
16
- # switch extension to .markdown for gihub formatting
17
- self.readme_file = 'README.md'
18
- self.history_file = 'HISTORY.md'
19
-
20
- self.extra_deps = [
21
- ['logutils'],
22
- ['textutils'],
23
- ['fetcher'],
24
- ['rubyzip'],
25
- ['gli'],
26
- ]
27
-
28
- self.licenses = ['Public Domain']
29
-
30
- self.spec_extras = {
31
- required_ruby_version: '>= 1.9.2'
32
- }
33
-
34
- end
1
+ require 'hoe'
2
+ require './lib/quik/version.rb'
3
+
4
+ Hoe.spec 'quik' do
5
+
6
+ self.version = Quik::VERSION
7
+
8
+ self.summary = 'qk/quik - ruby quick starter template script wizard .:. the missing code generator'
9
+ self.description = summary
10
+
11
+ self.urls = { home: 'https://github.com/quikstart/quik' }
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'ruby-talk@ruby-lang.org'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.extra_deps = [
21
+ ['logutils'],
22
+ ['fetcher'],
23
+ ['rubyzip'],
24
+ ['gli'],
25
+ ]
26
+
27
+ self.licenses = ['Public Domain']
28
+
29
+ self.spec_extras = {
30
+ required_ruby_version: '>= 2.2.2'
31
+ }
32
+
33
+ end
data/bin/qk CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'quik'
4
-
5
- Quik.main
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'quik'
4
+
5
+ Quik.main
data/bin/quik CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'quik'
4
-
5
- Quik.main
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'quik'
4
+
5
+ Quik.main
@@ -1,44 +1,55 @@
1
- # encoding: utf-8
2
-
3
- # stdlibs
4
- require 'pp'
5
- require 'fileutils'
6
- require 'yaml'
7
- require 'uri'
8
-
9
- # 3rd party libs/gems
10
- require 'fetcher'
11
- require 'textutils' ## used for File.read_utf8
12
-
13
- ## more 3rd party gems
14
- require 'zip' # use $ gem install rubyzip
15
- require 'gli'
16
-
17
-
18
- # our own code
19
- require 'quik/version' # let version always go first
20
- require 'quik/catalog'
21
- require 'quik/package'
22
- require 'quik/merger'
23
- require 'quik/config'
24
- require 'quik/wizard'
25
- require 'quik/builder'
26
- require 'quik/colors'
27
-
28
-
29
- require 'quik/cli/opts'
30
- require 'quik/cli/main'
31
-
32
-
33
- module Quik
34
- def self.main
35
- exit Tool.new.run( ARGV )
36
- end
37
- end # module Quik
38
-
39
-
40
- ## say hello
41
- puts Quik.banner if defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG
42
-
43
-
44
- Quik.main if __FILE__ == $0
1
+ # encoding: utf-8
2
+
3
+ # stdlibs
4
+ require 'pp'
5
+ require 'fileutils'
6
+ require 'yaml'
7
+ require 'json'
8
+ require 'uri'
9
+ require 'time'
10
+ require 'date'
11
+
12
+
13
+ # 3rd party libs/gems
14
+ require 'fetcher'
15
+
16
+ ## more 3rd party gems
17
+ require 'zip' # use $ gem install rubyzip
18
+ require 'gli'
19
+
20
+
21
+ # our own code
22
+ require 'quik/version' # let version always go first
23
+
24
+
25
+ module Quik
26
+ ### builtin default urls
27
+ QUIK_SCRIPTS_URL = "https://github.com/quikstart/scripts/raw/master/scripts.yml"
28
+ end
29
+
30
+
31
+
32
+ require 'quik/catalog'
33
+ require 'quik/package'
34
+ require 'quik/merger'
35
+ require 'quik/config'
36
+ require 'quik/wizard'
37
+ require 'quik/builder'
38
+ require 'quik/colors'
39
+
40
+
41
+ require 'quik/cli/opts'
42
+ require 'quik/cli/main'
43
+
44
+
45
+ module Quik
46
+ def self.main( args=ARGV )
47
+ exit Tool.new.run( args )
48
+ end
49
+ end # module Quik
50
+
51
+
52
+
53
+
54
+ ## say hello
55
+ puts Quik.banner if defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG
@@ -1,96 +1,96 @@
1
- #encoding: utf-8
2
-
3
- module Quik
4
-
5
- class Builder
6
-
7
- def self.load_file( path, opts={} )
8
- code = File.read_utf8( path )
9
- self.load( code, opts )
10
- end
11
-
12
- def self.load( code, opts={} )
13
- builder = Builder.new( opts )
14
- builder.instance_eval( code )
15
- builder
16
- end
17
-
18
-
19
- include Wizard ## mixin helpers for say, ask, yes?, no?, select, etc.
20
-
21
- def initialize( opts={} )
22
- puts "starting new Quik script #{opts.inspect}; lets go"
23
-
24
- @test = opts[:dry_run] || opts[:test] || false
25
- @output_dir = opts[:o] || '.'
26
- @pak = nil ## for now reference last template pack (in future support many - why?? why not??)
27
- end
28
-
29
- ## "global" builder options
30
- def test?() @test; end ## dry_run option (defaults to false)
31
- def output_dir() @output_dir; end ## ouptput (root) dir (defaults to . e.g. working folder)
32
-
33
-
34
-
35
- def use( name, opts={} ) ## short alias for install_template
36
- install_template( name, opts )
37
- end
38
-
39
- def install_template( name, opts= {} )
40
- puts " handle install_template #{name}, #{opts.inspect}"
41
-
42
- ## note for now assume name is key
43
- ## e.g. always downcase (e.g. Gem => gem)
44
- key = name.downcase
45
-
46
- if test?
47
- # do nothing; dry run
48
- else
49
- @pak = Package.new( key )
50
-
51
- puts "GET #{@pak.remote_zip_url}".bold.green ## output network access in green bold
52
- @pak.download
53
- ## pak.unzip( "#{@output_dir}/#{key}" )
54
- end
55
- end
56
-
57
-
58
- def config( opts={} )
59
- puts " handle config block"
60
- c = OpenConfig.new
61
- yield( c )
62
- ## pp c
63
- h = c.to_h
64
-
65
- pp h
66
-
67
- ##
68
- # check for name
69
- ## required for output
70
- ## if no name
71
- ## use ./ working folder for output!!!
72
-
73
- name = h['name']
74
-
75
- if name.nil? || name.empty?
76
- fail 'sorry; for now name is required for output folder'
77
- end
78
-
79
- if test?
80
- ## do nothing; dry run
81
- else
82
- if @pak
83
- unzip_dir = "./#{name}"
84
- ## step 1: unzip templates
85
- @pak.unzip( unzip_dir )
86
- ## step 2: merge templates (using hash/config settings)
87
- m = Quik::Merger.new
88
- m.merge( unzip_dir, h )
89
- end
90
- end
91
- end # method config
92
-
93
-
94
- end # class Builder
95
-
96
- end # module Quik
1
+ #encoding: utf-8
2
+
3
+ module Quik
4
+
5
+ class Builder
6
+
7
+ def self.load_file( path, opts={} )
8
+ code = File.open( path, 'r:utf-8' ) { |f| f.read }
9
+ self.load( code, opts )
10
+ end
11
+
12
+ def self.load( code, opts={} )
13
+ builder = Builder.new( opts )
14
+ builder.instance_eval( code )
15
+ builder
16
+ end
17
+
18
+
19
+ include Wizard ## mixin helpers for say, ask, yes?, no?, select, etc.
20
+
21
+ def initialize( opts={} )
22
+ puts "==> starting new Quik script with options #{opts.inspect}; lets go"
23
+
24
+ @test = opts[:dry_run] || opts[:test] || false
25
+ @output_dir = opts[:o] || '.'
26
+ @pak = nil ## for now reference last template pack (in future support many - why?? why not??)
27
+ end
28
+
29
+ ## "global" builder options
30
+ def test?() @test; end ## dry_run option (defaults to false)
31
+ def output_dir() @output_dir; end ## ouptput (root) dir (defaults to . e.g. working folder)
32
+
33
+
34
+
35
+ def use( name, opts={} ) ## short alias for install_template
36
+ install_template( name, opts )
37
+ end
38
+
39
+ def install_template( name, opts= {} )
40
+ puts "==> handle install_template >#{name}< with options #{opts.inspect}"
41
+
42
+ ## note for now assume name is key
43
+ ## e.g. always downcase (e.g. Gem => gem)
44
+ key = name.downcase
45
+
46
+ if test?
47
+ # do nothing; dry run
48
+ else
49
+ @pak = Package.new( key )
50
+
51
+ puts "GET #{@pak.remote_zip_url}".bold.green ## output network access in green bold
52
+ @pak.download
53
+ ## pak.unzip( "#{@output_dir}/#{key}" )
54
+ end
55
+ end
56
+
57
+
58
+ def config( opts={} )
59
+ puts "==> handle config block"
60
+ c = OpenConfig.new
61
+ yield( c )
62
+ ## pp c
63
+ h = c.to_h
64
+
65
+ pp h
66
+
67
+ ##
68
+ # check for name
69
+ ## required for output
70
+ ## if no name
71
+ ## use ./ working folder for output!!!
72
+
73
+ name = h['name']
74
+
75
+ if name.nil? || name.empty?
76
+ fail 'sorry; for now name is required for output folder'
77
+ end
78
+
79
+ if test?
80
+ ## do nothing; dry run
81
+ else
82
+ if @pak
83
+ unzip_dir = "./#{name}"
84
+ ## step 1: unzip templates
85
+ @pak.unzip( unzip_dir )
86
+ ## step 2: merge templates (using hash/config settings)
87
+ m = Quik::Merger.new
88
+ m.merge( unzip_dir, h )
89
+ end
90
+ end
91
+ end # method config
92
+
93
+
94
+ end # class Builder
95
+
96
+ end # module Quik
@@ -1,56 +1,73 @@
1
- # encoding: utf-8
2
-
3
- module Quik
4
-
5
- class Catalog
6
-
7
- def self.from_url( src )
8
- worker = Fetcher::Worker.new
9
- text = worker.read_utf8!( src )
10
- self.from_string( text )
11
- end
12
-
13
- def self.from_file( path )
14
- ## read in themes catalog
15
- text = File.read( path ) ## fix: use File.read_utf8 ??
16
- self.from_string( text )
17
- end
18
-
19
- def self.from_string( text )
20
- self.new( text )
21
- end
22
-
23
-
24
- def initialize( text )
25
- @scripts = YAML.load( text )
26
- end
27
-
28
- def list( filter=nil )
29
- ## pp filter
30
-
31
- @scripts.each_with_index do |h,i|
32
- name = h['name']
33
- summary = h['summary']
34
-
35
- line = ''
36
- line << " %3d" % (i+1)
37
- line << "..%-10s" % name
38
- line << " .:. #{summary}"
39
-
40
- if filter
41
- ## note: ignore case (upper/lower/downcase) for now
42
- ## filter on name/title and
43
- ## tags for now
44
- if name.downcase.index(filter.downcase) != nil || ## note: 0 is match found on index 0; only nil is not found
45
- summary.downcase.index(filter.downcase) != nil
46
- puts line
47
- end
48
- else
49
- puts line
50
- end
51
- end
52
- end # method filter
53
-
54
- end # class Catalog
55
-
56
- end # module Quik
1
+ # encoding: utf-8
2
+
3
+ module Quik
4
+
5
+ class Catalog
6
+
7
+ def self.from_url( src )
8
+ worker = Fetcher::Worker.new
9
+ text = worker.read_utf8!( src )
10
+ new( text )
11
+ end
12
+
13
+ def self.from_file( path )
14
+ ## read in themes catalog
15
+ text = File.open( path, 'r:utf-8' ) { |f| f.read }
16
+ new( text )
17
+ end
18
+
19
+ # def self.from_string( text )
20
+ # self.new( text )
21
+ # end
22
+
23
+
24
+ def initialize( text )
25
+ recs = YAML.load( text )
26
+ ## note: convert array to hash (lookup by name)
27
+ ## todo: check for missing name property? - why? why not?
28
+ @scripts = recs.reduce( {} ) { |h,rec| h[rec['name']] = rec; h }
29
+ end
30
+
31
+
32
+ def find( name )
33
+ @scripts[ name ]
34
+ end
35
+
36
+ def list( filter=nil )
37
+ ## pp filter
38
+
39
+ @scripts.each_with_index do |(_,rec),i|
40
+ name = rec['name']
41
+ summary = rec['summary']
42
+ script = rec['script']
43
+
44
+ if script && script.index( '//github.com/')
45
+ ## "beautify" / shorten github links - remove raw/master/
46
+ script = script.gsub('raw/master/', '' )
47
+ end
48
+
49
+ ## pp h
50
+
51
+ line = ''
52
+ line << " %3d" % (i+1)
53
+ line << "..%-10s" % name
54
+ line << " .:. #{summary}"
55
+ line << " @ (#{script})"
56
+
57
+ if filter
58
+ ## note: ignore case (upper/lower/downcase) for now
59
+ ## filter on name/title and
60
+ ## tags for now
61
+ if name.downcase.index(filter.downcase) != nil || ## note: 0 is match found on index 0; only nil is not found
62
+ summary.downcase.index(filter.downcase) != nil
63
+ puts line
64
+ end
65
+ else
66
+ puts line
67
+ end
68
+ end
69
+ end # method filter
70
+
71
+ end # class Catalog
72
+
73
+ end # module Quik