nandoc 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +5 -4
- data/Rakefile +1 -1
- data/bin/nandoc +2 -1
- data/doc/FAQ.md +3 -0
- data/doc/PROVISO.md +39 -0
- data/doc/commands/diff.md +49 -0
- data/doc/svg/less-fonts.svg +2 -2
- data/lib/nandoc/cli/README.md +6 -0
- data/lib/nandoc/cli/command-methods.rb +38 -0
- data/lib/nandoc/cli/option-methods/exclusive-options.rb +56 -0
- data/lib/nandoc/cli/option-methods/option-enum.rb +64 -0
- data/lib/nandoc/cli/option-methods.rb +35 -0
- data/lib/nandoc/cli.rb +3 -0
- data/lib/nandoc/commands/create-nandoc-site.rb +9 -12
- data/lib/nandoc/commands/diff.rb +14 -11
- data/lib/nandoc/commands.rb +9 -0
- data/lib/nandoc/{config.rb → core/config.rb} +18 -9
- data/lib/nandoc/core/project.rb +50 -0
- data/lib/nandoc/doc/hack-free-zone-defined.md +33 -0
- data/lib/nandoc/erb/agent.rb +5 -5
- data/lib/nandoc/{test/minitest-extlib.rb → extlib/minitest.rb} +1 -1
- data/lib/nandoc/filters/builtin-tags/fence/terminal.rb +24 -0
- data/lib/nandoc/filters/builtin-tags/fence-dispatcher.rb +43 -0
- data/lib/nandoc/filters/builtin-tags/fences.rb +4 -0
- data/lib/nandoc/filters/builtin-tags/see-test.rb +67 -0
- data/lib/nandoc/filters/builtin-tags.rb +11 -0
- data/lib/nandoc/filters/custom-tag.rb +43 -0
- data/lib/nandoc/filters/custom-tags.rb +19 -0
- data/lib/nandoc/filters/tag-parse-instance-methods.rb +11 -0
- data/lib/nandoc/filters/tag-parser.rb +206 -0
- data/lib/nandoc/filters.rb +11 -585
- data/lib/nandoc/{cri-hacks.rb → hacks/cri-hacks.rb} +4 -3
- data/lib/nandoc/{data-source.rb → hacks/data-source.rb} +5 -4
- data/lib/nandoc/{item-class-hacks.rb → hacks/item-class-hacks.rb} +3 -1
- data/lib/nandoc/hacks.rb +6 -0
- data/lib/nandoc/helpers/menu-bouncy.rb +1 -1
- data/lib/nandoc/helpers/site-map.rb +3 -0
- data/lib/nandoc/helpers.rb +1 -1
- data/lib/nandoc/html/tags.rb +65 -0
- data/lib/nandoc/html.rb +6 -0
- data/lib/nandoc/parse-readme.rb +4 -0
- data/lib/nandoc/spec-doc/agent-instance-methods.rb +24 -0
- data/lib/nandoc/spec-doc/code-snippet.rb +59 -0
- data/lib/nandoc/spec-doc/generic-agent.rb +40 -0
- data/lib/nandoc/spec-doc/mock-prompt.rb +3 -9
- data/lib/nandoc/spec-doc/parse-trace.rb +25 -0
- data/lib/nandoc/spec-doc/{mini-test/spec-instance-methods.rb → playback/html/foo-bar.rb} +0 -0
- data/lib/nandoc/spec-doc/playback/html.rb +2 -0
- data/lib/nandoc/spec-doc/playback/players/method.rb +64 -0
- data/lib/nandoc/spec-doc/playback/players/ruby.rb +158 -0
- data/lib/nandoc/spec-doc/playback/players/terminal.rb +93 -0
- data/lib/nandoc/spec-doc/playback/players.rb +4 -0
- data/lib/nandoc/spec-doc/playback/support/playback-methods.rb +44 -0
- data/lib/nandoc/spec-doc/playback/support/sexp-scanner.rb +61 -0
- data/lib/nandoc/spec-doc/playback/support.rb +3 -0
- data/lib/nandoc/spec-doc/playback/terminal/color-to-html.rb +100 -0
- data/lib/nandoc/spec-doc/playback.rb +3 -0
- data/lib/nandoc/spec-doc/recordings.rb +55 -0
- data/lib/nandoc/spec-doc/ruby2ruby-standin.rb +37 -0
- data/lib/nandoc/spec-doc/test-case-agent.rb +1 -1
- data/lib/nandoc/spec-doc/{mini-test.rb → test-framework/mini-test/proxy.rb} +9 -31
- data/lib/nandoc/spec-doc/{test-framework-proxy.rb → test-framework/proxy.rb} +27 -50
- data/lib/nandoc/spec-doc.rb +57 -13
- data/lib/nandoc/{test → support}/diff-to-string.rb +0 -0
- data/lib/nandoc/support/regexp-enhance.rb +6 -0
- data/lib/nandoc/support/regexp.rb +12 -0
- data/lib/nandoc/support/secret-parent.rb +21 -0
- data/lib/nandoc/support/shared-attr-reader.rb +32 -0
- data/lib/nandoc/support/site-merge.rb +1 -1
- data/lib/nandoc/support/site-methods.rb +4 -4
- data/lib/nandoc/support/stream-colorizer.rb +1 -1
- data/lib/nandoc/support/string-methods.rb +56 -0
- data/lib/nandoc.rb +12 -35
- data/proto/README.md +4 -2
- data/test/test.rb +1 -0
- metadata +58 -25
- data/doc/bar/baz.md +0 -4
- data/doc/bar/bliff.md +0 -8
- data/doc/foo.md +0 -5
- data/doc/getting-started.rb +0 -13
- data/lib/nandoc/spec-doc/support-modules.rb +0 -158
- data/lib/nandoc/spec-doc/test-framework-dispatcher.rb +0 -15
- data/lib/nandoc/support-modules.rb +0 -273
- data/lib/nandoc/treebis/NOGIT-DOCS/NEWS.md +0 -5
- data/lib/nandoc/treebis/NOGIT-README.md +0 -65
- data/lib/nandoc/treebis/nandoc.persistent.json +0 -3
@@ -1,273 +0,0 @@
|
|
1
|
-
module NanDoc
|
2
|
-
module CliCommandHelpers
|
3
|
-
def command_name
|
4
|
-
(/::([_a-z0-9]+)\Z/i =~ self.class.to_s and base = $1) or fail('no')
|
5
|
-
base.gsub(/([a-z])([A-Z])/){ "#{$1}-#{$2}" }.downcase
|
6
|
-
end
|
7
|
-
def invite_to_more_command_help
|
8
|
-
"see `nandoc help #{command_name}` for more information."
|
9
|
-
end
|
10
|
-
def invocation_name
|
11
|
-
File.basename($PROGRAM_NAME)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
module StringFormatting; end
|
15
|
-
module OptsNormalizer
|
16
|
-
def normalize_opts opts
|
17
|
-
opts = opts.dup
|
18
|
-
opts.keys.select{|x| x.to_s.index('-') }.each do |k|
|
19
|
-
opts[normalize_opt_key(k)] = opts.delete(k)
|
20
|
-
end
|
21
|
-
opts
|
22
|
-
end
|
23
|
-
def normalize_opt_key k
|
24
|
-
k.to_s.gsub('-','_').to_sym
|
25
|
-
end
|
26
|
-
def unnormalize_opt_keys keys
|
27
|
-
keys.map{|x| unnormalize_opt_key(x)}
|
28
|
-
end
|
29
|
-
def unnormalize_opt_key key
|
30
|
-
"--#{key.to_s.gsub('_','-')}"
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# only call this if you are like a ::Cri::Command object with
|
35
|
-
# all the nanDoc hacks. ick. This is a temprary hack. Trollop et al
|
36
|
-
# do this better.
|
37
|
-
#
|
38
|
-
def exclusive_opt_flags opts, &block
|
39
|
-
Exclusive.new(&block).parse(self, opts)
|
40
|
-
end
|
41
|
-
|
42
|
-
class Exclusive
|
43
|
-
include OptsNormalizer
|
44
|
-
def initialize &block
|
45
|
-
@exclusive_flag_keys = nil
|
46
|
-
@default_short = nil
|
47
|
-
@default_key = nil
|
48
|
-
@notice_stream = $stderr
|
49
|
-
instance_eval(&block)
|
50
|
-
fail('definition block needs at least flags()') unless
|
51
|
-
@exclusive_flag_keys
|
52
|
-
end
|
53
|
-
def flags * exclusive_flag_keys
|
54
|
-
@exclusive_flag_keys = exclusive_flag_keys
|
55
|
-
end
|
56
|
-
# params: [short_name_string] name_key
|
57
|
-
def default *a
|
58
|
-
if a.first.kind_of?(String)
|
59
|
-
@default_short = a.shift
|
60
|
-
end
|
61
|
-
if a.first.kind_of?(Symbol)
|
62
|
-
@default_key = a.shift
|
63
|
-
else
|
64
|
-
fail("bad args: #{a.first.inspect}")
|
65
|
-
end
|
66
|
-
fail("extra args: #{a.inspect}") if a.any?
|
67
|
-
end
|
68
|
-
def notice_stream mixed
|
69
|
-
@notice_stream = mixed
|
70
|
-
end
|
71
|
-
def parse cmd, opts
|
72
|
-
these = @exclusive_flag_keys & opts.keys
|
73
|
-
if these.empty? && @default_key
|
74
|
-
if @notice_stream
|
75
|
-
msg =
|
76
|
-
["using default: "+unnormalize_opt_key(@default_key),
|
77
|
-
@default_short ? "(#{@default_short})" : nil
|
78
|
-
].compact.join(' ')
|
79
|
-
@notice_stream.puts msg
|
80
|
-
end
|
81
|
-
these.push(@default_key)
|
82
|
-
end
|
83
|
-
if these.size > 1
|
84
|
-
flags = unnormalize_opt_keys(@exclusive_flag_keys)
|
85
|
-
cmd.task_abort <<-ABORT.gsub(/^ */,'')
|
86
|
-
#{flags.join(' and ')} are mutually exclusive.
|
87
|
-
usage: #{cmd.usage}
|
88
|
-
#{cmd.invite_to_more_command_help}
|
89
|
-
ABORT
|
90
|
-
end
|
91
|
-
these.first
|
92
|
-
end
|
93
|
-
end
|
94
|
-
class OptEnum
|
95
|
-
include OptsNormalizer, StringFormatting
|
96
|
-
def initialize(&block)
|
97
|
-
instance_eval(&block)
|
98
|
-
end
|
99
|
-
def command cmd
|
100
|
-
@command = cmd
|
101
|
-
end
|
102
|
-
def default str
|
103
|
-
@default = str
|
104
|
-
end
|
105
|
-
def name name
|
106
|
-
@name = name
|
107
|
-
end
|
108
|
-
def parse opts
|
109
|
-
found = nil
|
110
|
-
if opts.key?(@name)
|
111
|
-
v = opts[@name]
|
112
|
-
re = /\A#{Regexp.escape(v)}/
|
113
|
-
founds = @values.grep(re)
|
114
|
-
case founds.size
|
115
|
-
when 0; invalid(v)
|
116
|
-
when 1; found = founds.first
|
117
|
-
else found = founds.detect{|f| f==v} or too_many(founds)
|
118
|
-
end
|
119
|
-
elsif(@default)
|
120
|
-
found = @default
|
121
|
-
else
|
122
|
-
found = nil
|
123
|
-
end
|
124
|
-
opts[@name] = found if found # normalize short versions
|
125
|
-
found
|
126
|
-
end
|
127
|
-
def values *v
|
128
|
-
v = v.first if v.size==1 && Array === v
|
129
|
-
@values = v
|
130
|
-
end
|
131
|
-
private
|
132
|
-
def coda
|
133
|
-
"usage: #{@command.usage}\n#{@command.invite_to_more_command_help}"
|
134
|
-
end
|
135
|
-
def invalid val
|
136
|
-
@command.task_abort("invalid value #{val.inspect} for "<<
|
137
|
-
"#{long_name}. #{valid_values_are}\n#{coda}")
|
138
|
-
end
|
139
|
-
def long_name
|
140
|
-
unnormalize_opt_key(@name)
|
141
|
-
end
|
142
|
-
def too_many these
|
143
|
-
@command.task_abort("did you mean " <<
|
144
|
-
oxford_comma(these,' or ', "ed)<<" for #{long_name}?\n#{coda}")
|
145
|
-
end
|
146
|
-
def valid_values_are
|
147
|
-
"valid values are " << oxford_comma(@values,"ed)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
module PathHelper
|
152
|
-
def assert_path name, *paths
|
153
|
-
paths.each do |p|
|
154
|
-
unless File.exist?(p)
|
155
|
-
task_abort("#{name} does not exist: #{p}")
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
module StringFormatting
|
161
|
-
def basename_no_extension str
|
162
|
-
/([^\/\.]+)(?:\.[^\.\/]+)?\Z/ =~ str ? $1 : nil
|
163
|
-
end
|
164
|
-
def indent str, indent
|
165
|
-
str.gsub(/^/, indent)
|
166
|
-
end
|
167
|
-
def no_blank_lines str
|
168
|
-
str.gsub(/\n[[:space:]]*\n/, "\n")
|
169
|
-
end
|
170
|
-
def no_leading_ws str
|
171
|
-
str.sub(/\A[[:space:]]+/, '')
|
172
|
-
end
|
173
|
-
def no_trailing_ws str
|
174
|
-
str.sub(/[[:space:]]+\Z/, '')
|
175
|
-
end
|
176
|
-
def oxford_comma items, final = ' and ', "er
|
177
|
-
items = items.map("er) if quoter
|
178
|
-
these = []
|
179
|
-
these.push final if items.size > 1
|
180
|
-
these.concat(Array.new(items.size-2,', ')) if items.size > 2
|
181
|
-
these.reverse!
|
182
|
-
items.zip(these).flatten.compact.join
|
183
|
-
end
|
184
|
-
def quoted
|
185
|
-
proc{|x| "\"#{x}\"" }
|
186
|
-
end
|
187
|
-
|
188
|
-
#
|
189
|
-
# must respond to tab() and tabs()
|
190
|
-
# reindent a block by striping leading whitespace from lines evenly
|
191
|
-
# and then re-indenting each line according to our indent.
|
192
|
-
# this could be simpler, it has been more complicated
|
193
|
-
# we do it languidly because we can
|
194
|
-
#
|
195
|
-
def reindent h1, offset=0
|
196
|
-
indent_by = tab * (tabs+offset)
|
197
|
-
unindent_by = (/\A([[:space:]]+)/ =~ h1 && $1) or
|
198
|
-
fail('regex fail -- not sure if we need this to be so strict')
|
199
|
-
h2 = no_blank_lines(h1) # careful. will mess up with <pre> etc
|
200
|
-
return h2 if unindent_by == indent_by
|
201
|
-
h3 = unindent(h2, unindent_by)
|
202
|
-
h4 = indent(h3, indent_by)
|
203
|
-
h4
|
204
|
-
end
|
205
|
-
|
206
|
-
def unindent str, by
|
207
|
-
str.gsub(/^#{Regexp.escape(by)}/, '')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
module SecretParent
|
211
|
-
#
|
212
|
-
# set parent attribute without it showing up in inspect() dumps
|
213
|
-
#
|
214
|
-
def parent= mixed
|
215
|
-
fail("no clear_parent() available yet.") unless mixed
|
216
|
-
@has_parent = !! mixed
|
217
|
-
class << self; self end.send(:define_method, :parent){mixed}
|
218
|
-
mixed # maybe chain assignmnet of 1 parent to several cx at once
|
219
|
-
end
|
220
|
-
def parent?
|
221
|
-
instance_variable_defined?('@has_parent') && @has_parent # no warnings
|
222
|
-
end
|
223
|
-
def parent
|
224
|
-
nil
|
225
|
-
end
|
226
|
-
end
|
227
|
-
module SharedAttrReader
|
228
|
-
#
|
229
|
-
# this is a specialized form of delegator pattern: let one object
|
230
|
-
# use the responses from another object for a set of accessors
|
231
|
-
#
|
232
|
-
def shared_attr_reader *list
|
233
|
-
fail('no inehiritance yet') if method_defined?(:shared=)
|
234
|
-
sm = Module.new
|
235
|
-
name = self.to_s+'::SharedAttrReaders'
|
236
|
-
sing = class << sm; self end
|
237
|
-
sing.send(:define_method, :name){name}
|
238
|
-
sing.send(:alias_method, :inspect, :name)
|
239
|
-
list.each do |attrib|
|
240
|
-
sm.send(:define_method, attrib){ shared.send(attrib) }
|
241
|
-
end
|
242
|
-
fail('no') if method_defined?(:shared)
|
243
|
-
define_method(:shared){ self }
|
244
|
-
define_method(:shared=) do |source|
|
245
|
-
sing = class << self; self end
|
246
|
-
sing.send(:define_method, :shared){ source }
|
247
|
-
sing.send(:include, sm) # wow cool that this works w/o having
|
248
|
-
# to Module#undef_method
|
249
|
-
source
|
250
|
-
end
|
251
|
-
nil
|
252
|
-
end
|
253
|
-
end
|
254
|
-
module TaskCommon
|
255
|
-
def task_abort msg
|
256
|
-
if msg.index("for more info") # not mr. right, mr. right now
|
257
|
-
tail = ''
|
258
|
-
else
|
259
|
-
last = msg[-1].chr
|
260
|
-
tail = ".?!".index(last) ? ' ' : ("\n"==last ? '' : '. ')
|
261
|
-
tail << 'Aborting.'
|
262
|
-
end
|
263
|
-
$stderr.puts "nanDoc: #{msg}#{tail}"
|
264
|
-
exit 1
|
265
|
-
end
|
266
|
-
end
|
267
|
-
module CliCommandHelpers
|
268
|
-
include OptsNormalizer, TaskCommon, PathHelper
|
269
|
-
end
|
270
|
-
module PathHelper
|
271
|
-
include TaskCommon
|
272
|
-
end
|
273
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
## treebis
|
2
|
-
|
3
|
-
### in short,
|
4
|
-
Treebis is a minimal (small) task utility written in ruby designed expressly for wrapping common actions for moving, copying and altering filetrees. It's geared towards things like generators. Its look is comparable to a Rake task. Its effect is comparable to a shell script composed of mkdir, mv, cp commands etc.
|
5
|
-
|
6
|
-
This document is overkill. Treebis is underkill.
|
7
|
-
|
8
|
-
### it is:
|
9
|
-
- task wrapper for external commands that make filetrees, e.g.
|
10
|
-
- maybe the generators in things like rails, ramaze, nandoc
|
11
|
-
- copies filetrees to filetrees
|
12
|
-
- removes filetrees from filetrees
|
13
|
-
- applies diffs to filetrees
|
14
|
-
- different ways to represent trees and diffs - heredocs, diffs, filesystem.
|
15
|
-
- under 500 lines of code (?) (~300 SLOC ATTOTW)
|
16
|
-
- near 100% test coverage (?)
|
17
|
-
|
18
|
-
### it is not:
|
19
|
-
- a vcs or vcs wrapper (version control system)
|
20
|
-
- atomic
|
21
|
-
- a replacement for the heavy hitters used by web frameworks
|
22
|
-
- Safe. Little sanity checking and error checking is done. At present it
|
23
|
-
it is mostly a wrapper around FileUtils and patch. If you refer to files
|
24
|
-
that aren't there or try to read/move/remove files you don't have the
|
25
|
-
permissions to do so with, you will see the errors as you would from
|
26
|
-
FileUtils.
|
27
|
-
|
28
|
-
### faq
|
29
|
-
|
30
|
-
#### Q: why use it?
|
31
|
-
|
32
|
-
#### A:
|
33
|
-
<p class='ans'>Because you want a consistent way to wrap these common tasks that doesn't explicitly rely on shelling out to the underlying system, or other hodgepodges. (also see 'why did you make this?')
|
34
|
-
</p>
|
35
|
-
|
36
|
-
#### Q: why not use it?
|
37
|
-
|
38
|
-
#### A:
|
39
|
-
Because it doesn't do what you want or it does what you do not want.
|
40
|
-
|
41
|
-
#### Q: why is it named "Treebis?"
|
42
|
-
|
43
|
-
#### A:
|
44
|
-
because it rhymes with "Jeebus."
|
45
|
-
|
46
|
-
#### Q: why did you make this?
|
47
|
-
|
48
|
-
#### A:
|
49
|
-
by the third or fourth time i found myself re-writing this same kind of thing for different projects (or bleeding from its absence), i decided to abstract it. It's more readable than a bunch of FileUtils statements, it's more portable than a bunch of bash scripts (sorta), it's divorced from any heavy (or light) web frameworks, and it paves the way for possible future enhancements like atomicitiy and units of work; and wouldn't it be nice if every generator of every project used the same library?
|
50
|
-
|
51
|
-
### requirements
|
52
|
-
- ruby 1.8.7
|
53
|
-
- GNU patch 2.5.8 (if the diff-patching functionality is to be used)
|
54
|
-
(most versions of patch will likely work; it uses unified diffs.)
|
55
|
-
|
56
|
-
### installation
|
57
|
-
@todo
|
58
|
-
|
59
|
-
### usage
|
60
|
-
@todo
|
61
|
-
|
62
|
-
### future unfulfilled promises made today:
|
63
|
-
- dry run
|
64
|
-
- erb
|
65
|
-
- two-pass units of work !!??
|