devver-germinate 1.0.0 → 1.0.1

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.
@@ -105,4 +105,5 @@ Feature: author formats article
105
105
  | regexen.rb | regexen.txt |
106
106
  | pipelines.txt | pipelines.out |
107
107
  | escaping.txt | escaping.out |
108
+ | bracketing.rb | bracketing.out |
108
109
 
@@ -0,0 +1,27 @@
1
+ # :BRACKET_CODE: "[", "]"
2
+
3
+ # :SAMPLE: main
4
+ def main
5
+ hello
6
+ end
7
+
8
+ # :SAMPLE: hello, { brackets: [ "{", "}" ] }
9
+ def hello
10
+ puts "hello"
11
+ end
12
+
13
+ # :TEXT:
14
+ # Should have square brackets
15
+ # :INSERT: @main
16
+
17
+ # :TEXT:
18
+ # Should have curly brackets
19
+ # :INSERT: @hello
20
+
21
+ # :TEXT:
22
+ # Should have curly brackets
23
+ # :INSERT: @hello:2
24
+
25
+ # :TEXT:
26
+ # Should have angle brackets
27
+ # :INSERT: @hello:2, { brackets: [ "<", ">" ] }
@@ -0,0 +1,23 @@
1
+ Should have square brackets
2
+ [
3
+ def main
4
+ hello
5
+ end
6
+ ]
7
+
8
+ Should have curly brackets
9
+ {
10
+ def hello
11
+ puts "hello"
12
+ end
13
+ }
14
+
15
+ Should have curly brackets
16
+ {
17
+ puts "hello"
18
+ }
19
+
20
+ Should have angle brackets
21
+ <
22
+ puts "hello"
23
+ >
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{germinate}
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
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"]
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
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", "bin/germ", "cucumber.yml", "examples/basic.rb", "examples/short.rb", "features/author-formats-article.feature", "features/author-lists-info.feature", "features/author-publishes-article-source.feature", "features/author-publishes-article.feature", "features/author-republishes-article.feature", "features/author-selects-hunks.feature", "features/author-updates-article-source.feature", "features/author-views-stuff.feature", "features/bin/quoter", "features/bin/sorter", "features/example_articles/code_samples.rb", "features/example_articles/escaping.txt", "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/wrapping.rb", "features/example_output/code_samples.txt", "features/example_output/escaping.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/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/article_formatter.rb", "lib/germinate/formatter.rb", "lib/germinate/hunk.rb", "lib/germinate/implicit_insertion.rb", "lib/germinate/insertion.rb", "lib/germinate/librarian.rb", "lib/germinate/pipeline.rb", "lib/germinate/process.rb", "lib/germinate/reader.rb", "lib/germinate/selector.rb", "lib/germinate/shared_style_attributes.rb", "lib/germinate/text_transforms.rb", "spec/germinate/application_spec.rb", "spec/germinate/article_editor_spec.rb", "spec/germinate/article_formatter_spec.rb", "spec/germinate/code_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/reader_spec.rb", "spec/germinate/selector_spec.rb", "spec/germinate/text_hunk_spec.rb", "spec/germinate/text_transforms_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"]
15
+ s.files = [".gitignore", "History.txt", "README.rdoc", "Rakefile", "bin/germ", "cucumber.yml", "examples/basic.rb", "examples/short.rb", "features/author-formats-article.feature", "features/author-lists-info.feature", "features/author-publishes-article-source.feature", "features/author-publishes-article.feature", "features/author-republishes-article.feature", "features/author-selects-hunks.feature", "features/author-updates-article-source.feature", "features/author-views-stuff.feature", "features/bin/quoter", "features/bin/sorter", "features/example_articles/bracketing.rb", "features/example_articles/escaping.txt", "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/wrapping.rb", "features/example_output/bracketing.out", "features/example_output/code_samples.txt", "features/example_output/escaping.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/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/article_formatter.rb", "lib/germinate/formatter.rb", "lib/germinate/hunk.rb", "lib/germinate/implicit_insertion.rb", "lib/germinate/insertion.rb", "lib/germinate/librarian.rb", "lib/germinate/pipeline.rb", "lib/germinate/process.rb", "lib/germinate/reader.rb", "lib/germinate/selector.rb", "lib/germinate/shared_style_attributes.rb", "lib/germinate/text_transforms.rb", "spec/germinate/application_spec.rb", "spec/germinate/article_editor_spec.rb", "spec/germinate/article_formatter_spec.rb", "spec/germinate/code_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/reader_spec.rb", "spec/germinate/selector_spec.rb", "spec/germinate/text_hunk_spec.rb", "spec/germinate/text_transforms_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"]
@@ -5,7 +5,7 @@ require 'logger'
5
5
  module Germinate
