devver-germinate 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/README.rdoc +26 -4
- data/TODO +80 -8
- data/bin/germ +162 -38
- data/examples/basic.rb +14 -9
- data/examples/short.rb +2 -0
- data/features/author-formats-article.feature +3 -3
- data/features/{author-lists-info.feature → author-lists-info.pending_feature} +3 -0
- data/features/author-publishes-article.feature +52 -0
- data/features/author-selects-hunks.feature +1 -1
- data/features/author-sets-variables.feature +88 -0
- data/features/{author-views-stuff.feature → author-views-stuff.pending_feature} +4 -0
- data/features/example_articles/escaping.txt +1 -0
- data/features/example_articles/specials.rb +3 -3
- data/features/example_output/specials.txt +9 -5
- data/features/step_definitions/germinate.rb +9 -0
- data/germinate.gemspec +3 -3
- data/lib/germinate.rb +1 -1
- data/lib/germinate/application.rb +82 -31
- data/lib/germinate/hunk.rb +20 -0
- data/lib/germinate/insertion.rb +10 -2
- data/lib/germinate/librarian.rb +129 -31
- data/lib/germinate/origin.rb +5 -0
- data/lib/germinate/pipeline.rb +2 -0
- data/lib/germinate/publisher.rb +57 -0
- data/lib/germinate/reader.rb +51 -8
- data/lib/germinate/selector.rb +18 -6
- data/lib/germinate/shared_style_attributes.rb +18 -1
- data/lib/germinate/{process.rb → shell_process.rb} +27 -8
- data/lib/germinate/shell_publisher.rb +19 -0
- data/lib/germinate/simple_publisher.rb +7 -0
- data/lib/germinate/source_file.rb +41 -0
- data/lib/germinate/text_transforms.rb +38 -9
- data/lib/germinate/transform_process.rb +25 -0
- data/lib/germinate/variable.rb +23 -0
- data/sample.rb +14 -0
- data/spec/germinate/application_spec.rb +18 -1
- data/spec/germinate/article_editor_spec.rb +3 -3
- data/spec/germinate/code_hunk_spec.rb +28 -0
- data/spec/germinate/file_hunk_spec.rb +1 -0
- data/spec/germinate/hunk_spec.rb +1 -0
- data/spec/germinate/insertion_spec.rb +2 -1
- data/spec/germinate/librarian_spec.rb +280 -85
- data/spec/germinate/pipeline_spec.rb +10 -0
- data/spec/germinate/process_spec.rb +31 -6
- data/spec/germinate/publisher_spec.rb +130 -0
- data/spec/germinate/reader_spec.rb +58 -2
- data/spec/germinate/selector_spec.rb +34 -14
- data/spec/germinate/shell_publisher_spec.rb +61 -0
- data/spec/germinate/source_file_spec.rb +99 -0
- data/spec/germinate/text_hunk_spec.rb +45 -0
- data/spec/germinate/text_transforms_spec.rb +90 -2
- data/spec/germinate/transform_process_spec.rb +50 -0
- data/spec/germinate/variable_spec.rb +14 -0
- metadata +19 -7
- data/lib/germinate/article_formatter.rb +0 -75
- data/spec/germinate/article_formatter_spec.rb +0 -153
data/examples/basic.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# :PUBLISHER: source, gist
|
1
2
|
# A basic example of a Germinate article.
|
2
3
|
#
|
3
4
|
# This text is "front matter" and will not be included in the final article.
|
@@ -48,41 +49,41 @@ hello
|
|
48
49
|
# If it doesn't find a %f, Germinate will pipe the source sample into the
|
49
50
|
# command on its STDIN.
|
50
51
|
#
|
51
|
-
# Here's the result of
|
52
|
+
# Here's the result of :INSERT: @hello|fred
|
52
53
|
# :INSERT: @hello|fred
|
53
54
|
#
|
54
55
|
# Here's the result of :INSERT: @hello|jane
|
55
56
|
# :INSERT: @hello|jane
|
56
57
|
#
|
57
58
|
# We can even chain processes together. Here's the result of
|
58
|
-
#
|
59
|
+
# :INSERT: @hello|jane|quote
|
59
60
|
# :INSERT: @hello|jane|quote
|
60
61
|
#
|
61
62
|
# It's not necessary to quote whole code samples. We can select specific lines
|
62
63
|
# to excerpt using more advanced selectors.
|
63
64
|
#
|
64
65
|
# Select a single line
|
65
|
-
#
|
66
|
+
# :INSERT: @foo:2
|
66
67
|
# :INSERT: @foo:2
|
67
68
|
#
|
68
69
|
# Select an inclusive range
|
69
|
-
#
|
70
|
+
# :INSERT: @foo:2..4
|
70
71
|
# :INSERT: @foo:2..4
|
71
72
|
#
|
72
73
|
# Select an exclusive range
|
73
|
-
#
|
74
|
+
# :INSERT: @foo:1...3
|
74
75
|
# :INSERT: @foo:1...3
|
75
76
|
#
|
76
77
|
# Select by starting line and length
|
77
|
-
#
|
78
|
+
# :INSERT: @foo:4,4
|
78
79
|
# :INSERT: @foo:4,4
|
79
80
|
#
|
80
81
|
# Select by starting and ending regular expressions
|
81
|
-
#
|
82
|
+
# :INSERT: @foo:/do_stuff/../end/
|
82
83
|
# :INSERT: @foo:/do_stuff/../end/
|
83
84
|
#
|
84
85
|
# Select by regex and length
|
85
|
-
#
|
86
|
+
# :INSERT: @foo:/attr_reader/,3
|
86
87
|
# :INSERT: @foo:/attr_reader/,3
|
87
88
|
#
|
88
89
|
# :SAMPLE: foo
|
@@ -99,7 +100,7 @@ end
|
|
99
100
|
|
100
101
|
# :TEXT:
|
101
102
|
# Finally, we can include all of the code samples in a single chunk with
|
102
|
-
#
|
103
|
+
# :INSERT: $CODE
|
103
104
|
# :INSERT: $CODE
|
104
105
|
#
|
105
106
|
# There are some other special section names, such as $SOURCE and $TEXT. See
|
@@ -116,3 +117,7 @@ end
|
|
116
117
|
# germ select -s <selector>
|
117
118
|
#
|
118
119
|
# Enjoy!
|
120
|
+
#
|
121
|
+
# 1 2 3 5 6 7 8
|
122
|
+
|
123
|
+
# :SET: 'GIST_ID', '150391'
|
data/examples/short.rb
CHANGED
@@ -10,7 +10,7 @@ Feature: author formats article
|
|
10
10
|
# :TEXT:
|
11
11
|
# This is my article
|
12
12
|
|
13
|
-
this is my code
|
13
|
+
this is my code
|
14
14
|
"""
|
15
15
|
When I run the format command on the article
|
16
16
|
Then the output should be as follows:
|
@@ -27,7 +27,7 @@ Feature: author formats article
|
|
27
27
|
# :TEXT:
|
28
28
|
# This is my article
|
29
29
|
|
30
|
-
this is my code
|
30
|
+
this is my code
|
31
31
|
"""
|
32
32
|
When I run the format command on the article
|
33
33
|
Then the output should be as follows:
|
@@ -47,7 +47,7 @@ Feature: author formats article
|
|
47
47
|
# This is my article
|
48
48
|
|
49
49
|
# :SAMPLE: SECTION1, { brackets: [ '[code]', '[/code]' ] }
|
50
|
-
this is my code
|
50
|
+
this is my code
|
51
51
|
"""
|
52
52
|
When I run the format command on the article
|
53
53
|
Then the output should be as follows:
|
@@ -1,3 +1,5 @@
|
|
1
|
+
Note: this is a debug feature and its not worth specifying until it gets a bit
|
2
|
+
more stable.
|
1
3
|
Feature: author lists information
|
2
4
|
|
3
5
|
As an author
|
@@ -41,5 +43,6 @@ Feature: author lists information
|
|
41
43
|
Then the output should be as follows:
|
42
44
|
"""
|
43
45
|
frob
|
46
|
+
_transform
|
44
47
|
munge
|
45
48
|
"""
|
@@ -3,3 +3,55 @@ Feature: author publishes article
|
|
3
3
|
As an author
|
4
4
|
I want to publish my article as a blog post
|
5
5
|
So that the world can see it
|
6
|
+
|
7
|
+
Scenario: using a shell publisher
|
8
|
+
Given an article with the contents:
|
9
|
+
"""
|
10
|
+
# :PUBLISHER: source, shell, { command: "quoter %f", select: '$SOURCE' }
|
11
|
+
# :BRACKET_CODE: "<pre>", "</pre>"
|
12
|
+
# :TEXT:
|
13
|
+
# This is the text
|
14
|
+
# :SAMPLE:
|
15
|
+
def hello
|
16
|
+
# ...
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
When I run the command "germ publish source --debug " on the article
|
20
|
+
Then the output should be as follows:
|
21
|
+
"""
|
22
|
+
> # :PUBLISHER: source, shell, { command: "quoter %f", select: '$SOURCE' }
|
23
|
+
> # :BRACKET_CODE: "<pre>", "</pre>"
|
24
|
+
> # :TEXT:
|
25
|
+
> # This is the text
|
26
|
+
> # :SAMPLE:
|
27
|
+
> def hello
|
28
|
+
> # ...
|
29
|
+
> end
|
30
|
+
"""
|
31
|
+
|
32
|
+
Scenario: using a shell publisher with a pipeline
|
33
|
+
Given an article with the contents:
|
34
|
+
"""
|
35
|
+
# :PROCESS: quote, "quoter %f"
|
36
|
+
# :PUBLISHER: source, shell, { command: "quoter %f", pipeline: quote, select: '$SOURCE' }
|
37
|
+
# :BRACKET_CODE: "<pre>", "</pre>"
|
38
|
+
# :TEXT:
|
39
|
+
# This is the text
|
40
|
+
# :SAMPLE:
|
41
|
+
def hello
|
42
|
+
# ...
|
43
|
+
end
|
44
|
+
"""
|
45
|
+
When I run the command "germ publish source --debug " on the article
|
46
|
+
Then the output should be as follows:
|
47
|
+
"""
|
48
|
+
> > # :PROCESS: quote, "quoter %f"
|
49
|
+
> > # :PUBLISHER: source, shell, { command: "quoter %f", pipeline: quote, select: '$SOURCE' }
|
50
|
+
> > # :BRACKET_CODE: "<pre>", "</pre>"
|
51
|
+
> > # :TEXT:
|
52
|
+
> > # This is the text
|
53
|
+
> > # :SAMPLE:
|
54
|
+
> > def hello
|
55
|
+
> > # ...
|
56
|
+
> > end
|
57
|
+
"""
|
@@ -18,7 +18,7 @@ Feature: author experiments with selectors
|
|
18
18
|
|
19
19
|
# :PROCESS: quote, "quoter %f"
|
20
20
|
"""
|
21
|
-
When I run the command "germ select
|
21
|
+
When I run the command "germ select '@X:2..3|quote'" on the article
|
22
22
|
Then the output should be as follows:
|
23
23
|
"""
|
24
24
|
> X 2
|
@@ -0,0 +1,88 @@
|
|
1
|
+
Feature: author sets variables
|
2
|
+
|
3
|
+
As an author
|
4
|
+
I want to set named values in my article
|
5
|
+
So that I can re-use them in processes, etc.
|
6
|
+
|
7
|
+
Scenario: setting a new variable
|
8
|
+
Given an article with the contents:
|
9
|
+
"""
|
10
|
+
# :TEXT:
|
11
|
+
# This is some text
|
12
|
+
# :SET: FOO, 123
|
13
|
+
"""
|
14
|
+
When I run the command "germ list variables --debug" on the article
|
15
|
+
Then the output should be as follows:
|
16
|
+
"""
|
17
|
+
FOO 123
|
18
|
+
"""
|
19
|
+
When I run the command "germ set MAGIC_WORD xyzzy --debug" on the article
|
20
|
+
Then the article contents should be:
|
21
|
+
"""
|
22
|
+
# :TEXT:
|
23
|
+
# This is some text
|
24
|
+
# :SET: FOO, 123
|
25
|
+
# :SET: 'MAGIC_WORD', 'xyzzy'
|
26
|
+
|
27
|
+
"""
|
28
|
+
And the article backup contents should be:
|
29
|
+
"""
|
30
|
+
# :TEXT:
|
31
|
+
# This is some text
|
32
|
+
# :SET: FOO, 123
|
33
|
+
"""
|
34
|
+
When I run the command "germ list variables --debug" on the article
|
35
|
+
Then the output should be as follows:
|
36
|
+
"""
|
37
|
+
FOO 123
|
38
|
+
MAGIC_WORD xyzzy
|
39
|
+
"""
|
40
|
+
|
41
|
+
Scenario: changing an existing variable
|
42
|
+
Given an article with the contents:
|
43
|
+
"""
|
44
|
+
# :PUBLISHER: env, shell, { command: 'echo %f > /dev/null; echo $FOO' }
|
45
|
+
# :TEXT:
|
46
|
+
# This is some text
|
47
|
+
# :SET: FOO, 123
|
48
|
+
# This is more text
|
49
|
+
"""
|
50
|
+
When I run the command "germ list variables --debug" on the article
|
51
|
+
Then the output should be as follows:
|
52
|
+
"""
|
53
|
+
FOO 123
|
54
|
+
"""
|
55
|
+
When I run the command "germ publish env --debug" on the article
|
56
|
+
Then the output should be as follows:
|
57
|
+
"""
|
58
|
+
123
|
59
|
+
"""
|
60
|
+
When I run the command "germ set FOO 456 --debug" on the article
|
61
|
+
Then the article contents should be:
|
62
|
+
"""
|
63
|
+
# :PUBLISHER: env, shell, { command: 'echo %f > /dev/null; echo $FOO' }
|
64
|
+
# :TEXT:
|
65
|
+
# This is some text
|
66
|
+
# :SET: 'FOO', '456'
|
67
|
+
# This is more text
|
68
|
+
|
69
|
+
"""
|
70
|
+
And the article backup contents should be:
|
71
|
+
"""
|
72
|
+
# :PUBLISHER: env, shell, { command: 'echo %f > /dev/null; echo $FOO' }
|
73
|
+
# :TEXT:
|
74
|
+
# This is some text
|
75
|
+
# :SET: FOO, 123
|
76
|
+
# This is more text
|
77
|
+
|
78
|
+
"""
|
79
|
+
When I run the command "germ list variables --debug" on the article
|
80
|
+
Then the output should be as follows:
|
81
|
+
"""
|
82
|
+
FOO 456
|
83
|
+
"""
|
84
|
+
When I run the command "germ publish env --debug" on the article
|
85
|
+
Then the output should be as follows:
|
86
|
+
"""
|
87
|
+
456
|
88
|
+
"""
|
@@ -1,3 +1,5 @@
|
|
1
|
+
Note: this is a debug feature and its not worth specifying until it gets a bit
|
2
|
+
more stable.
|
1
3
|
Feature: author views information
|
2
4
|
|
3
5
|
As an author
|
@@ -28,6 +30,8 @@ Feature: author views information
|
|
28
30
|
Then the output should be as follows:
|
29
31
|
"""
|
30
32
|
# Anonymous section 1
|
33
|
+
|
34
|
+
Insertion[@SECTION1]
|
31
35
|
"""
|
32
36
|
When I run the command "germ show --section=A" on the article
|
33
37
|
Then the output should be as follows:
|
@@ -10,10 +10,10 @@ b_line_2 = 2
|
|
10
10
|
|
11
11
|
# :TEXT:
|
12
12
|
# We can paste in all the code:
|
13
|
-
# :INSERT: $CODE
|
13
|
+
# :INSERT: $CODE, { disable_transforms: true }
|
14
14
|
#
|
15
15
|
# Or all the text:
|
16
|
-
# :INSERT: $TEXT
|
16
|
+
# :INSERT: $TEXT, { disable_transforms: true }
|
17
17
|
#
|
18
18
|
# Or the entire source file
|
19
|
-
# :INSERT: $SOURCE
|
19
|
+
# :INSERT: $SOURCE, { disable_transforms: true }
|
@@ -7,12 +7,16 @@ a_line_4 = 4
|
|
7
7
|
b_line_1 = 1
|
8
8
|
b_line_2 = 2
|
9
9
|
|
10
|
+
|
10
11
|
Or all the text:
|
11
12
|
# We can paste in all the code:
|
12
|
-
|
13
|
+
Insertion[$CODE(<Unknown>)]
|
14
|
+
#
|
13
15
|
# Or all the text:
|
16
|
+
Insertion[$TEXT(<Unknown>)]
|
14
17
|
#
|
15
18
|
# Or the entire source file
|
19
|
+
Insertion[$SOURCE(<Unknown>)]
|
16
20
|
|
17
21
|
Or the entire source file
|
18
22
|
# :SAMPLE: A
|
@@ -27,10 +31,10 @@ b_line_2 = 2
|
|
27
31
|
|
28
32
|
# :TEXT:
|
29
33
|
# We can paste in all the code:
|
30
|
-
# :INSERT: $CODE
|
31
|
-
#
|
34
|
+
# :INSERT: $CODE, { disable_transforms: true }
|
35
|
+
#
|
32
36
|
# Or all the text:
|
33
|
-
# :INSERT: $TEXT
|
37
|
+
# :INSERT: $TEXT, { disable_transforms: true }
|
34
38
|
#
|
35
39
|
# Or the entire source file
|
36
|
-
# :INSERT: $SOURCE
|
40
|
+
# :INSERT: $SOURCE, { disable_transforms: true }
|
@@ -31,3 +31,12 @@ end
|
|
31
31
|
Then /^the output should be as follows:$/ do |example_output|
|
32
32
|
@output.strip.should == example_output.strip
|
33
33
|
end
|
34
|
+
|
35
|
+
Then /^the article contents should be:$/ do |contents|
|
36
|
+
@filename.read.strip.should == contents.strip
|
37
|
+
end
|
38
|
+
|
39
|
+
Then /^the article backup contents should be:$/ do |contents|
|
40
|
+
Pathname(@filename.to_s + ".germ.bak").read.should == contents
|
41
|
+
end
|
42
|
+
|
data/germinate.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{germinate}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Avdi Grimm"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-21}
|
10
10
|
s.default_executable = %q{germ}
|
11
11
|
s.description = %q{Germinate is a tool for writing about code. With Germinate, the source code IS the article. For example, given the following source code: # #!/usr/bin/env ruby # :BRACKET_CODE: <pre>, </pre> # :PROCESS: ruby, "ruby %f" # :SAMPLE: hello def hello(who) puts "Hello, #{who}" end hello("World") # :TEXT: # Check out my amazing program! Here's the hello method: # :INSERT: @hello:/def/../end/ # And here's the output: # :INSERT: @hello|ruby When we run the <tt>germ format</tt> command the following output is generated: Check out my amazing program! Here's the hello method: <pre> def hello(who) puts "Hello, #{who}" end </pre> And here's the output: <pre> Hello, World </pre> To get a better idea of how this works, please take a look at link:examples/basic.rb, or run: germ generate > basic.rb To generate an example article to play with. Germinate is particularly useful for writing articles, such as blog posts, which contain code excerpts. Instead of forcing you to keep a source code file and an article document in sync throughout the editing process, the Germinate motto is "The source code IS the article". Specially marked comment sections in your code file become the article text. Wherever you need to reference the source code in the article, use insertion directives to tell Germinate what parts of the code to excerpt. An advanced selector syntax enables you to be very specific about which lines of code you want to insert. If you also want to show the output of your code, Germinate has you covered. Special "process" directives enable you to define arbitrary commands which can be run on your code. The output of the command then becomes the excerpt text. You can define an arbitrary number of processes and have different excerpts showing the same code as processed by different commands. You can even string processes together into pipelines. Development of Germinate is graciously sponsored by Devver, purveyor of fine cloud-based services to busy Ruby developers. If you like this tool please check them out at http://devver.net.}
|
12
12
|
s.email = %q{avdi@avdi.org}
|
13
13
|
s.executables = ["germ"]
|
14
14
|
s.extra_rdoc_files = ["History.txt", "README.rdoc", "bin/germ"]
|
15
|
-
s.files = [".gitignore", "History.txt", "README.rdoc", "Rakefile", "TODO", "bin/germ", "cucumber.yml", "examples/basic.rb", "examples/short.rb", "features/author-formats-article.feature", "features/author-lists-info.
|
15
|
+
s.files = [".gitignore", "History.txt", "README.rdoc", "Rakefile", "TODO", "bin/germ", "cucumber.yml", "examples/basic.rb", "examples/short.rb", "features/author-formats-article.feature", "features/author-lists-info.pending_feature", "features/author-publishes-article-source.feature", "features/author-publishes-article.feature", "features/author-republishes-article.feature", "features/author-selects-hunks.feature", "features/author-sets-variables.feature", "features/author-updates-article-source.feature", "features/author-views-stuff.pending_feature", "features/bin/quoter", "features/bin/sorter", "features/example_articles/bracketing.rb", "features/example_articles/escaping.txt", "features/example_articles/excerpt_output.rb", "features/example_articles/hello.rb", "features/example_articles/pipelines.txt", "features/example_articles/regexen.rb", "features/example_articles/sample_offsets.rb", "features/example_articles/specials.rb", "features/example_articles/stderr.rb", "features/example_articles/wrapping.rb", "features/example_output/bracketing.out", "features/example_output/code_samples.txt", "features/example_output/escaping.out", "features/example_output/excerpt_output.out", "features/example_output/hello.txt", "features/example_output/pipelines.out", "features/example_output/regexen.txt", "features/example_output/sample_offsets.txt", "features/example_output/specials.txt", "features/example_output/stderr.out", "features/example_output/wrapping.txt", "features/step_definitions/germinate.rb", "features/support/env.rb", "germinate.gemspec", "lib/germinate.rb", "lib/germinate/application.rb", "lib/germinate/article_editor.rb", "lib/germinate/formatter.rb", "lib/germinate/hunk.rb", "lib/germinate/implicit_insertion.rb", "lib/germinate/insertion.rb", "lib/germinate/librarian.rb", "lib/germinate/origin.rb", "lib/germinate/pipeline.rb", "lib/germinate/publisher.rb", "lib/germinate/reader.rb", "lib/germinate/selector.rb", "lib/germinate/shared_style_attributes.rb", "lib/germinate/shell_process.rb", "lib/germinate/shell_publisher.rb", "lib/germinate/simple_publisher.rb", "lib/germinate/source_file.rb", "lib/germinate/text_transforms.rb", "lib/germinate/transform_process.rb", "lib/germinate/variable.rb", "sample.rb", "spec/germinate/application_spec.rb", "spec/germinate/article_editor_spec.rb", "spec/germinate/code_hunk_spec.rb", "spec/germinate/file_hunk_spec.rb", "spec/germinate/formatter_spec.rb", "spec/germinate/hunk_spec.rb", "spec/germinate/implicit_insertion_spec.rb", "spec/germinate/insertion_spec.rb", "spec/germinate/librarian_spec.rb", "spec/germinate/pipeline_spec.rb", "spec/germinate/process_spec.rb", "spec/germinate/publisher_spec.rb", "spec/germinate/reader_spec.rb", "spec/germinate/selector_spec.rb", "spec/germinate/shell_publisher_spec.rb", "spec/germinate/source_file_spec.rb", "spec/germinate/text_hunk_spec.rb", "spec/germinate/text_transforms_spec.rb", "spec/germinate/transform_process_spec.rb", "spec/germinate/variable_spec.rb", "spec/germinate_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/ann.rake", "tasks/bones.rake", "tasks/cucumber.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake", "tasks/zentest.rake", "test/test_germinate.rb"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/devver/germinate/}
|
18
18
|
s.rdoc_options = ["--main", "README.rdoc"]
|
data/lib/germinate.rb
CHANGED
@@ -1,54 +1,97 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
# The Application ties all the other componts together. It has public methods
|
2
4
|
# roughly corresponding commands that the 'germ' command-line tool supports.
|
3
5
|
class Germinate::Application
|
4
6
|
attr_writer :formatter
|
5
7
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize(output, errors)
|
9
|
+
@output = output
|
10
|
+
@error_output = errors
|
11
|
+
@log = Germinate.logger
|
12
|
+
@plugins = []
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
# Search Rubygems for Germinate plugins and load them
|
16
|
+
def load_plugins!
|
17
|
+
$LOAD_PATH.each do |dir|
|
18
|
+
plugin_init = Pathname(dir) + 'germinate_plugin_v0_init.rb'
|
19
|
+
if plugin_init.readable?
|
20
|
+
load_plugin!(plugin_init.to_s)
|
21
|
+
end
|
14
22
|
end
|
15
|
-
|
16
|
-
|
17
|
-
formatter.format!(hunk)
|
23
|
+
Gem.find_files('germinate_plugin_v0_init').each do |file|
|
24
|
+
load_plugin!(file)
|
18
25
|
end
|
19
|
-
formatter.finish!
|
20
26
|
end
|
21
27
|
|
22
|
-
def
|
28
|
+
def format(source, path)
|
23
29
|
librarian = load_librarian(source, path)
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
if things_to_list.include?(:samples)
|
28
|
-
output.puts(librarian.sample_names.join("\n"))
|
29
|
-
end
|
30
|
-
if things_to_list.include?(:processes)
|
31
|
-
output.puts(librarian.process_names.join("\n"))
|
32
|
-
end
|
30
|
+
publisher = Germinate::SimplePublisher.new("simple", librarian)
|
31
|
+
publisher.publish!(@output)
|
33
32
|
end
|
34
33
|
|
35
|
-
def
|
34
|
+
def list(source, path, collection)
|
36
35
|
librarian = load_librarian(source, path)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
output.puts(
|
36
|
+
case collection
|
37
|
+
when "sections"
|
38
|
+
@output.puts(librarian.section_names.join("\n"))
|
39
|
+
when "samples"
|
40
|
+
@output.puts(librarian.sample_names.join("\n"))
|
41
|
+
when "processes"
|
42
|
+
@output.puts(librarian.process_names.join("\n"))
|
43
|
+
when "publishers"
|
44
|
+
@output.puts(*librarian.publisher_names)
|
45
|
+
when "all_publishers"
|
46
|
+
Germinate::Publisher.registered_publishers.keys do |p|
|
47
|
+
@output.puts(p)
|
48
|
+
end
|
49
|
+
when "variables"
|
50
|
+
librarian.variables.each_pair do |name, value|
|
51
|
+
@output.puts("%-20s %s" % [name, value.to_s])
|
52
|
+
end
|
53
|
+
when "plugins"
|
54
|
+
@plugins.each do |plugin|
|
55
|
+
puts(plugin)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
raise "I don't know how to list '#{collection}'"
|
42
59
|
end
|
43
|
-
|
44
|
-
|
60
|
+
end
|
61
|
+
|
62
|
+
def show(source, path, item_type, item)
|
63
|
+
librarian = load_librarian(source, path)
|
64
|
+
case item_type
|
65
|
+
when "section"
|
66
|
+
@output.puts(librarian.section(item))
|
67
|
+
when "sample"
|
68
|
+
@output.puts(librarian.sample(item))
|
69
|
+
when "process"
|
70
|
+
@output.puts(librarian.process(item).command)
|
71
|
+
when "publisher"
|
72
|
+
@output.puts(librarian.publisher(item))
|
73
|
+
else
|
74
|
+
raise "I don't know how to show '#{item_type}'"
|
45
75
|
end
|
46
76
|
end
|
47
77
|
|
48
|
-
def select(source, path, selector,
|
78
|
+
def select(source, path, selector, options, origin="command line")
|
49
79
|
librarian = load_librarian(source, path)
|
50
|
-
output.puts(*librarian[selector])
|
80
|
+
@output.puts(*librarian[selector, origin, options])
|
51
81
|
end
|
82
|
+
|
83
|
+
def publish(source, path, publisher, options={})
|
84
|
+
librarian = load_librarian(source, path)
|
85
|
+
librarian.publisher(publisher).publish!(@output, options)
|
86
|
+
librarian.store_changes!
|
87
|
+
end
|
88
|
+
|
89
|
+
def set(source, path, name, value)
|
90
|
+
librarian = load_librarian(source, path)
|
91
|
+
librarian.variables[name] = value
|
92
|
+
librarian.store_changes!
|
93
|
+
end
|
94
|
+
|
52
95
|
private
|
53
96
|
|
54
97
|
def load_librarian(source, path)
|
@@ -59,4 +102,12 @@ class Germinate::Application
|
|
59
102
|
end
|
60
103
|
librarian
|
61
104
|
end
|
105
|
+
|
106
|
+
def load_plugin!(file)
|
107
|
+
unless @plugins.include?(file)
|
108
|
+
@log.debug "Loading plugin: #{file}"
|
109
|
+
Kernel.load(file)
|
110
|
+
@plugins << File.dirname(file)
|
111
|
+
end
|
112
|
+
end
|
62
113
|
end
|