asciidoctor 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor might be problematic. Click here for more details.

@@ -1,11 +1,8 @@
1
- # Public: Methods for managing items for Asciidoc olists, ulist, and dlists.
1
+ # Public: Methods for managing items for AsciiDoc olists, ulist, and dlists.
2
2
  class Asciidoctor::ListItem
3
3
  # Public: Get the Array of Blocks from the list item's continuation.
4
4
  attr_reader :blocks
5
5
 
6
- # Public: Get/Set the String content.
7
- attr_accessor :content
8
-
9
6
  # Public: Get/Set the String list item anchor name.
10
7
  attr_accessor :anchor
11
8
 
@@ -14,22 +11,58 @@ class Asciidoctor::ListItem
14
11
 
15
12
  # Public: Initialize an Asciidoctor::ListItem object.
16
13
  #
17
- # content - the String content (default '')
18
- def initialize(content='')
19
- @content = content
20
- @blocks = []
14
+ # parent - The parent list block for this list item
15
+ # text - the String text (default '')
16
+ def initialize(parent, text='')
17
+ @parent = parent
18
+ @text = text
19
+ @blocks = []
20
+ end
21
+
22
+ def text=(new_text)
23
+ @text = new_text
24
+ end
25
+
26
+ def text
27
+ # this will allow the text to be processed
28
+ ::Asciidoctor::Block.new(self, nil, [@text]).content
29
+ end
30
+
31
+ def document
32
+ @parent.document
21
33
  end
22
34
 
23
- def render
24
- output = "<li><p>#{content} (HTMLIFY) "
25
- output += blocks.map{|block| block.render}.join
26
- output += "</p></li>"
35
+ def content
36
+ # create method for !blocks.empty?
37
+ if !blocks.empty?
38
+ blocks.map{|block| block.render}.join
39
+ else
40
+ nil
41
+ end
42
+ end
43
+
44
+ # Public: Fold the first paragraph block into the text
45
+ def fold_first
46
+ # looking for :literal here allows indentation of paragraph content, then strip indent
47
+ if !blocks.empty? && blocks.first.is_a?(Asciidoctor::Block) &&
48
+ (blocks.first.context == :paragraph || blocks.first.context == :literal)
49
+ block = blocks.shift
50
+ if !@text.nil? && !@text.empty?
51
+ block.buffer.unshift(@text)
52
+ end
53
+
54
+ if block.context == :literal
55
+ @text = block.buffer.map {|l| l.lstrip}.join("\n")
56
+ else
57
+ @text = block.buffer.join("\n")
58
+ end
59
+ end
27
60
  end
28
61
 
29
62
  def splain(parent_level = 0)
30
63
  parent_level += 1
31
- Asciidoctor.puts_indented(parent_level, "List Item anchor: #{anchor}") unless self.anchor.nil?
32
- Asciidoctor.puts_indented(parent_level, "Content: #{content}") unless self.content.nil?
64
+ Asciidoctor.puts_indented(parent_level, "List Item anchor: #{@anchor}") unless @anchor.nil?
65
+ Asciidoctor.puts_indented(parent_level, "Text: #{@text}") unless @text.nil?
33
66
 
34
67
  Asciidoctor.puts_indented(parent_level, "Blocks: #{@blocks.count}")
35
68
 
@@ -6,8 +6,11 @@ class Asciidoctor::Reader
6
6
  # Public: Get the String document source.
7
7
  attr_reader :source
8
8
 
9
- # Public: Get the Hash of defines
10
- attr_reader :defines
9
+ # Public: Get the String Array of lines parsed from the source
10
+ attr_reader :lines
11
+
12
+ # Public: Get the Hash of attributes
13
+ attr_reader :attributes
11
14
 
12
15
  attr_reader :references
13
16
 
@@ -41,9 +44,9 @@ class Asciidoctor::Reader
41
44
  #
42
45
  # data = File.readlines(filename)
43
46
  # reader = Asciidoctor::Reader.new(data)
44
- def initialize(data = [], &block)
47
+ def initialize(data = [], attributes = {}, &block)
45
48
  raw_source = []
46
- @defines = {}
49
+ @attributes = attributes
47
50
  @references = {}
48
51
 
49
52
  data = data.split("\n") if data.is_a? String
@@ -80,12 +83,12 @@ class Asciidoctor::Reader
80
83
  # Lines that start with whitespace and end with a '+' are
81
84
  # a continuation, so gobble them up into `value`
