hologram 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,6 +28,34 @@ Markdown stuff
28
28
  eos
29
29
  end
30
30
 
31
+ let(:multi_category_child_doc) do
32
+ <<-eos
33
+ /*doc
34
+ ---
35
+ parent: multi
36
+ name: otherStyle
37
+ title: MultiChild
38
+ ---
39
+ Markdown stuff
40
+ multi-child
41
+ */
42
+ eos
43
+ end
44
+
45
+ let(:multi_category_doc) do
46
+ <<-eos
47
+ /*doc
48
+ ---
49
+ title: MultiParent
50
+ name: multi
51
+ category: [Foo, Bar]
52
+ ---
53
+ Markdown stuff
54
+ multi-parent
55
+ */
56
+ eos
57
+ end
58
+
31
59
  let(:source_path) { 'spec/fixtures/source' }
32
60
  let(:temp_doc) { File.join(source_path, 'components', 'button', 'skin', 'testSkin.css') }
33
61
 
@@ -36,11 +64,23 @@ eos
36
64
  context '#parse' do
37
65
  let(:result) { parser.parse }
38
66
  let(:pages) { result[0] }
39
- let(:categories) { result[1] }
67
+ let(:output_files_by_category) { result[1] }
40
68
 
41
- it 'builds and returns a hash of pages and a hash of categories' do
69
+ it 'builds and returns a hash of pages and a hash of output_files_by_category' do
42
70
  expect(pages).to be_a Hash
43
- expect(categories).to be_a Hash
71
+ expect(output_files_by_category).to be_a Hash
72
+ end
73
+
74
+ context 'when the component has two categories' do
75
+ around do |example|
76
+ File.open(temp_doc, 'a+'){ |io| io << multi_category_doc }
77
+ example.run
78
+ FileUtils.rm(temp_doc)
79
+ end
80
+
81
+ it 'adds two categories to output_files_by_category' do
82
+ expect(output_files_by_category).to eql({'Foo'=>'foo.html', 'Base CSS'=>'base_css.html', 'Bar'=>'bar.html'})
83
+ end
44
84
  end
45
85
 
46
86
 
@@ -89,5 +129,26 @@ eos
89
129
  expect(pages['base_css.html'][:md]).to include '<h2 id="otherStyle">Some other style</h2>'
90
130
  end
91
131
  end
132
+
133
+ context 'when a source doc is the child of a multi category doc block' do
134
+ around do |example|
135
+ File.open(temp_doc, 'w'){ |io|
136
+ io << multi_category_doc
137
+ io << multi_category_child_doc
138
+ }
139
+ example.run
140
+ FileUtils.rm(temp_doc)
141
+ end
142
+
143
+ it 'should not output duplicate content' do
144
+ objects = expect(pages['foo.html'][:md]).not_to match(/multi-parent.*multi-child.*multi-child/m)
145
+ objects = expect(pages['bar.html'][:md]).not_to match(/multi-parent.*multi-child.*multi-child/m)
146
+ end
147
+
148
+ it 'should correctly order content in each page' do
149
+ objects = expect(pages['foo.html'][:md]).to match(/multi-parent.*multi-child/m)
150
+ objects = expect(pages['bar.html'][:md]).to match(/multi-parent.*multi-child/m)
151
+ end
152
+ end
92
153
  end
93
154
  end
@@ -8,17 +8,68 @@ describe Hologram::DocumentBlock do
8
8
  let(:markdown){ 'blah' }
9
9
  let(:doc_block){ subject.class.new(config, markdown) }
10
10
 
11
+ context '.from_comment' do
12
+ let(:doc) do
13
+ <<-eos
14
+ /*doc
15
+ ---
16
+ title: Some other style
17
+ name: otherStyle
18
+ category: Foo
19
+ ---
20
+ Markdown stuff
21
+ */
22
+ eos
23
+ end
24
+
25
+ let(:bad_doc) do
26
+ <<-eos
27
+ /*doc
28
+ ---
29
+ : :
30
+ ---
31
+ Markdown stuff
32
+ */
33
+ eos
34
+ end
35
+
36
+ it 'initializes a new document block from a matching comment' do
37
+ doc_block = Hologram::DocumentBlock.from_comment(doc)
38
+ expect(doc_block).to be_a Hologram::DocumentBlock
39
+ end
40
+
41
+ it 'raises CommentLoadError when the yaml section is bad' do
42
+ expect{
43
+ Hologram::DocumentBlock.from_comment(bad_doc)
44
+ }.to raise_error Hologram::CommentLoadError
45
+ end
46
+
47
+ it 'returns nothing if its not a valid doc block' do
48
+ doc_block = Hologram::DocumentBlock.from_comment('foo')
49
+ expect(doc_block).to be_nil
50
+ end
51
+
52
+ it 'sets up the usual attrs using the YAML and markdown text' do
53
+ doc_block = Hologram::DocumentBlock.from_comment(doc)
54
+ expect(doc_block.name).to eql 'otherStyle'
55
+ expect(doc_block.categories).to eql ['Foo']
56
+ expect(doc_block.title).to eql 'Some other style'
57
+ expect(doc_block.markdown).to eql "/*doc\n\nMarkdown stuff\n*/\n"
58
+ end
59
+ end
60
+
11
61
  context '#set_members' do
