germinate 1.2.0

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.
Files changed (105) hide show
  1. data/.gitignore +2 -0
  2. data/History.txt +26 -0
  3. data/README.rdoc +152 -0
  4. data/Rakefile +43 -0
  5. data/TODO +140 -0
  6. data/bin/germ +260 -0
  7. data/cucumber.yml +2 -0
  8. data/examples/basic.rb +123 -0
  9. data/examples/short.rb +19 -0
  10. data/features/author-formats-article.feature +111 -0
  11. data/features/author-lists-info.pending_feature +48 -0
  12. data/features/author-publishes-article-source.feature +5 -0
  13. data/features/author-publishes-article.feature +57 -0
  14. data/features/author-republishes-article.feature +5 -0
  15. data/features/author-selects-hunks.feature +26 -0
  16. data/features/author-sets-variables.feature +88 -0
  17. data/features/author-updates-article-source.feature +5 -0
  18. data/features/author-views-stuff.pending_feature +52 -0
  19. data/features/bin/quoter +6 -0
  20. data/features/bin/sorter +4 -0
  21. data/features/example_articles/bracketing.rb +27 -0
  22. data/features/example_articles/escaping.txt +13 -0
  23. data/features/example_articles/excerpt_output.rb +16 -0
  24. data/features/example_articles/hello.rb +9 -0
  25. data/features/example_articles/pipelines.txt +25 -0
  26. data/features/example_articles/regexen.rb +24 -0
  27. data/features/example_articles/sample_offsets.rb +18 -0
  28. data/features/example_articles/specials.rb +19 -0
  29. data/features/example_articles/stderr.rb +10 -0
  30. data/features/example_articles/wrapping.rb +8 -0
  31. data/features/example_output/bracketing.out +23 -0
  32. data/features/example_output/code_samples.txt +186 -0
  33. data/features/example_output/escaping.out +5 -0
  34. data/features/example_output/excerpt_output.out +6 -0
  35. data/features/example_output/hello.txt +1 -0
  36. data/features/example_output/pipelines.out +28 -0
  37. data/features/example_output/regexen.txt +22 -0
  38. data/features/example_output/sample_offsets.txt +15 -0
  39. data/features/example_output/specials.txt +40 -0
  40. data/features/example_output/stderr.out +3 -0
  41. data/features/example_output/wrapping.txt +3 -0
  42. data/features/step_definitions/germinate.rb +42 -0
  43. data/features/support/env.rb +20 -0
  44. data/germinate.gemspec +55 -0
  45. data/lib/germinate.rb +54 -0
  46. data/lib/germinate/application.rb +113 -0
  47. data/lib/germinate/article_editor.rb +20 -0
  48. data/lib/germinate/formatter.rb +119 -0
  49. data/lib/germinate/hunk.rb +183 -0
  50. data/lib/germinate/implicit_insertion.rb +9 -0
  51. data/lib/germinate/insertion.rb +29 -0
  52. data/lib/germinate/librarian.rb +293 -0
  53. data/lib/germinate/origin.rb +5 -0
  54. data/lib/germinate/pipeline.rb +13 -0
  55. data/lib/germinate/publisher.rb +57 -0
  56. data/lib/germinate/reader.rb +266 -0
  57. data/lib/germinate/selector.rb +136 -0
  58. data/lib/germinate/shared_style_attributes.rb +54 -0
  59. data/lib/germinate/shell_process.rb +94 -0
  60. data/lib/germinate/shell_publisher.rb +19 -0
  61. data/lib/germinate/simple_publisher.rb +7 -0
  62. data/lib/germinate/source_file.rb +41 -0
  63. data/lib/germinate/text_transforms.rb +119 -0
  64. data/lib/germinate/transform_process.rb +25 -0
  65. data/lib/germinate/variable.rb +23 -0
  66. data/sample.rb +14 -0
  67. data/spec/germinate/application_spec.rb +31 -0
  68. data/spec/germinate/article_editor_spec.rb +97 -0
  69. data/spec/germinate/code_hunk_spec.rb +73 -0
  70. data/spec/germinate/file_hunk_spec.rb +28 -0
  71. data/spec/germinate/formatter_spec.rb +160 -0
  72. data/spec/germinate/hunk_spec.rb +84 -0
  73. data/spec/germinate/implicit_insertion_spec.rb +33 -0
  74. data/spec/germinate/insertion_spec.rb +19 -0
  75. data/spec/germinate/librarian_spec.rb +555 -0
  76. data/spec/germinate/pipeline_spec.rb +34 -0
  77. data/spec/germinate/process_spec.rb +105 -0
  78. data/spec/germinate/publisher_spec.rb +130 -0
  79. data/spec/germinate/reader_spec.rb +385 -0
  80. data/spec/germinate/selector_spec.rb +121 -0
  81. data/spec/germinate/shell_publisher_spec.rb +61 -0
  82. data/spec/germinate/source_file_spec.rb +99 -0
  83. data/spec/germinate/text_hunk_spec.rb +98 -0
  84. data/spec/germinate/text_transforms_spec.rb +242 -0
  85. data/spec/germinate/transform_process_spec.rb +50 -0
  86. data/spec/germinate/variable_spec.rb +14 -0
  87. data/spec/germinate_spec.rb +8 -0
  88. data/spec/spec.opts +1 -0
  89. data/spec/spec_helper.rb +16 -0
  90. data/tasks/ann.rake +80 -0
  91. data/tasks/bones.rake +20 -0
  92. data/tasks/cucumber.rake +5 -0
  93. data/tasks/gem.rake +201 -0
  94. data/tasks/git.rake +40 -0
  95. data/tasks/notes.rake +27 -0
  96. data/tasks/post_load.rake +34 -0
  97. data/tasks/rdoc.rake +51 -0
  98. data/tasks/rubyforge.rake +55 -0
  99. data/tasks/setup.rb +292 -0
  100. data/tasks/spec.rake +54 -0
  101. data/tasks/svn.rake +47 -0
  102. data/tasks/test.rake +40 -0
  103. data/tasks/zentest.rake +36 -0
  104. data/test/test_germinate.rb +0 -0
  105. metadata +228 -0
