jeckyl 0.2.7 → 0.3.7

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTVhZDM0YjllODFmZmViOGFjMmE1YzkwNmEzNDc5ODAwMTE4Y2Q1NA==
5
+ data.tar.gz: !binary |-
6
+ Y2E5NWYxZjllYzI5ODE4YTk3MWRkODgxMWQ5NDY4MTQ2MjlmNzRjOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YzY0MTQ5YjNjZWZlZmU2ODFlY2E4Njg0MmYzYjZlODg4MWIzNDQ2MmNiYTVk
10
+ MzdhN2NmNDZkNmNkZGM0YWJkOTU0YmQ2ZjFjODNhZDlkYzFiNzAyNGEzMDVl
11
+ MDcyMjFmNjNiZGM5NDJiNmQwZWQwMDYyOGVlMWEzZTk3ZjI4YWE=
12
+ data.tar.gz: !binary |-
13
+ MzhhYjQ1MTRiNGMwOGFlZTM2Mjg3OTZkNDQ4YzYzNjQ1N2YyOTY5NDVhNzBi
14
+ MmUwMWJiMThlYTQ3ZmRjNmIwZmQ4N2Q1MjhlNTRlM2IzZWUwNTE0MmZjMjdm
15
+ YTViNDYxMjg3ZDcyMjcwOTQwZGFiOTRhN2UwZWNmMDkyMjAzM2Q=
data/Bugs.rdoc CHANGED
@@ -1,6 +1,18 @@
1
1
  === BUGS
2
2
 
3
- [jeckyl-0.2.0 20-Sep-2012]
3
+ [jeckyl-0.3.2 22-Aug-2013]
4
4
 
5
- Nothing yet...
5
+ Can use a *arg but it fails to get through method_missing. Would be nice if it could?
6
+
7
+ [jeckyl-0.3.2 26-July-2013]
8
+
9
+ When accessing a newly created options hash, it appears that undefined keys do not return nil/false as expected.
10
+ If the same request is made again the expected nil is returned.
11
+
12
+ force = options[:force_init] # where :force_init is NOT a key
13
+ => true
14
+ force_again = options[:force_init]
15
+ => false
16
+
17
+ Very strange and unexpected behaviour.
6
18
 
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  #@markup ruby
2
2
 
3
3
  # for the command line
4
- gem 'thor'
5
- gem 'term-ansicolor'
4
+ # gem 'thor' not any more
5
+ # gem 'term-ansicolor'
6
+
7
+ gem 'optplus', '>=0.0.6'
6
8
 
data/History.txt CHANGED
@@ -4,13 +4,48 @@
4
4
 
5
5
  == History
6
6
 