6
6
 
7
7
  # :stopdoc:
8
- VERSION = '1.0.0'
8
+ VERSION = '1.0.1'
9
9
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
10
10
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
11
11
  # :startdoc:
@@ -11,13 +11,7 @@ class Germinate::Hunk < ::Array
11
11
 
12
12
  def initialize(contents=[], template = {})
13
13
  super(contents)
14
- if Germinate::SharedStyleAttributes === template
15
- copy_shared_style_attrubutes_from(template)
16
- else
17
- template.each_pair do |key, value|
18
- send(key, value)
19
- end
20
- end
14
+ copy_shared_style_attrubutes_from(template)
21
15
  end
22
16
 
23
17
  # return a copy with leading and trailing whitespace lines removed
@@ -1,15 +1,21 @@
1
1
  require 'fattr'
2
+ require File.expand_path("shared_style_attributes", File.dirname(__FILE__))
2
3
 
3
4
  class Germinate::Insertion
5
+ include Germinate::SharedStyleAttributes
6
+
4
7
  attr_reader :library
5
8
  attr_reader :selector
6
9
 
7
- def initialize(selector, library)
10
+ def initialize(selector, library, template={})
11
+ copy_shared_style_attrubutes_from(template)
8
12
  @selector = selector
9
13
  @library = library
10
14
  end
11
15
 
12
16
  def resolve
13
- library[selector]
17
+ returning(library[selector]) do |hunk|
18
+ hunk.copy_shared_style_attrubutes_from(self, false)
19
+ end
14
20
  end
15
21
  end
@@ -50,8 +50,8 @@ class Germinate::Librarian
50
50
  @samples[sample] << line
51
51
  end
52
52
 
53
- def add_insertion!(section, selector)
54
- insertion = Germinate::Insertion.new(selector, self)
53
+ def add_insertion!(section, selector, attributes)
54
+ insertion = Germinate::Insertion.new(selector, self, attributes)
55
55
  @sections[section] << insertion
56
56
  end
57
57
 
@@ -153,8 +153,7 @@ class Germinate::Reader
153
153
  self.sample_name = sample_name || automatic_section_name
154
154
  librarian.set_code_attributes!(
155
155
  sample_name,
156
- :code_open_bracket => options.fetch("brackets", []).first,
157
- :code_close_bracket => options.fetch("brackets", []).last)
156
+ options_to_style_attributes(options))
158
157
  code!
159
158
  end
160
159
 
@@ -163,10 +162,11 @@ class Germinate::Reader
163
162
  librarian.code_close_bracket = close_bracket
164
163
  end
165
164
 
166
- def insert_control_line!(selector=nil)
165
+ def insert_control_line!(selector=nil, options={})
167
166
  librarian.add_insertion!(
168
167
  current_section,
169
- Germinate::Selector.new(selector, current_section))
168
+ Germinate::Selector.new(selector, current_section),
169
+ options_to_style_attributes(options))
170
170
  end
171
171
 
172
172
  def process_control_line!(process_name, command)
@@ -209,4 +209,13 @@ class Germinate::Reader
209
209
  def unescape(line)
210
210
  line.sub(/\\(:[A-Z0-9_]+:)/, '\1')
211
211
  end
