drjekyll 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1abacc0051e57841738784b05c84d1adb06051ad
4
+ data.tar.gz: d756a8cd82ef92f2310f8dd40445583c8abf3c7c
5
+ SHA512:
6
+ metadata.gz: 0c127f82e87a8eaf5e5dc2be3440c11863d61c0282917e5fd03925531cb7e8281407a7273ad2feb6f4d51bb620a45dea1b759a170993fd8ae528457af5cf805b
7
+ data.tar.gz: 09f07a808b355bbcb8cb06ea2a5c466af3d22ab84829dfe813128ae5fa4212cc5053827c9862848bcd49c228504632ecdec6bfca9e703bec839dcbb8993ad52a
File without changes
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2015-08-11
2
+
3
+ * Everything is new. First release
@@ -0,0 +1,15 @@
1
+ HISTORY.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ bin/drj
6
+ bin/drjekyll
7
+ lib/drjekyll.rb
8
+ lib/drjekyll/catalog.rb
9
+ lib/drjekyll/cli/download.rb
10
+ lib/drjekyll/cli/list.rb
11
+ lib/drjekyll/cli/main.rb
12
+ lib/drjekyll/cli/opts.rb
13
+ lib/drjekyll/cli/unzip.rb
14
+ lib/drjekyll/version.rb
15
+ test/data/themes.yml
@@ -0,0 +1,2 @@
1
+ # drjekyll
2
+ drjekyll
@@ -0,0 +1,31 @@
1
+ require 'hoe'
2
+ require './lib/drjekyll/version.rb'
3
+
4
+ Hoe.spec 'drjekyll' do
5
+
6
+ self.version = DrJekyll::VERSION
7
+
8
+ self.summary = "drjekyll - the missing static site theme package manager"
9
+ self.description = summary
10
+
11
+ self.urls = ['https://github.com/drjekyllthemes/drjekyll']
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'wwwmake@googlegroups.com'
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
+ ## 3rd party
22
+ ['fetcher', '>= 0.4.5'],
23
+ ]
24
+
25
+ self.licenses = ['Public Domain']
26
+
27
+ self.spec_extras = {
28
+ required_ruby_version: '>= 1.9.2'
29
+ }
30
+
31
+ end
data/bin/drj ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'drjekyll'
4
+
5
+ ## todo: set x flag for file
6
+
7
+ DrJekyll.main
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'drjekyll'
4
+
5
+ ## todo: set x flag for file
6
+
7
+ DrJekyll.main
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # use to test:
5
+ # $ ruby -I ./lib ./lib/drjekyll.rb
6
+
7
+
8
+ ## stdlibs
9
+ require 'pp'
10
+ require 'yaml'
11
+
12
+
13
+ ## 3rd party gems
14
+ require 'props' ## Use Env.home
15
+ require 'logutils'
16
+
17
+
18
+ ## require 'fetcher'
19
+
20
+ ## more 3rd party gems
21
+ require 'gli'
22
+
23
+
24
+
25
+ # our own code
26
+
27
+ require 'drjekyll/version' # note: version always goes first
28
+ require 'drjekyll/catalog'
29
+
30
+ require 'drjekyll/cli/opts'
31
+ require 'drjekyll/cli/main'
32
+ require 'drjekyll/cli/list'
33
+ require 'drjekyll/cli/download'
34
+ require 'drjekyll/cli/unzip'
35
+
36
+
37
+
38
+ module DrJekyll
39
+
40
+ def self.main
41
+ exit Tool.new.run( ARGV )
42
+ end
43
+
44
+ end # module DrJekyll
45
+
46
+
47
+ ## DrJekyll.banner ## say hello
48
+
49
+ ## for debugging
50
+ pp Env.home
51
+ pp DrJekyll.root
52
+
53
+ DrJekyll.main if __FILE__ == $0
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+
3
+ module DrJekyll
4
+
5
+ class Catalog
6
+
7
+ def initialize( path )
8
+ ## read in themes catalog
9
+ text = File.read( path )
10
+ @themes = YAML.load( text )
11
+
12
+ ## auto-add keys for now (for quick testing)
13
+ @themes.each do |k,h|
14
+ name = k
15
+ keys = h['keys'] || []
16
+ if keys.empty?
17
+ ## auto-add key from title/name
18
+ ## downcase and remove all non alphanumeric (non-ascii)
19
+ slug = name.downcase.gsub( /[^a-z0-9]/, '' )
20
+
21
+ ## for quick testing add some shortcuts
22
+ if slug == 'planetjekyllsstarterminimal'
23
+ keys << 'starter'
24
+ elsif slug == 'drjekyllsminimal'
25
+ keys << 'minimial'
26
+ elsif slug == 'drjekyllsbootstrap'
27
+ keys << 'bootstrap'
28
+ elsif slug == 'drjekyllsclassicsbook'
29
+ keys << 'classics'
30
+ else
31
+ end
32
+ keys << slug
33
+ h['keys'] = keys
34
+ end
35
+ end
36
+ end
37
+
38
+ def list( filter=nil )
39
+ ## pp filter
40
+
41
+ @themes.each_with_index do |(k,h),i|
42
+ name = k
43
+ author = h['author']
44
+ tags = h['tags'] || [] ## allow nil for tags array for now
45
+ keys = h['keys']
46
+
47
+ line = ''
48
+ line << " %3d" % (i+1)
49
+ line << "..#{name}"
50
+ line << " (#{keys.join(' | ')})"
51
+ line << " by #{author}"
52
+ if tags.nil? == false && tags.empty? == false
53
+ line << " - "
54
+ tags.each do |tag|
55
+ line << "##{tag} "
56
+ end
57
+ end
58
+
59
+ if filter
60
+ ## note: ignore case (upper/lower/downcase) for now
61
+ ## filter on name/title and
62
+ ## tags for now
63
+ if name.downcase.index(filter.downcase) != nil || ## note: 0 is match found on index 0; only nil is not found
64
+ tags.join('|').downcase.index( filter.downcase ) != nil
65
+ puts line
66
+ end
67
+ else
68
+ puts line
69
+ end
70
+ end
71
+ end # method filter
72
+
73
+ def get( key ) ## use fetch or different name - why? why not??
74
+ ## find theme by key
75
+ ## fix/todo: use linear search for now; use hash lookup later
76
+
77
+ theme = nil ## note: return nil if nothing found
78
+
79
+ @themes.each do |k,h|
80
+ name = k
81
+ keys = h['keys']
82
+
83
+ if keys.include?( key )
84
+ ## bingo found
85
+ ## todo: merge k (name/title) into (returned) hash - why? why not??
86
+ puts " ** bingo; found theme >#{k}<:"
87
+ pp h
88
+ theme = h
89
+ break
90
+ end
91
+ end
92
+
93
+ theme
94
+ end
95
+
96
+ end # class Catalog
97
+
98
+ end # module DrJekyll
99
+
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module DrJekyll
5
+
6
+ class DownloadCommand ## find a better name - why, why not ??
7
+
8
+ def initialize( catalog, opts )
9
+ @catalog = catalog
10
+ @opts = opts
11
+ end
12
+
13
+ def run( args )
14
+ ## note: required template name (defaults to starter for now)
15
+ key = args[0] || 'starter'
16
+
17
+ theme = @catalog.get( key )
18
+
19
+ if theme
20
+ download( theme )
21
+ else
22
+ ## todo: issue warning - why, why not??
23
+ end
24
+ end
25
+
26
+ def download( theme )
27
+ ## to be done
28
+ pp theme
29
+ end
30
+
31
+ end ## class DownloadCommand
32
+
33
+ end # module DrJekyll
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module DrJekyll
5
+
6
+ class ListCommand ## find a better name ??
7
+
8
+ def initialize( catalog, opts )
9
+ @catalog = catalog
10
+ @opts = opts
11
+ end
12
+
13
+ def run( args )
14
+ filter = args[0] ## optional filter (search query)
15
+ list( filter )
16
+ end
17
+
18
+ def list( filter=nil )
19
+ @catalog.list( filter )
20
+ end
21
+
22
+ end ## class ListCommand
23
+
24
+ end # module DrJekyll
@@ -0,0 +1,177 @@
1
+ # encoding: utf-8
2
+
3
+ ### NOTE: wrap gli config into a class
4
+ ## see github.com/davetron5000/gli/issues/153
5
+
6
+ module DrJekyll
7
+
8
+ class Tool
9
+ def initialize
10
+ LogUtils::Logger.root.level = :info # set logging level to info
11
+ end
12
+
13
+ def run( args )
14
+ puts DrJekyll.banner
15
+ Toolii.run( args )
16
+ end
17
+ end
18
+
19
+ ## NOTE: gli added function are class methods (thus, wrap class Toolii in Tool for now)
20
+
21
+ class Toolii
22
+ extend GLI::App
23
+
24
+ def self.logger=(value) @@logger=value; end
25
+ def self.logger() @@logger; end
26
+
27
+ ## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
28
+ def self.opts=(value) @@opts = value; end
29
+ def self.opts() @@opts; end
30
+
31
+
32
+ logger = LogUtils::Logger.root
33
+ opts = Opts.new
34
+
35
+
36
+ program_desc 'drjekyll command line tool'
37
+ version VERSION
38
+
39
+
40
+ desc 'Use only local (offline) cached data; no (online) remote network access'
41
+ switch [:l, :local], negatable: false
42
+
43
+ desc '(Debug) Show debug messages'
44
+ switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
45
+
46
+ desc 'Only show warnings, errors and fatal messages'
47
+ switch [:q, :quiet], negatable: false
48
+
49
+
50
+
51
+ desc "List themes"
52
+ arg_name 'QUERY' # optional search query/filter
53
+ command [:list,:ls,:l] do |c|
54
+
55
+ c.action do |g,o,args|
56
+ ## read in themes diretory
57
+ themes_dir = "#{DrJekyll.root}/test/data"
58
+ catalog = Catalog.new( "#{themes_dir}/themes.yml" )
59
+
60
+ cmd = ListCommand.new( catalog, opts )
61
+ cmd.run( args )
62
+ puts 'Done.'
63
+ end # action
64
+ end # command list
65
+
66
+
67
+ ## use get or fetch - why, why not??
68
+ desc "Download theme; saved in ~/.drjekyll/cache"
69
+ arg_name 'NAME' # required theme name
70
+ command [:download,:dl,:d,:get,:g] do |c|
71
+
72
+ c.action do |g,o,args|
73
+ ## read in themes diretory
74
+ themes_dir = "#{DrJekyll.root}/test/data"
75
+ catalog = Catalog.new( "#{themes_dir}/themes.yml" )
76
+
77
+ cmd = DownloadCommand.new( catalog, opts )
78
+ cmd.run( args )
79
+ puts 'Done.'
80
+ end # action
81
+ end # command download
82
+
83
+
84
+ ## use install or unzip/unpack - why, why not??
85
+ desc "Setup (unzip/unpack) theme; use archive in ~/.drjekyll/cache"
86
+ arg_name 'NAME' # required theme name
87
+ command [:unpack,:pk,:p,:setup,:s] do |c|
88
+
89
+ c.action do |g,o,args|
90
+ ## read in themes diretory
91
+ themes_dir = "#{DrJekyll.root}/test/data"
92
+ catalog = Catalog.new( "#{themes_dir}/themes.yml" )
93
+
94
+ cmd = UnzipCommand.new( catalog, opts )
95
+ cmd.run( args )
96
+ puts 'Done.'
97
+ end # action
98
+ end # command setup
99
+
100
+
101
+ desc "Download 'n' setup (unzip/unpack) theme"
102
+ arg_name 'NAME' # required theme name
103
+ command [:new,:n] do |c|
104
+
105
+ c.action do |g,o,args|
106
+
107
+ ## todo: required template name (defaults to starter for now)
108
+ name = args[0] || 'starter'
109
+
110
+ puts " download theme here"
111
+ puts " unzip/unpack (setup) here"
112
+ puts 'Done.'
113
+ end # action
114
+ end # command setup
115
+
116
+
117
+
118
+
119
+ desc '(Debug) Test command suite'
120
+ command :test do |c|
121
+ c.action do |g,o,args|
122
+
123
+ puts "hello from test command"
124
+ puts "args (#{args.class.name}):"
125
+ pp args
126
+ puts "o (#{o.class.name}):"
127
+ pp o
128
+ puts "g (#{g.class.name}):"
129
+ pp g
130
+
131
+ LogUtils::Logger.root.debug 'test debug msg'
132
+ LogUtils::Logger.root.info 'test info msg'
133
+ LogUtils::Logger.root.warn 'test warn msg'
134
+
135
+ puts 'Done.'
136
+ end
137
+ end
138
+
139
+
140
+
141
+ pre do |g,c,o,args|
142
+ opts.merge_gli_options!( g )
143
+ opts.merge_gli_options!( o )
144
+
145
+ puts DrJekyll.banner
146
+
147
+ if opts.verbose?
148
+ LogUtils::Logger.root.level = :debug
149
+ end
150
+
151
+ logger.debug "Executing #{c.name}"
152
+ true
153
+ end
154
+
155
+ post do |global,c,o,args|
156
+ logger.debug "Executed #{c.name}"
157
+ true
158
+ end
159
+
160
+
161
+ on_error do |e|
162
+ puts
163
+ puts "*** error: #{e.message}"
164
+
165
+ if opts.verbose?
166
+ puts e.backtrace
167
+ end
168
+
169
+ false # skip default error handling
170
+ end
171
+
172
+
173
+ ### exit run(ARGV) ## note: use Toolii.run( ARGV ) outside of class
174
+
175
+ end # class Toolii
176
+
177
+ end # module DrJekyll