7
+ [jeckyl-0.3.7 19-Sep-2013]
8
+
9
+ Corrected some minor yard issues
10
+
11
+ [jeckyl-0.3.6 11-Sep-2013]
12
+
13
+ Added a couple of helpers (an_executable) and removed thor from utility.
14
+
15
+ [jeckyl-0.3.5 23-Aug-2013]
16
+
17
+ Ensure 1.9 compliance
18
+
19
+ [jeckyl-0.3.4 23-Aug-2013]
20
+
21
+ Test for files in merge and ignore if not there
22
+
23
+ [jeckyl-0.3.3 22-Aug-2013]
24
+
25
+ Set :config_files to an empty array by default
26
+
27
+ [jeckyl-0.3.2 25-Jul-2013]
28
+
29
+ Updated merge to merge a hash as well as a file (using Hash#merge!)
30
+
31
+ [jeckyl-0.3.1 9-Apr-2013]
32
+
33
+ Added class method get_config_opt to pre-parse -c cfile from the command line so that
34
+ the specified config file can then be used for the rest of the options
35
+
36
+ [jeckyl-0.3.0 29-Mar-2013]
37
+
38
+ Beta test. Jeckyl can now process command switches for the same options using optparse.
39
+ Helper methods moved to a separate module and a couple of new ones added (a_number, a_positive_number).
40
+ A to_s method added to make it easier to display values.
41
+
7
42
  [jeckyl-0.2.7 15-Nov-2012]
8
43
 
9
44
  Change base directory for configs to /etc/jerbil consistent with the main jerbil gem
10
45
 
11
46
  [jeckyl-0.2.6 25-Oct-2012]
12
47
 
13
- Revert to /etc/jermine while working through changes to over gems
48
+ Revert to /etc/jermine while working through changes to other gems
14
49
 
15
50
  [jeckyl-0.2.5 25-Oct-2012]
16
51
 
data/bin/jeckyl CHANGED
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env ruby18
1
+ #!/usr/bin/env ruby
2
2
  #
3
- # Description
3
+ # Command Line utilities for Jeckyl
4
4
  #
5
5
  # Author:: Robert Sharp
6
- # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # Copyright:: Copyright (c) 2013 Robert Sharp
7
7
  # License:: Open Software Licence v3.0
8
8
  #
9
9
  # This software is licensed for use under the Open Software Licence v. 3.0
@@ -12,36 +12,34 @@
12
12
  # must themselves be licensed under the Open Software Licence v. 3.0
13
13
  #
14
14
  #
15
- # replace this to point to your config class
16
- # require 'my_jeckyl_configurator'
17
- require 'rubygems' # want to find classes that might be in gems
18
- require 'jeckyl'
19
- require 'jeckyl/errors'
20
- require 'thor'
21
- require 'thor/group'
22
- require 'colored'
23
15
 
16
+ require 'rubygems'
17
+ require 'optplus'
24
18
 
19
+ require 'jeckyl'
20
+ require 'jeckyl/errors'
25
21
 
26
- # the Command Line Interface for jeckyl to allow users to generate
27
- # config files, generate a simple template or check a config file
28
- class JeckylCLI < Thor
22
+ class JeckylCli < Optplus::Parser
29
23
 
30
- default_task :usage
24
+ usage "action [params] [options]"
31
25
 
32
- desc "usage", "You are looking at it"
33
- def usage
34
- puts "Useful tasks for managing Jeckyl config files."
35
- puts ""
36
- help
37
- puts ""
38
- puts "See Also:"
39
- puts " README.md: (see jeckyl readme above)"
40
- puts " GitHub: https://github.com/osburn-sharp/jeckyl"
41
- puts " RubyDoc: http://rdoc.info/github/osburn-sharp/jeckyl/frames"
26
+ description "Useful utilities for Jeckyl configuration files.",
27
+ "To find out more, type 'jeckyl readme'"
28
+
29
+ # before_all
30
+
31
+ def options(opts)
32
+ opts.on('-C', '--class Index', Integer, 'select a class by index') do |i|
33
+ set_option :klass_index, i
34
+ end
35
+ opts.on('-k', '--concat', 'concat all classes, starting with the oldest') do
36
+ set_option :konkat
37
+ end
42
38
  end
43
39
 
44
- desc "readme", "display the readme file for the gem"
40
+ # before_actions
41
+
42
+ describe "readme", "display the readme file for the gem"
45
43
  def readme
46
44
  gem_spec = Gem::Specification.find_by_name('jeckyl')
47
45
  readme_path = File.join(gem_spec.gem_dir, 'README.md')
@@ -54,30 +52,36 @@ class JeckylCLI < Thor
54
52
 
55
53
  end
56
54
 
57
- desc "list", "list all the config classes involved in a given class"
58
- def list(cfile)
55
+ describe "list", "list all the config classes involved in a given class"
56
+ def list
57
+ cfile = next_argument_or_error("missing config class")
59
58
  require cfile
60
59
  classes = Jeckyl::Options.descendants
61
60
  display_classes(classes)
62
61
  rescue LoadError
63
62
  puts "Error: could not load #{cfile}".red.bold
64
63
  end
64
+ help :list, "Show a list of this config class and its ancestors",
65
+ "This is useful when you have create a config class from a parent class",
66
+ "in order to include the parent classes' parameters.",
67
+ "The list is indexed and the index can be used in other actions,",
68
+ "include 'jeckyl config'."
65
69
 
66
70
 
67
- desc "config", "generate config file for the given config class"
68
- method_option :class, :aliases=>'-C', :type=>:numeric, :desc=>'select class by index'
69
- method_option :concat, :aliases=>'-k', :desc=>'concat all classes, starting with the oldest'
70
- def config(cfile, my_class_name=nil)
71
-
71
+
72
+ describe "config", "generate config file for the given config class"
73
+ def config
74
+ cfile = next_argument_or_error("You must provide a config class")
72
75
  require cfile # catch LoadError if cfile does not load
73
76
 
74
- my_class_index = options[:class] || 0
75
- my_class_index += -1 if my_class_index > 0
77
+ my_class_index = get_option(:klass_index) || 0
78
+ my_class_index -= 1 if my_class_index > 0
76
79
 
80
+ konkat = get_option :konkat
77
81
 
78
82
  classes = Jeckyl::Options.descendants
79
83
 
80
- if options[:concat].nil? && classes[my_class_index].nil? then
84
+ if !konkat && classes[my_class_index].nil? then
81
85
  $stderr.puts "Index #{my_class_index + 1} is invalid. Please select a valid index".red.bold
82
86
  display_classes(classes)
83
87
  return false
@@ -86,7 +90,7 @@ class JeckylCLI < Thor
86
90
  $stderr.puts "There are #{classes.length} sets of configs, use 'jeckyl list' to list them or -k to generate them all".yellow if classes.length > 1
87
91
 
88
92
  my_classes = []
89
- if options[:concat] then
93
+ if konkat then
90
94
  classes.each_index {|i| my_classes.unshift i}
91
95
  else
92
96
  my_classes << my_class_index
@@ -100,7 +104,7 @@ class JeckylCLI < Thor
100
104
  classes[ci].generate_config(true)
101
105
  end
102
106
 
103
- unless options[:concat] || classes.length == 1
107
+ unless konkat || classes.length == 1
104
108
  puts ""
105
109
  puts "# There are also parameters in:"
106
110
  classes.each do |klass|
@@ -109,11 +113,24 @@ class JeckylCLI < Thor
109
113
  end
110
114
 
111
115
  rescue LoadError
112
- puts "Error: could not load #{cfile}".red.bold
116
+ if cfile.nil? then
117
+ puts "Error: you need to specify a configration file".red.bold
118
+ else
119
+ puts "Error: could not load #{cfile}".red.bold
120
+ end
113
121
  end
122
+ help :config, "Outputs a default config file for the given class.",
123
+ "Use this to create a default file that you can then tailor for",
124
+ "specific settings. If there is more than one class involved use",
125
+ "-k to create an output with all the config parameters included.",
126
+ "Output is to stdout and can easily be redirected to a file as needed."
114
127
 
115
- desc "klass", "generate a simple class template"
116
- def klass(name, parent="Jeckyl::Config")
128
+
129
+
130
+ describe "klass", "generate a simple class template"
131
+ def klass
132
+ name = next_argument_or_error("missing class name")
133
+ parent = next_argument_or('Jeckyl::Config')
117
134
  puts <<EOTXT
118
135
  # Simple framework for defining Jeckyl options to put into a config hash
119
136
 
@@ -135,13 +152,20 @@ module #{name}
135
152
  end
136
153
  end
137
154
  EOTXT
138
-
155
+
139
156
  end
157
+ help :klass, "Generate a simple class file as a template for defining your",
158
+ "own parameters. You can also specify a class to inherit if you want to",
159
+ "pick up additional parameters. Otherwise the parent will default to",
160
+ "Jeckyl::Config. Alternatives include Jellog::Config and JerbilService::Config."
140
161
 
141
162
 
142
- desc "check", "check the given config file is valid for the given class"
163
+ describe "check", "check the given config file is valid for the given class"
143
164
  def check(klass_file, conf_file)
144
165
 
166
+ klass_file = next_argument_or_error("missing class name")
167
+ conf_file = next_argument_or_error("missing config file")
168
+
145
169
  require klass_file # catch LoadError if cfile does not load
146
170
 
147
171
  my_class_index = 0 # assume there is only one
@@ -153,23 +177,27 @@ EOTXT
153
177
 
154
178
  rescue LoadError
155
179
  puts "Error: could not load #{cfile}".red
156
-
180
+
157
181
  end
182
+ help :check, "Use the given class (which must be requirable) and check",
183
+ "that the given config file is OK or show errors if not.",
184
+ "Useful way to check that a config file works before using it in earnest."
158
185
 
159
- desc "markdown", "display the comments from a class in markdown format"
160
- method_option :class, :aliases=>'-C', :type=>:numeric, :desc=>'select class by index'
161
- method_option :concat, :aliases=>'-k', :desc=>'concat all classes, starting with the oldest'
162
- def markdown(cfile)
186
+
187
+ describe "markdown", "display the comments from a class in markdown format"
188
+ def markdown
163
189
 
164
- require cfile # catch LoadError if cfile does not load
190
+ cfile = next_argument_or_error("missing class")
165
191
 
166
- my_class_index = options[:class] || 0
167
- my_class_index += -1 if my_class_index > 0
192
+ require cfile # catch LoadError if cfile does not load
168
193
 
194
+ my_class_index = get_option(:klass_index) || 0
195
+ my_class_index -= 1 if my_class_index > 0
196
+ konkat = get_option :konkat
169
197
 
170
198
  classes = Jeckyl::Options.descendants
171
199
 
172
- if options[:concat].nil? && classes[my_class_index].nil? then
200
+ if !konkat && classes[my_class_index].nil? then
173
201
  $stderr.puts "Index #{my_class_index + 1} is invalid. Please select a valid index".red.bold
174
202
  display_classes(classes)
175
203
  return false
@@ -178,7 +206,7 @@ EOTXT
178
206
  $stderr.puts "There are #{classes.length} sets of configs, use 'jeckyl list' to list them or -k to generate them all".yellow if classes.length > 1
179
207
 
180
208
  my_classes = []
181
- if options[:concat] then
209
+ if konkat then
182
210
  classes.each_index {|i| my_classes << i}
183
211
  else
184
212
  my_classes << my_class_index
@@ -225,7 +253,7 @@ EOTXT
225
253
  end
226
254
  end
227
255
 
228
- unless options[:concat] || classes.length == 1
256
+ unless konkat || classes.length == 1
229
257
  puts ""
230
258
  puts "## See Also"
231
259
  puts ""
@@ -240,8 +268,11 @@ EOTXT
240
268
  puts "Error: could not load #{cfile}".red
241
269
 
242
270
  end
271
+ help :markdown, "Similar to config but instead of creating the config file itself",
272
+ "this creates a markdown file that can be used in rdoc to describe the config",
273
+ "parameters."
243
274
 
244
- no_tasks do
275
+
245
276
  def display_classes(classes)
246
277
  $stderr.puts "The following classes are available:".green
247
278
  count = 1
@@ -250,8 +281,9 @@ EOTXT
250
281
  count += 1
251
282
  end
252
283
  end
253
- end
254
284
 
285
+
286
+
255
287
  end
256
288
 
257
- JeckylCLI.start
289
+ JeckylCli.run!
data/bin/jeckyl-old ADDED
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Description
4
+ #
5
+ # Author:: Robert Sharp
6
+ # Copyright:: Copyright (c) 2010 Robert Sharp
7
+ # License:: Open Software Licence v3.0
8
+ #
9
+ # This software is licensed for use under the Open Software Licence v. 3.0
10
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
11
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
12
+ # must themselves be licensed under the Open Software Licence v. 3.0
13
+ #
14
+ #
15
+ # replace this to point to your config class
16
+ # require 'my_jeckyl_configurator'
17
+ require 'rubygems' # want to find classes that might be in gems
18
+ require 'jeckyl'
19
+ require 'jeckyl/errors'
20
+ require 'thor'
21
+ require 'thor/group'
22
+ require 'colored'
23
+
24
+
25
+
26
+ # the Command Line Interface for jeckyl to allow users to generate
27
+ # config files, generate a simple template or check a config file
28
+ class JeckylCLI < Thor
29
+
30
+ default_task :usage
31
+
32
+ class_option :gem, :aliases=>'-g', :type=>:string, :desc=>'get config classes etc from the given gem'
33
+
34
+ desc "usage", "You are looking at it"
35
+ def usage
36
+ puts "Useful tasks for managing Jeckyl config files."
37
+ puts ""
38
+ help
39
+ puts ""
40
+ puts "See Also:"
41
+ puts " README.md: (see jeckyl readme above)"
42
+ puts " GitHub: https://github.com/osburn-sharp/jeckyl"
43
+ puts " RubyDoc: http://rdoc.info/github/osburn-sharp/jeckyl/frames"
44
+ end
45
+
46
+ desc "readme", "display the readme file for the gem"
47
+ def readme
48
+ gem_spec = Gem::Specification.find_by_name('jeckyl')
49
+ readme_path = File.join(gem_spec.gem_dir, 'README.md')
50
+
51
+ File.open(readme_path) do |rfile|
52
+ rfile.each_line do |rline|
53
+ puts rline
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ desc "list", "list all the config classes involved in a given class"
60
+ def list(cfile)
61
+ require cfile
62
+ classes = Jeckyl::Options.descendants
63
+ display_classes(classes)
64
+ rescue LoadError
65
+ puts "Error: could not load #{cfile}".red.bold
66
+ end
67
+
68
+
69
+ desc "config", "generate config file for the given config class"
70
+ method_option :class, :aliases=>'-C', :type=>:numeric, :desc=>'select class by index'
71
+ method_option :concat, :aliases=>'-k', :desc=>'concat all classes, starting with the oldest'
72
+ def config(cfile, my_class_name=nil)
73
+
74
+ require cfile # catch LoadError if cfile does not load
75
+
76
+ my_class_index = options[:class] || 0
77
+ my_class_index += -1 if my_class_index > 0
78
+
79
+
80
+ classes = Jeckyl::Options.descendants
81
+
82
+ if options[:concat].nil? && classes[my_class_index].nil? then
83
+ $stderr.puts "Index #{my_class_index + 1} is invalid. Please select a valid index".red.bold
84
+ display_classes(classes)
85
+ return false
86
+ end
87
+
88
+ $stderr.puts "There are #{classes.length} sets of configs, use 'jeckyl list' to list them or -k to generate them all".yellow if classes.length > 1
89
+
90
+ my_classes = []
91
+ if options[:concat] then
92
+ classes.each_index {|i| my_classes.unshift i}
93
+ else
94
+ my_classes << my_class_index
95
+ end
96
+
97
+ my_classes.each do |ci|
98
+ puts "#"
99
+ puts "# Configuration Options for: #{classes[ci].name}"
100
+ puts "#"
101
+ puts
102
+ classes[ci].generate_config(true)
103
+ end
104
+
105
+ unless options[:concat] || classes.length == 1
106
+ puts ""
107
+ puts "# There are also parameters in:"
108
+ classes.each do |klass|
109
+ puts "# #{klass.name}"unless klass == classes[my_class_index]
110
+ end
111
+ end
112
+
113
+ rescue LoadError
114
+ puts "Error: could not load #{cfile}".red.bold
115
+ end
116
+
117
+ desc "klass", "generate a simple class template"
118
+ def klass(name, parent="Jeckyl::Config")
119
+ puts <<EOTXT
120
+ # Simple framework for defining Jeckyl options to put into a config hash
121
+
122
+ module #{name}
123
+
124
+ # configuration parameters for #{name}
125
+ #
126
+ # @see file:<PATH_TO_CONFIG_MARKDOWN_FILE> #{name} Parameter Descriptions
127
+ #
128
+ class Config < #{parent}
129
+
130
+ def configure_a_parameter(val)
131
+ default "default"
132
+ comment "Comment line",
133
+ "more comments"
134
+ a_type_of(String)
135
+ end
136
+
137
+ end
138
+ end
139
+ EOTXT
140
+
141
+ end
142
+
143
+
144
+ desc "check", "check the given config file is valid for the given class"
145
+ def check(klass_file, conf_file)
146
+
147
+ require klass_file # catch LoadError if cfile does not load
148
+
149
+ my_class_index = 0 # assume there is only one
150
+
151
+ classes = Jeckyl::Options.descendants
152
+
153
+
154
+ classes[my_class_index].check_config(conf_file)
155
+
156
+ rescue LoadError
157
+ puts "Error: could not load #{cfile}".red
158
+
159
+ end
160
+
161
+ desc "markdown", "display the comments from a class in markdown format"
162
+ method_option :class, :aliases=>'-C', :type=>:numeric, :desc=>'select class by index'
163
+ method_option :concat, :aliases=>'-k', :desc=>'concat all classes, starting with the oldest'
164
+ def markdown(cfile)
165
+
166
+ require cfile # catch LoadError if cfile does not load
167
+
168
+ my_class_index = options[:class] || 0
169
+ my_class_index += -1 if my_class_index > 0
170
+
171
+
172
+ classes = Jeckyl::Options.descendants
173
+
174
+ if options[:concat].nil? && classes[my_class_index].nil? then
175
+ $stderr.puts "Index #{my_class_index + 1} is invalid. Please select a valid index".red.bold
176
+ display_classes(classes)
177
+ return false
178
+ end
179
+
180
+ $stderr.puts "There are #{classes.length} sets of configs, use 'jeckyl list' to list them or -k to generate them all".yellow if classes.length > 1
181
+
182
+ my_classes = []
183
+ if options[:concat] then
184
+ classes.each_index {|i| my_classes << i}
185
+ else
186
+ my_classes << my_class_index
187
+ end
188
+
189
+ first = true
190
+ sublevel = 2
191
+
192
+ my_classes.each do |ci|
193
+ my_class = classes[ci]
194
+ my_configurator = my_class.new(nil, :local=>true)
195
+
196
+ if first then
197
+ puts "# #{my_class.name} Parameters"
198
+ puts ""
199
+ puts "The following parameters are defined in {#{my_class.name}} and should be used"
200
+ puts "in a configuration file. A default config file can be generated using:"
201
+ puts ""
202
+ puts " jeckyl config #{cfile}"
203
+ else
204
+ puts "## Additional Parameters from #{my_class.name}"
205
+ puts ""
206
+ puts "The following additional parameters are defined in #{my_class.name}, which"
207
+ puts "is an ancestor of this config class. See separate documentation for more details."
208
+ sublevel = 3
209
+ end
210
+ first = false
211
+ puts ""
212
+
213
+ puts "#" * sublevel + " Parameters"
214
+ puts ""
215
+
216
+ my_configurator.comments.each do |param, comment|
217
+ puts " * **#{param}**"
218
+ puts " "
219
+ comment.each {|line| puts " #{line}"}
220
+ puts ""
221
+ if my_configurator.defaults.has_key?(param) then
222
+ puts " Default: #{my_configurator.defaults[param].inspect}"
223
+ else
224
+ puts " No default set"
225
+ end
226
+ puts ""
227
+ end
228
+ end
229
+
230
+ unless options[:concat] || classes.length == 1
231
+ puts ""
232
+ puts "## See Also"
233
+ puts ""
234
+ puts "There are also parameters in:"
235
+ puts ""
236
+ classes.each do |klass|
237
+ puts " * #{klass.name}"unless klass == classes[my_class_index]
238
+ end
239
+ end
240
+
241
+ rescue LoadError
242
+ puts "Error: could not load #{cfile}".red
243
+
244
+ end
245
+
246
+ no_tasks do
247
+ def display_classes(classes)
248
+ $stderr.puts "The following classes are available:".green
249
+ count = 1
250
+ classes.each do |klass|
251
+ $stderr.puts " #{count}. #{klass.name}"
252
+ count += 1
253
+ end
254
+ end
255
+ end
256
+
257
+ end
258
+
259
+ JeckylCLI.start