12
62
  it 'sets accessors for the the block config' do
13
- config.each do |k, v|
14
- expect(doc_block.send(k)).to eql v
15
- end
63
+ expect(doc_block.send('name')).to eql 'foo'
64
+ expect(doc_block.send('categories')).to eql ['bar']
65
+ expect(doc_block.send('title')).to eql 'baz'
66
+ expect(doc_block.send('parent')).to eql 'pop'
16
67
  end
17
68
  end
18
69
 
19
70
  context '#get_hash' do
20
71
  let(:meta) do
21
- { :name => 'foo', :category => 'bar', :title => 'baz', :parent => 'pop' }
72
+ { :name => 'foo', :categories => ['bar'], :title => 'baz', :parent => 'pop' }
22
73
  end
23
74
 
24
75
  it 'returns a hash of meta info' do
@@ -41,6 +92,11 @@ describe Hologram::DocumentBlock do
41
92
  it 'returns false' do
42
93
  expect(invalid_doc_block.is_valid?).to eql false
43
94
  end
95
+
96
+ it 'populates errors' do
97
+ invalid_doc_block.is_valid?
98
+ expect(invalid_doc_block.errors).to include('Missing name or title config value')
99
+ end
44
100
  end
45
101
 
46
102
  context 'when markdown is not present' do
@@ -51,6 +107,11 @@ describe Hologram::DocumentBlock do
51
107
  it 'returns false' do
52
108
  expect(invalid_doc_block.is_valid?).to eql false
53
109
  end
110
+
111
+ it 'populates errors' do
112
+ invalid_doc_block.is_valid?
113
+ expect(invalid_doc_block.errors).to include('Missing required markdown')
114
+ end
54
115
  end
55
116
  end
56
117
 
@@ -0,0 +1,2 @@
1
+ class FooBar < Redcarpet::Render::HTML
2
+ end
@@ -0,0 +1,2 @@
1
+ class ValidRenderer < Redcarpet::Render::HTML
2
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe HologramMarkdownRenderer do
4
+ context 'for backwards compatability' do
5
+ it 'is retained' do
6
+ capture(:stdout) {
7
+ class TestFoo < HologramMarkdownRenderer
8
+ end
9
+ }
10
+
11
+ expect(TestFoo.ancestors).to include Hologram::MarkdownRenderer
12
+ end
13
+ end
14
+ end
@@ -5,3 +5,20 @@ require 'tmpdir'
5
5
  RSpec.configure do |config|
6
6
  config.order = "random"
7
7
  end
8
+
9
+ #Rails kernerl helper
10
+ def capture(stream)
11
+ stream = stream.to_s
12
+ captured_stream = Tempfile.new(stream)
13
+ stream_io = eval("$#{stream}")
14
+ origin_stream = stream_io.dup
15
+ stream_io.reopen(captured_stream)
16
+
17
+ yield
18
+
19
+ stream_io.rewind
20
+ return captured_stream.read
21
+ ensure
22
+ captured_stream.unlink
23
+ stream_io.reopen(origin_stream)
24
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hologram::Utils do
4
+ context '.get_markdown_renderer' do
5
+ subject(:utils) { Hologram::Utils }
6
+
7
+ around do |example|
8
+ Hologram::DisplayMessage.quiet!
9
+ current_dir = Dir.pwd
10
+ Dir.chdir('spec/fixtures/renderer')
11
+
12
+ example.run
13
+
14
+ Dir.chdir(current_dir)
15
+ Hologram::DisplayMessage.show!
16
+ end
17
+
18
+ context 'by default' do
19
+ let(:renderer) { utils.get_markdown_renderer }
20
+
21
+ it 'returns the standard hologram markdown renderer' do
22
+ expect(renderer).to eql Hologram::MarkdownRenderer
23
+ end
24
+ end
25
+
26
+ context 'when passed a valid custom renderer' do
27
+ let(:renderer) { utils.get_markdown_renderer('valid_renderer.rb') }
28
+
29
+ it 'returns the custom renderer' do
30
+ expect(renderer).to eql ValidRenderer
31
+ end
32
+ end
33
+
34
+ context 'when passed an invalid custom renderer' do
35
+ context 'expecting a class named as the upper camel cased version of the file name' do
36
+ it 'exits' do
37
+ expect {
38
+ utils.get_markdown_renderer('invalid_renderer.rb')
39
+ }.to raise_error SystemExit
40
+ end
41
+ end
42
+
43
+ context 'expecting a filename.rb' do
44
+ it 'exits' do
45
+ expect {
46
+ utils.get_markdown_renderer('foo')
47
+ }.to raise_error SystemExit
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hologram
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Cantrell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-28 00:00:00.000000000 Z
12
+ date: 2014-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redcarpet
@@ -17,42 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: 2.2.2
20
+ version: '2.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: 2.2.2
27
+ version: '2.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: pygments.rb
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: 0.4.2
34
+ version: '0.4'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ~>
40
40
  - !ruby/object:Gem::Version