82
85
  if match = line.match(/\s+(.+)\s+\+\s*$/)
83
- continuing_value += match[1]
86
+ continuing_value += ' ' + match[1]
84
87
  elsif match = line.match(/\s+(.+)/)
85
88
  # If this continued line doesn't end with a +, then this
86
89
  # is the end of the continuation, no matter what the next
87
90
  # line does.
88
- continuing_value += match[1]
91
+ continuing_value += ' ' + match[1]
89
92
  close_continue = true
90
93
  else
91
94
  # If this line doesn't start with whitespace, then it's
@@ -94,15 +97,15 @@ class Asciidoctor::Reader
94
97
  raw_source.unshift(line)
95
98
  end
96
99
  if close_continue
97
- @defines[continuing_key] = continuing_value
100
+ @attributes[continuing_key] = continuing_value
98
101
  continuing_key = nil
99
102
  continuing_value = nil
100
103
  end
101
104
  elsif match = line.match(ifdef_regexp)
102
105
  attr = match[2]
103
106
  skip = case match[1]
104
- when 'ifdef'; !@defines.has_key?(attr)
105
- when 'ifndef'; @defines.has_key?(attr)
107
+ when 'ifdef'; !@attributes.has_key?(attr)
108
+ when 'ifndef'; @attributes.has_key?(attr)
106
109
  end
107
110
  skip_to = /^endif::#{attr}\[\]\s*\n/ if skip
108
111
  elsif match = line.match(defattr_regexp)
@@ -115,18 +118,19 @@ class Asciidoctor::Reader
115
118
  continuing_value = match[1] # strip off the spaces and +
116
119
  Asciidoctor.debug "continuing key: #{continuing_key} with partial value: '#{continuing_value}'"
117
120
  else
118
- @defines[key] = value
121
+ @attributes[key] = value
119
122
  Asciidoctor.debug "Defines[#{key}] is '#{value}'"
120
123
  end
121
124
  elsif match = line.match(delete_attr_regexp)
122
125
  key = sanitize_attribute_name(match[1])
123
- @defines.delete(key)
126
+ @attributes.delete(key)
124
127
  elsif !line.match(endif_regexp)
125
128
  while match = line.match(conditional_regexp)
126
- value = @defines.has_key?(match[1]) ? match[2] : ''
129
+ value = @attributes.has_key?(match[1]) ? match[2] : ''
127
130
  line.sub!(conditional_regexp, value)
128
131
  end
129
- @lines << line unless line.match(REGEXP[:comment])
132
+ # leave line comments in as they play a role in flow (such as a list divider)
133
+ @lines << line
130
134
  end
131
135
  end
132
136
 
@@ -138,7 +142,7 @@ class Asciidoctor::Reader
138
142
  end
139
143
  end
140
144
 
141
- Asciidoctor.debug "About to leave Reader#init, and references is #{@references.inspect}"
145
+ #Asciidoctor.debug "About to leave Reader#init, and references is #{@references.inspect}"
142
146
  @source = @lines.join
143
147
  Asciidoctor.debug "Leaving Reader#init, and I have #{@lines.count} lines"
144
148
  Asciidoctor.debug "Also, has_lines? is #{self.has_lines?}"
@@ -173,6 +177,17 @@ class Asciidoctor::Reader
173
177
  nil
174
178
  end
175
179
 
180
+ # Skip the next line if it's a list continuation character
181
+ #
182
+ # Returns nil
183
+ def skip_list_continuation
184
+ if !@lines.empty? && @lines.first.chomp == '+'
185
+ @lines.shift
186
+ end
187
+
188
+ nil
189
+ end
190
+
176
191
  # Public: Get the next line of source data. Consumes the line returned.
177
192
  #
178
193
  # Returns the String of the next line of the source data if data is present.
@@ -24,23 +24,41 @@ end
24
24
  class DocumentTemplate < BaseTemplate
25
25
  def template
26
26
  @template ||= ::ERB.new <<-EOF