212
+
213
+ def options_to_style_attributes(options)
214
+ returning({}) do |attributes|
215
+ if options.key?("brackets")
216
+ attributes[:code_open_bracket] = options.fetch("brackets").first
217
+ attributes[:code_close_bracket] = options.fetch("brackets").last
218
+ end
219
+ end
220
+ end
212
221
  end
@@ -15,9 +15,22 @@ module Germinate::SharedStyleAttributes
15
15
  }
16
16
  end
17
17
 
18
- def copy_shared_style_attrubutes_from(other)
19
- other.shared_style_attributes.each_pair do |key, value|
20
- self.send(key, value) unless other.send(key).nil?
18
+ def copy_shared_style_attrubutes_from(other, override=true)
19
+ case other
20
+ when Germinate::SharedStyleAttributes
21
+ copy_attributes!(other.shared_style_attributes)
22
+ when Hash
23
+ copy_attributes!(other, override)
24
+ else
25
+ raise "Don't know how to copy attributes from #{other.inspect}"
26
+ end
27
+ end
28
+
29
+ def copy_attributes!(attributes, override=true)
30
+ attributes.each_pair do |key, value|
31
+ if !value.nil? && (override || !send(key))
32
+ self.send(key, value)
33
+ end
21
34
  end
22
35
  end
23
36
  end
