bookie 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,3 +62,7 @@ examples from <= 0.0.10. Move towards a book manifest type API. Much work needs
62
62
 
63
63
  Added rudimentary chapter support for EPUB, MOBI, and PDF. Render once per
64
64
  emitter rather than once per chapter per emitter (bugfix).
65
+
66
+ ## 0.0.13 (2011.05.23)
67
+
68
+ Basic inline code formatting. Horrible parser needs to go away...
@@ -8,7 +8,9 @@ book.chapter "Multiple paragraphs", "#{fixture_dir}/multi_paragraph_document.md"
8
8
  book.chapter "Preformatted text blocks", "#{fixture_dir}/preformatted_blocks.md"
9
9
  book.chapter "Section headings", "#{fixture_dir}/document_with_headings.md"
10
10
  book.chapter "Unordered lists", "#{fixture_dir}/lists.md"
11
+ book.chapter "Inline Formatting", "#{fixture_dir}/inline_formatting.md"
11
12
 
12
13
  book.render("bookie-basic-feature", [Bookie::Emitters::PDF.new,
13
14
  Bookie::Emitters::EPUB.new,
14
- Bookie::Emitters::MOBI.new])
15
+ Bookie::Emitters::MOBI.new,
16
+ Bookie::Emitters::HTML.new])
@@ -2,6 +2,7 @@ require "date"
2
2
  require "fileutils"
3
3
  require "tempfile"
4
4
  require "erb"
5
+ require "strscan"
5
6
 
6
7
  require "prawn"
7
8
  require "eeepub"
@@ -16,7 +16,18 @@ module Bookie
16
16
  end
17
17
 
18
18
  def build_paragraph(paragraph)
19
- @body << "<p>#{paragraph.contents}</p>"
19
+ @body << "<p>#{convert_inlines(paragraph.contents)}</p>"
20
+ end
21
+
22
+ def convert_inlines(contents)
23
+ contents.map do |c|
24
+ case c
25
+ when Bookie::NormalText
26
+ c.contents
27
+ when Bookie::CodeText
28
+ "<tt>#{c.contents}</tt>"
29
+ end
30
+ end.join.strip
20
31
  end
21
32
 
22
33
  def build_raw_text(raw_text)
@@ -67,14 +67,27 @@ module Bookie
67
67
  end
68
68
 
69
69
  def build_paragraph(paragraph)
70
+ para_text = convert_inlines(paragraph.contents)
71
+
70
72
  draw do
71
73
  font("serif", size: 9) do
72
- text(paragraph.contents.strip, align: :justify, leading: 2)
74
+ text(para_text, align: :justify, leading: 2, inline_format: true)
73
75
  end
74
76
  move_down in2pt(0.1)
75
77
  end
76
78
  end
77
79
 
80
+ def convert_inlines(contents)
81
+ contents.map do |c|
82
+ case c
83
+ when Bookie::NormalText
84
+ c.contents
85
+ when Bookie::CodeText
86
+ "<color rgb='660000'><font name='mono' size='9'>#{c.contents}</font></color>"
87
+ end
88
+ end.join.strip
89
+ end
90
+
78
91
  def build_raw_text(raw_text)
79
92
  sanitized_text = raw_text.contents.gsub(" ", Prawn::Text::NBSP).strip
80
93
 
@@ -3,6 +3,8 @@ module Bookie
3
3
  RawText = Struct.new(:contents)
4
4
  SectionHeading = Struct.new(:contents)
5
5
  List = Struct.new(:contents)
6
+ NormalText = Struct.new(:contents)
7
+ CodeText = Struct.new(:contents)
6
8
 
7
9
  class Parser
8
10
  def self.parse(raw_data, emitter=Bookie::Emitters::Null.new)
@@ -19,8 +21,25 @@ module Bookie
19
21
  parse_contents(raw_data)
20
22
  end
21
23
 
24
+ def extract_inlines(paragraph_text)
25
+ scanner = StringScanner.new(paragraph_text)
26
+ modes = [NormalText, CodeText].cycle
27
+ output = []
28
+
29
+ current_mode = modes.next
30
+ current_mode = modes.next if scanner.scan(/`/)
31
+
32
+ until scanner.eos?
33
+ output << current_mode.new(scanner.scan(/[^`]+/m))
34
+ current_mode = modes.next if scanner.scan(/`/)
35
+ end
36
+
37
+ output
38
+ end
39
+
22
40
  def extract_paragraph(paragraph_text)
23
- paragraph = Paragraph.new(paragraph_text.gsub(/\s+/," "))
41
+ text_segments = extract_inlines(paragraph_text.gsub(/\s+/," "))
42
+ paragraph = Paragraph.new(text_segments)
24
43
  @emitter.build_paragraph(paragraph)
25
44
  parsed_content << paragraph
26
45
  end
@@ -1,3 +1,3 @@
1
1
  module Bookie
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -0,0 +1,17 @@
1
+ As you can see in the code above, I decided that my `Piece#paint` method was
2
+ probably better off as `Canvas#paint_shape`, just to collect the presentation
3
+ logic in one place. Here’s what the updated code ended up looking like.
4
+
5
+ class Canvas
6
+ # ...
7
+
8
+ def paint_shape(shape, position)
9
+ shape.translated_points(position).each do |point|
10
+ paint(point, Piece::SYMBOL)
11
+ end
12
+ end
13
+ end
14
+
15
+ This new code does not rely directly on the `Piece#points` method anymore, but
16
+ instead, passes a position to the newly created `Piece#translated_points` to get a
17
+ set of coordinates anchored by the specified position.
@@ -12,7 +12,7 @@ context "A Parser" do
12
12
  assert_equal 8, parsed_content.length
13
13
 
14
14
  actual_paragraph = parsed_content[4]
15
- actual_paragraph_text = actual_paragraph.first
15
+ actual_paragraph_text = actual_paragraph.first[0].contents
16
16
 
17
17
  assert_equal sample_paragraph_text, actual_paragraph_text
18
18
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bookie
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.12
5
+ version: 0.0.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gregory Brown
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-12 00:00:00 -04:00
13
+ date: 2011-05-23 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -56,6 +56,7 @@ files:
56
56
  - lib/bookie/version.rb
57
57
  - lib/bookie.rb
58
58
  - test/fixtures/document_with_headings.md
59
+ - test/fixtures/inline_formatting.md
59
60
  - test/fixtures/lists.md
60
61
  - test/fixtures/multi_paragraph_document.md
61
62
  - test/fixtures/preformatted_blocks.md