27
- <div class='man-page'>
28
- <div id='header'>
29
- <% if header %>
30
- <h1><%= header.name %></h1>
31
- <div class='sectionbody'><%= header.content %></div>
32
- <% elsif preamble %>
33
- <div class=preamble'>
34
- <div class='sectionbody'>
35
- <%= preamble.content %>
27
+ <!DOCTYPE html>
28
+ <html lang='en'>
29
+ <head>
30
+ <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
31
+ <meta name='generator' content='Asciidoctor <%= attr "asciidoctor-version" %>'>
32
+ <title><%= title ? title : (doctitle ? doctitle : '') %></title>
33
+ </head>
34
+ <body class='<%= attr :doctype %>'>
35
+ <div id='header'>
36
+ <% if doctitle %>
37
+ <h1><%= doctitle %></h1>
38
+ <% end %>
39
+ </div>
40
+ <div id='content'>
41
+ <%= content %>
42
+ </div>
43
+ <div id='footer'>
44
+ <div id='footer-text'>
45
+ Last updated <%= attr :localdatetime %>
36
46
  </div>
37
47
  </div>
38
- <% end %>
39
- </div>
40
-
41
- <%= content %>
48
+ </body>
49
+ </html>
50
+ EOF
51
+ end
52
+ end
42
53
 
43
- </div>
54
+ class SectionPreambleTemplate < BaseTemplate
55
+ def template
56
+ @template ||= ::ERB.new <<-EOF
57
+ <div id='preamble'>
58
+ <div class='sectionbody'>
59
+ <%= content %>
60
+ </div>
61
+ </div>
44
62
  EOF
45
63
  end
46
64
  end
@@ -77,9 +95,19 @@ class SectionDlistTemplate < BaseTemplate
77
95
  <div class='dlist'>
78
96
  <dl>
79
97
  <% content.each do |dt, dd| %>
80
- <dt class='hdlist1'><%= dt %></dt>
81
- <% unless dd.nil? || dd.empty? %>
82
- <dd><%= dd %></dd>
98
+ <dt class='hdlist1'>
99
+ <% if !dt.anchor.nil? and !dt.anchor.empty? %>
100
+ <a id='<%= dt.anchor %>'></a>
101
+ <% end %>
102
+ <%= dt.text %>
103
+ </dt>
104
+ <% unless dd.nil? %>
105
+ <dd>
106
+ <p><%= dd.text %></p>
107
+ <% if !dd.blocks.empty? %>
108
+ <%= dd.content %>
109
+ <% end %>
110
+ </dd>
83
111
  <% end %>
84
112
  <% end %>
85
113
  </dl>
@@ -114,13 +142,17 @@ class SectionLiteralTemplate < BaseTemplate
114
142
  end
115
143
  end
116
144
 
117
- class SectionNoteTemplate < BaseTemplate
145
+ class SectionAdmonitionTemplate < BaseTemplate
118
146
  def template
119
147
  @template ||= ERB.new <<-EOF
120
148
  <div class='admonitionblock'>
121
149
  <table>
122
150
  <tr>
123
- <td class='icon'></td>
151
+ <td class='icon'>
152
+ <% if attr? :caption %>
153
+ <div class='title'><%= attr :caption %></div>
154
+ <% end %>
155
+ </td>
124
156
  <td class='content'>
125
157
  <% if !title.nil? %>
126
158
  <div class='title'><%= title %></div>
@@ -152,7 +184,75 @@ class SectionSidebarTemplate < BaseTemplate
152
184
  @template ||= ERB.new <<-EOF
153
185
  <div class='sidebarblock'>
154
186
  <div class='content'>
155
- <p><%= content %></p>
187
+ <% if !title.nil? %>
188
+ <div class='title'><%= title %></div>
189
+ <% end %>
190
+ <%= content %>
191
+ </div>
192
+ </div>
193
+ EOF
194
+ end
195
+ end
196
+
197
+ class SectionExampleTemplate < BaseTemplate
198
+ def template
199
+ @template ||= ERB.new <<-EOF
200
+ <div class='exampleblock'>
201
+ <div class='content'>
202
+ <% if !title.nil? %>
203
+ <div class='title'><%= title %></div>
204
+ <% end %>
205
+ <%= content %>
206
+ </div>
207
+ </div>
208
+ EOF
209
+ end
210
+ end
211
+
212
+ class SectionQuoteTemplate < BaseTemplate
213
+ def template
214
+ @template ||= ERB.new <<-EOF
215
+ <div class='quoteblock'>
216
+ <% if !title.nil? %>
217
+ <div class='title'><%= title %></div>
218
+ <% end %>
219
+ <div class='content'>
220
+ <%= content %>
221
+ </div>
222
+ <div class='attribution'>
223
+ <% if attr? :citetitle %>
224
+ <em><%= attr :citetitle %></em>
225
+ <% end %>
226
+ <% if attr? :attribution %>
227
+ <% if attr? :citetitle %>
228
+ <br/>
229
+ <% end %>
230
+ <%= "&#8212; " + attr(:attribution) %>
231
+ <% end %>
232
+ </div>
233
+ </div>
234
+ EOF
235
+ end
236
+ end
237
+
238
+ class SectionVerseTemplate < BaseTemplate
239
+ def template
240
+ @template ||= ERB.new <<-EOF
241
+ <div class='verseblock'>
242
+ <% if !title.nil? %>
243
+ <div class='title'><%= title %></div>
244
+ <% end %>
245
+ <pre class='content'><%= content %></pre>
246
+ <div class='attribution'>
247
+ <% if attr? :citetitle %>
248
+ <em><%= attr :citetitle %></em>
249
+ <% end %>
250
+ <% if attr? :attribution %>
251
+ <% if attr? :citetitle %>
252
+ <br/>
253
+ <% end %>
254
+ <%= "&#8212; " + attr(:attribution) %>
255
+ <% end %>
156
256
  </div>