41
- version: 0.4.2
42
- - !ruby/object:Gem::Dependency
43
- name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ~>
47
- - !ruby/object:Gem::Version
48
- version: 2.14.1
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ~>
54
- - !ruby/object:Gem::Version
55
- version: 2.14.1
41
+ version: '0.4'
56
42
  - !ruby/object:Gem::Dependency
57
43
  name: bundler
58
44
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +67,20 @@ dependencies:
81
67
  - - '>='
82
68
  - !ruby/object:Gem::Version
83
69
  version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '2.14'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '2.14'
84
84
  description: Build doc type things
85
85
  email:
86
86
  - jcantrell@trulia.com
@@ -96,24 +96,31 @@ files:
96
96
  - README.md
97
97
  - Rakefile
98
98
  - bin/hologram
99
+ - example_markdown_renderer.rb.example
99
100
  - hologram.gemspec
100
101
  - lib/hologram.rb
102
+ - lib/hologram/cli.rb
101
103
  - lib/hologram/display_message.rb
102
104
  - lib/hologram/doc_block_collection.rb
103
105
  - lib/hologram/doc_builder.rb
104
106
  - lib/hologram/doc_parser.rb
105
107
  - lib/hologram/document_block.rb
108
+ - lib/hologram/errors.rb
109
+ - lib/hologram/markdown_renderer.rb
106
110
  - lib/hologram/template_variables.rb
111
+ - lib/hologram/utils.rb
107
112
  - lib/hologram/version.rb
108
- - lib/hologram_markdown_renderer.rb
109
113
  - lib/template/doc_assets/_footer.html
110
114
  - lib/template/doc_assets/_header.html
111
115
  - lib/template/hologram_config.yml
116
+ - spec/cli_spec.rb
112
117
  - spec/display_message_spec.rb
113
118
  - spec/doc_block_collection_spec.rb
114
119
  - spec/doc_builder_spec.rb
115
120
  - spec/doc_parser_spec.rb
116
121
  - spec/document_block_spec.rb
122
+ - spec/fixtures/renderer/invalid_renderer.rb
123
+ - spec/fixtures/renderer/valid_renderer.rb
117
124
  - spec/fixtures/source/components/background/backgrounds.css
118
125
  - spec/fixtures/source/components/button/buttons.css
119
126
  - spec/fixtures/source/components/button/skin/buttonSkins.css
@@ -127,7 +134,9 @@ files:
127
134
  - spec/fixtures/styleguide/extra/css/screen.css
128
135
  - spec/fixtures/styleguide/index.html
129
136
  - spec/fixtures/styleguide/static/css/doc.css
137
+ - spec/hologram_markdown_renderer_spec.rb
130
138
  - spec/spec_helper.rb
139
+ - spec/utils_spec.rb
131
140
  homepage: http://trulia.github.io/hologram
132
141
  licenses:
133
142
  - MIT
@@ -148,16 +157,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
157
  version: '0'
149
158
  requirements: []
150
159
  rubyforge_project:
151
- rubygems_version: 2.0.3
160
+ rubygems_version: 2.0.14
152
161
  signing_key:
153
162
  specification_version: 4
154
163
  summary: Build document type things.
155
164
  test_files:
165
+ - spec/cli_spec.rb
156
166
  - spec/display_message_spec.rb
157
167
  - spec/doc_block_collection_spec.rb
158
168
  - spec/doc_builder_spec.rb
159
169
  - spec/doc_parser_spec.rb
160
170
  - spec/document_block_spec.rb
171
+ - spec/fixtures/renderer/invalid_renderer.rb
172
+ - spec/fixtures/renderer/valid_renderer.rb
161
173
  - spec/fixtures/source/components/background/backgrounds.css
162
174
  - spec/fixtures/source/components/button/buttons.css
163
175
  - spec/fixtures/source/components/button/skin/buttonSkins.css
@@ -171,4 +183,6 @@ test_files:
171
183
  - spec/fixtures/styleguide/extra/css/screen.css
172
184
  - spec/fixtures/styleguide/index.html
173
185
  - spec/fixtures/styleguide/static/css/doc.css
186
+ - spec/hologram_markdown_renderer_spec.rb
174
187
  - spec/spec_helper.rb
188
+ - spec/utils_spec.rb