@@ -0,0 +1,2 @@
1
+ autotest: --no-color --format pretty
2
+ autotest-all: --no-color --format pretty
@@ -0,0 +1,123 @@
1
+ # :PUBLISHER: source, gist
2
+ # A basic example of a Germinate article.
3
+ #
4
+ # This text is "front matter" and will not be included in the final article.
5
+ # The article doesn't begin until the first text directive.
6
+ #
7
+ # Let's set up code bracketing so that code excerpts will be surrounded by HTML
8
+ # <pre>...</pre> tags.
9
+ #
10
+ # :BRACKET_CODE: <pre>, </pre>
11
+ #
12
+ # :TEXT:
13
+ # This is the first line of the article text. For the formatted article,
14
+ # Germinate will remove the comment prefixes ("# ") and join paragraphs into
15
+ # single lines.
16
+ #
17
+ # We're coming up on our first code section. If some code immediately follows a
18
+ # text section it will automatically be inserted into the formatted article
19
+ # text.
20
+ def my_func
21
+ # ...
22
+ end
23
+ # :END:
24
+ #
25
+ # The END directive above ends that particular code sample. This text will not
26
+ # be included in the final article.
27
+ #
28
+ # We don't want to have to write our source code in the order it appears in
29
+ # the article. Let's define a named code sample.
30
+ #
31
+ # :SAMPLE: hello
32
+ def hello
33
+ puts "Hello, #{ARGV[0]}"
34
+ end
35
+ hello
36
+
37
+ # :TEXT:
38
+ # We're back in the article text now. Let's insert our named sample now.
39
+ # :INSERT: @hello
40
+ #
41
+ # Now lets define some processes and experiment with running the sample through
42
+ # them.
43
+ #
44
+ # :PROCESS: fred, "ruby %f Fred"
45
+ # :PROCESS: jane, "ruby %f Jane"
46
+ # :PROCESS: quote, "ruby -n -e 'puts \"> #{$_}\"'"
47
+ #
48
+ # Note that the "quote" process has no %f placeholder for the filename.
49
+ # If it doesn't find a %f, Germinate will pipe the source sample into the
50
+ # command on its STDIN.
51
+ #
52
+ # Here's the result of :INSERT: @hello|fred
53
+ # :INSERT: @hello|fred
54
+ #
55
+ # Here's the result of :INSERT: @hello|jane
56
+ # :INSERT: @hello|jane
57
+ #
58
+ # We can even chain processes together. Here's the result of
59
+ # :INSERT: @hello|jane|quote
60
+ # :INSERT: @hello|jane|quote
61
+ #
62
+ # It's not necessary to quote whole code samples. We can select specific lines
63
+ # to excerpt using more advanced selectors.
64
+ #
65
+ # Select a single line
66
+ # :INSERT: @foo:2
67
+ # :INSERT: @foo:2
68
+ #
69
+ # Select an inclusive range
70
+ # :INSERT: @foo:2..4
71
+ # :INSERT: @foo:2..4
72
+ #
73
+ # Select an exclusive range
74
+ # :INSERT: @foo:1...3
75
+ # :INSERT: @foo:1...3
76
+ #
77
+ # Select by starting line and length
78
+ # :INSERT: @foo:4,4
79
+ # :INSERT: @foo:4,4
80
+ #
81
+ # Select by starting and ending regular expressions
82
+ # :INSERT: @foo:/do_stuff/../end/
83
+ # :INSERT: @foo:/do_stuff/../end/
84
+ #
85
+ # Select by regex and length
86
+ # :INSERT: @foo:/attr_reader/,3
87
+ # :INSERT: @foo:/attr_reader/,3
88
+ #
89
+ # :SAMPLE: foo
90
+ class Foo
91
+ attr_reader :bar
92
+ attr_reader :baz
93
+ attr_reader :buz
94
+
95
+ def do_stuff
96
+ # ...
97
+ end
98
+ end
99
+ # :END:
100
+
101
+ # :TEXT:
102
+ # Finally, we can include all of the code samples in a single chunk with
103
+ # :INSERT: $CODE
104
+ # :INSERT: $CODE
105
+ #
106
+ # There are some other special section names, such as $SOURCE and $TEXT. See
107
+ # the Germinate documentation for more.
108
+ #
109
+ # :CUT:
110
+ #
111
+ # You can format this article for publishing by running:
112
+ #
113
+ # germ format <filename>
114
+ #
115
+ # If you want to experiment with the selector syntax, try:
116
+ #
117
+ # germ select -s <selector>
118
+ #
119
+ # Enjoy!
120
+ #
121
+ # 1 2 3 5 6 7 8
122
+
123
+ # :SET: 'GIST_ID', '150391'
@@ -0,0 +1,19 @@
1
+ # #!/usr/bin/env ruby
2
+ # :PUBLISHER: source, gist
3
+ # :BRACKET_CODE: <pre>, </pre>
4
+ # :PROCESS: ruby, "ruby %f"
5
+
6
+ # :SAMPLE: hello
7
+ def hello(who)
8
+ puts "Hello, #{who}"
9
+ end
10
+
11
+ hello("World")
12
+
13
+ # :TEXT:
14
+ # Check out my amazing program! Here's the hello method:
15
+ # :INSERT: @hello:/def/../end/
16
+
17
+ # And here's the output:
18
+ # :INSERT: @hello|ruby
19
+ # :SET: 'GIST_ID', '150868'
@@ -0,0 +1,111 @@
1
+ Feature: author formats article
2
+
3
+ As an author
4
+ I want to format my articles
5
+ So that they can be published
6
+
7
+ Scenario: format text followed by code
8
+ Given an article with the contents:
9
+ """
10
+ # :TEXT:
11
+ # This is my article
12
+
13
+ this is my code
14
+ """
15
+ When I run the format command on the article
16
+ Then the output should be as follows:
17
+ """
18
+ This is my article
19
+
20
+ this is my code
21
+ """
22
+
23
+ Scenario: format code with bracketing
24
+ Given an article with the contents:
25
+ """
26
+ # :BRACKET_CODE: "<pre>", "</pre>"
27
+ # :TEXT:
28
+ # This is my article
29
+
30
+ this is my code
31
+ """
32
+ When I run the format command on the article
33
+ Then the output should be as follows:
34
+ """
35
+ This is my article
36
+
37
+ <pre>
38
+ this is my code
39
+ </pre>
40
+ """
41
+
42
+ Scenario: override default bracketing
43
+ Given an article with the contents:
44
+ """
45
+ # :BRACKET_CODE: "<pre>", "</pre>"
46
+ # :TEXT: SECTION1
47
+ # This is my article
48
+
49
+ # :SAMPLE: SECTION1, { brackets: [ '[code]', '[/code]' ] }
50
+ this is my code
51
+ """
52
+ When I run the format command on the article
53
+ Then the output should be as follows:
54
+ """
55
+ This is my article
56
+
57
+ [code]
58
+ this is my code
59
+ [/code]
60
+ """
61
+
62
+ Scenario: insert a named section
63
+ Given an article with the contents:
64
+ """
65
+ # :BRACKET_CODE: "<pre>", "</pre>"
66
+
67
+ # :SAMPLE: sample1
68
+ code sample 1
69
+
70
+ # :SAMPLE: sample2
71
+ code sample 2
72
+
73
+ # :TEXT:
74
+ # Here is example 2:
75
+ # :INSERT: @sample2
76
+ #
77
+ # And here is example 1:
78
+ # :INSERT: @sample1
79
+ """
80
+ When I run the format command on the article
81
+ Then the output should be as follows:
82
+ """
83
+ Here is example 2:
84
+ <pre>
85
+ code sample 2
86
+ </pre>
87
+
88
+ And here is example 1:
89
+ <pre>
90
+ code sample 1
91
+ </pre>
92
+ """
93
+
94
+ Scenario Outline: more formatting examples
95
+ Given the article "<input_file>"
96
+ When I run the format command on the article
97
+ Then the output should look like "<output_file>"
98
+
99
+ Scenarios:
100
+ | input_file | output_file |
101
+ | hello.rb | hello.txt |
102
+ | wrapping.rb | wrapping.txt |
103
+ | sample_offsets.rb | sample_offsets.txt |
104
+ | specials.rb | specials.txt |
105
+ | regexen.rb | regexen.txt |
106
+ | pipelines.txt | pipelines.out |
107
+ | escaping.txt | escaping.out |
108
+ | bracketing.rb | bracketing.out |
109
+ | stderr.rb | stderr.out |
110
+ | excerpt_output.rb | excerpt_output.out |
111
+
@@ -0,0 +1,48 @@
1
+ Note: this is a debug feature and its not worth specifying until it gets a bit
2
+ more stable.
3
+ Feature: author lists information
4
+
5
+ As an author
6
+ I want to list the various components of my article
7
+ So that I can diagnose errors in output
8
+
9
+ Scenario: list stuff
10
+ Given an article with the contents:
11
+ """
12
+ # :TEXT:
13
+ # Anonymous section 1
14
+
15
+ anonymous code 1
16
+ # :END:
17
+
18
+ anonymous code 2
19
+
20
+ # :TEXT: A
21
+ # Section A
22
+
23
+ # :SAMPLE: X
24
+ code sample X
25
+
26
+ # :PROCESS: frob, "aaa"
27
+ # :PROCESS: munge, "bbb"
28
+ """
29
+ When I run the command "germ list --sections" on the article
30
+ Then the output should be as follows:
31
+ """
32
+ SECTION1
33
+ A
34
+ """
35
+ When I run the command "germ list --samples" on the article
36
+ Then the output should be as follows:
37
+ """
38
+ SECTION1
39
+ SECTION2
40
+ X
41
+ """
42
+ When I run the command "germ list --processes" on the article
43
+ Then the output should be as follows:
44
+ """
45
+ frob
46
+ _transform
47
+ munge
48
+ """
@@ -0,0 +1,5 @@
1
+ Feature: author publishes article source
2
+
3
+ As an author
4
+ I want to publish my article source code to Gist
5
+ So that I can share it with other programmers
@@ -0,0 +1,57 @@
1
+ Feature: author publishes article
2
+
3
+ As an author
4
+ I want to publish my article as a blog post
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
+ """
@@ -0,0 +1,5 @@
1
+ Feature: author re-publishes article
2
+
3
+ As an author
4
+ I want to re-publish my article after updating it
5
+ So that the world can see the latest version
@@ -0,0 +1,26 @@
1
+ Feature: author experiments with selectors
2
+
3
+ As an author
4
+ I want to test the behavior of various selectors
5
+ So that I know what to use in my article
6
+
7
+ Scenario: list stuff
8
+ Given an article with the contents:
9
+ """
10
+ # :TEXT: A
11
+ # Section A
12
+
13
+ # :SAMPLE: X
14
+ X 1
15
+ X 2
16
+ X 3
17
+ X 4
18
+
19
+ # :PROCESS: quote, "quoter %f"
20
+ """
21
+ When I run the command "germ select '@X:2..3|quote'" on the article
22
+ Then the output should be as follows:
23
+ """
24
+ > X 2
25
+ > X 3
26
+ """
@@ -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
+ """