157
257
  </div>
158
258
  EOF
@@ -165,7 +265,12 @@ class SectionUlistTemplate < BaseTemplate
165
265
  <div class='ulist'>
166
266
  <ul>
167
267
  <% content.each do |li| %>
168
- <%= li %>
268
+ <li>
269
+ <p><%= li.text %></p>
270
+ <% if !li.blocks.empty? %>
271
+ <%= li.content %>
272
+ <% end %>
273
+ </li>
169
274
  <% end %>
170
275
  </ul>
171
276
  </div>
@@ -173,47 +278,40 @@ class SectionUlistTemplate < BaseTemplate
173
278
  end
174
279
  end
175
280
 
176
- =begin
177
- ../gitscm-next/templates/section_colist.html.erb
178
- <div class='colist arabic'>
179
- <ol>
180
- <% content.each do |li| %>
181
- <li><p><%= li %></p></li>
182
- <% end %>
183
- </ol>
184
- </div>
185
- ../gitscm-next/templates/section_example.html.erb
186
- <div class='exampleblock'>
187
- <div class='content'>
188
- <div class='literalblock'>
189
- <div class='content'>
190
- <pre><tt><%= content %></tt></pre>
281
+ class SectionOlistTemplate < BaseTemplate
282
+ def template
283
+ @template ||= ERB.new <<-EOF
284
+ <div class='olist arabic'>
285
+ <ol class='arabic'>
286
+ <% content.each do |li| %>
287
+ <li>
288
+ <p><%= li.text %></p>
289
+ <% if !li.blocks.empty? %>
290
+ <%= li.content %>
291
+ <% end %>
292
+ </li>
293
+ <% end %>
294
+ </ol>
295
+ </div>
296
+ EOF
297
+ end
298
+ end
299
+
300
+ class SectionImageTemplate < BaseTemplate
301
+ def template
302
+ @template ||= ERB.new <<-EOF
303
+ <div class='imageblock'>
304
+ <div class='content'>
305
+ <% if attr :link %>
306
+ <a class='image' href='<%= attr :link%>'><img src='<%= attr :target %>' alt='<%= attr :alt %>'/></a>
307
+ <% else %>
308
+ <img src='<%= attr :target %>' alt='<%= attr :alt %>'/>
309
+ <% end %>
310
+ </div>
311
+ <% if title %>
312
+ <div class='title'><%= title %></div>
313
+ <% end %>
191
314
  </div>
192
- </div>
193
- </div>
194
- </div>
195
- ../gitscm-next/templates/section_oblock.html.erb
196
- <div class='openblock'>
197
- <div class='content'>
198
- <%= content %>
199
- </div>
200
- </div>
201
- ../gitscm-next/templates/section_olist.html.erb
202
- <div class='olist arabic'>
203
- <ol class='arabic'>
204
- <% content.each do |li| %>
205
- <li><p><%= li %></p></li>
206
- <% end %>
207
- </ol>
208
- </div>
209
- ../gitscm-next/templates/section_quote.html.erb
210
- <div class='quoteblock'>
211
- <div class='content'>
212
- <%= content %>
213
- </div>
214
- </div>
215
- ../gitscm-next/templates/section_verse.html.erb
216
- <div class='verseblock'>
217
- <pre class='content'><%= content %></pre>
218
- </div>
219
- =end
315
+ EOF
316
+ end
317
+ end