@@ -4,7 +4,7 @@ require File.expand_path(
4
4
  module Germinate
5
5
  describe ImplicitInsertion do
6
6
  before :each do
7
- @hunk = stub("Hunk")
7
+ @hunk = stub("Hunk").as_null_object
8
8
  @library = stub("Library")
9
9
  @selector = stub("Selector")
10
10
  @it = Germinate::ImplicitInsertion.new(@selector, @library)
@@ -4,10 +4,10 @@ require File.expand_path(
4
4
  module Germinate
5
5
  describe Insertion, "given a library and a selector" do
6
6
  before :each do
7
- @hunk = stub("Hunk")
7
+ @hunk = stub("Hunk").as_null_object
8
8
  @library = stub("Library", :[] => @hunk)
9
9
  @selector = stub("Selector")
10
- @it = Germinate::Insertion.new(@selector, @library)
10
+ @it = Germinate::Insertion.new(@selector, @library, {})
11
11
  end
12
12
 
13
13
  it "should use the library to resolve itself" do
@@ -83,7 +83,7 @@ module Germinate
83
83
 
84
84
  context "given an insertion in my_section with selector @my_selector" do
85
85
  before :each do
86
- @it.add_insertion!("my_section", "@my_selector")
86
+ @it.add_insertion!("my_section", "@my_selector", { :comment_prefix => "@" })
87
87
  end
88
88
 
89
89
  it "should add an Insertion to the named section" do
@@ -97,6 +97,10 @@ module Germinate
97
97
  it "should give the insertion a reference to the library" do
98
98
  @it.section("my_section").last.library.should == @it
99
99
  end
100
+
101
+ it "should apply any passed attributes to the insertion" do
102
+ @it.section("my_section").last.comment_prefix.should == "@"
103
+ end
100
104
  end
101
105
 
102
106
  context "given a process to file" do
@@ -277,12 +277,13 @@ module Germinate
277
277
  end
278
278
 
279
279
  it "should add an insertion to the current section" do
280
- @librarian.should_receive(:add_insertion!).with("mysection", anything)
280
+ @librarian.should_receive(:add_insertion!).
281
+ with("mysection", anything, anything)
281
282
  @it << @line
282
283
  end
283
284
 
284
285
  it "should pass a selector object to the librarian" do
285
- @librarian.should_receive(:add_insertion!) do |section, selector|
286
+ @librarian.should_receive(:add_insertion!) do |section, selector, options|
286
287
  selector.should be_a_kind_of(Selector)
287
288
  selector.string.should == "foo"
288
289
  selector.default_key.should == "mysection"
@@ -291,6 +292,23 @@ module Germinate
291
292
  end
292
293
  end
293
294
 
295
+ context "given an insertion with custom attributes" do
296
+ before :each do
297
+ @it << ":TEXT: mysection"
298
+ @line = ":INSERT: foo, { brackets: ['<<', '>>'] } "
299
+ end
300
+
301
+ it "should pass the attributes on to the library" do
302
+ @librarian.should_receive(:add_insertion!).
303
+ with(anything, anything, {
304
+ :code_open_bracket => "<<",
305
+ :code_close_bracket => ">>"
306
+ })
307
+ @it << @line
308
+ end
309
+
310
+ end
311
+
294
312
  context "given a process directive" do
295
313
  before :each do
296
314
  @line = ' # :PROCESS: sortail, "sort | tail"'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devver-germinate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avdi Grimm
@@ -111,7 +111,7 @@ files:
111
111
  - features/author-views-stuff.feature
112
112
  - features/bin/quoter
113
113
  - features/bin/sorter
114
- - features/example_articles/code_samples.rb
114
+ - features/example_articles/bracketing.rb
115
115
  - features/example_articles/escaping.txt
116
116
  - features/example_articles/hello.rb
117
117
  - features/example_articles/pipelines.txt
@@ -119,6 +119,7 @@ files:
119
119
  - features/example_articles/sample_offsets.rb
120
120
  - features/example_articles/specials.rb
121
121
  - features/example_articles/wrapping.rb
122
+ - features/example_output/bracketing.out
122
123
  - features/example_output/code_samples.txt
123
124
  - features/example_output/escaping.out
124
125
  - features/example_output/hello.txt
@@ -1,89 +0,0 @@
1
- # This example demonstrates the use of code samples.
2
-
3
- # :TEXT:
4
- # Hi there! Here's a Hello, World method:
5
-
6
- def hello
7
- puts "Hello, World!"
8
- end
9
-
10
- # :CUT:
11
- # Here's some boring support code we don't want to show the world.
12
-
13
- def boring
14
- 1 + 1
15
- end
16
-
17
- # Here are two a named samples:
18
- # :SAMPLE: fred
19
-
20
- def fred
21
- # This comment is part of the sample
22
- puts "Hello, my name is Fred"
23
- puts "la la la"
24
- end
25
-
26
- # :SAMPLE: sally
27
-
28
- def sally
29
- puts "Hello, my name is Sally"
30
- end
31
-
32
- # :END:
33
- # Sample "sally" ends above, and does not include the following.
34
-
35
- def wizard
36
- puts "Pay no attention to the man behind the curtain!"
37
- end
38
-
39
- # Samples can be inside comment blocks
40
- # :SAMPLE: george
41
- # (defun george () (format "Hello from George"))
42
- # :CUT:
43
-
44
- # Samples can have comment markers stripped
45
- # :SAMPLE: mary, { uncomment: true }
46
- # (defun mary () (format "Hello from Mary"))
47
- # :CUT:
48
-
49
- # :TEXT:
50
- # The immediately following code sample can be implicitly referenced:
51
- # :INSERT:
52
- # :CUT:
53
- def nameless
54
- puts "I have no name"
55
- end
56
-
57
- # :TEXT:
58
- # Or explicitly referenced
59
- # :INSERT: FOLLOWING
60
- # :CUT:
61
- def foo
62
- puts "foo"
63
- end
64
-
65
- # :TEXT:
66
- # Samples can be referenced by name
67
- # :INSERT: fred
68
- #
69
- # Or by index:
70
- # :INSERT: #2
71
- #
72
- # SOURCE is a special sample which contains the entire source file.
73
- # :INSERT: SOURCE, { indent: 4 }
74
- #
75
- # CODE is a special sample which contains all the non-text portions of this
76
- # file.
77
- # :INSERT: CODE, { indent: " > " }
78
- #
79
- # We can select specific lines:
80
- # :INSERT: sally:2
81
- #
82
- # Or ranges of lines:
83
- # :INSERT: sally:2..3
84
- #
85
- # Or lines matching a regex:
86
- # :INSERT: sally:/def/
87
- #
88
- # Or ranges of regexen:
89
- # :INSERT: fred:/puts/.../end/