bookie 0.0.2 → 0.0.3
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.
- data/CHANGELOG.md +12 -0
- data/README.md +3 -3
- data/examples/simple_emitters.rb +10 -0
- data/lib/bookie.rb +3 -0
- data/lib/bookie/document.rb +8 -4
- data/lib/bookie/emitters.rb +51 -0
- data/lib/bookie/parser.rb +7 -4
- data/lib/bookie/version.rb +1 -1
- metadata +15 -3
data/CHANGELOG.md
CHANGED
@@ -2,3 +2,15 @@
|
|
2
2
|
|
3
3
|
Add some barely functional Parser and Document object stubs, initial gem release
|
4
4
|
to claim the namespace.
|
5
|
+
|
6
|
+
## 0.0.2 (2011.04.23)
|
7
|
+
|
8
|
+
Create some stubs for Paragraph and ContentTree objects, enough for us to start
|
9
|
+
thinking about what the emitter API might look like. But not really enough to do
|
10
|
+
anything else.
|
11
|
+
|
12
|
+
## 0.0.3 (2011.04.23)
|
13
|
+
|
14
|
+
Added some basic emitters for PDF and HTML paragraphs. Note these are proofs of
|
15
|
+
concept ONLY, not meant for practical use. See examples/simple_emitters.rb to
|
16
|
+
see how they're used.
|
data/README.md
CHANGED
@@ -17,9 +17,9 @@ put together a proper release plan.
|
|
17
17
|
|
18
18
|
## Dependencies
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
Bookie targets Ruby 1.9.2 exclusively, and will not run on Ruby 1.8.
|
21
|
+
Currently, the only direct dependency we use is Prawn, but that may change in
|
22
|
+
the future.
|
23
23
|
|
24
24
|
## Contributing
|
25
25
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative "../lib/bookie"
|
2
|
+
Prawn.debug = true
|
3
|
+
|
4
|
+
test_file = "#{File.dirname(__FILE__)}/../test/fixtures/multi_paragraph_document.md"
|
5
|
+
|
6
|
+
html_document = Bookie::Document.new(test_file, Bookie::Emitters::HTML.new)
|
7
|
+
File.open("output.html", "w") { |f| f << html_document.render }
|
8
|
+
|
9
|
+
pdf_document = Bookie::Document.new(test_file, Bookie::Emitters::PDF.new)
|
10
|
+
File.open("output.pdf", "w") { |f| f << pdf_document.render }
|
data/lib/bookie.rb
CHANGED
data/lib/bookie/document.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
module Bookie
|
2
2
|
class Document
|
3
|
-
def initialize(filename, parser=Bookie::Parser)
|
4
|
-
@
|
5
|
-
@contents = parser.parse(File.read(filename))
|
3
|
+
def initialize(filename, emitter=Bookie::Emitters::Null.new, parser=Bookie::Parser)
|
4
|
+
@emitter = emitter
|
5
|
+
@contents = parser.parse(File.read(filename), emitter)
|
6
6
|
end
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :emitter, :contents
|
9
|
+
|
10
|
+
def render
|
11
|
+
@emitter.render
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Bookie
|
2
|
+
module Emitters
|
3
|
+
class Null
|
4
|
+
def build_paragraph(paragraph)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class HTML
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@output = ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_paragraph(paragraph)
|
15
|
+
@output << "<p>#{paragraph.children.first}</p>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def render
|
19
|
+
"<html><body>#{@output}</body></html>"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class PDF
|
24
|
+
include Prawn::Measurements
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@document = new_prawn_document
|
28
|
+
@paragraphs = []
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_paragraph(paragraph)
|
32
|
+
@paragraphs << paragraph.children.first.gsub(/\s+/," ")
|
33
|
+
end
|
34
|
+
|
35
|
+
def render
|
36
|
+
@document.text(@paragraphs.join("\n\n"), align: :justify, size: 10)
|
37
|
+
@document.render
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def new_prawn_document
|
43
|
+
Prawn::Document.new( top_margin: in2pt(0.75),
|
44
|
+
bottom_margin: in2pt(1),
|
45
|
+
left_margin: in2pt(1),
|
46
|
+
right_margin: in2pt(1),
|
47
|
+
page_size: [in2pt(7.0), in2pt(9.19)] )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/bookie/parser.rb
CHANGED
@@ -3,20 +3,23 @@ module Bookie
|
|
3
3
|
Paragraph = Struct.new(:children)
|
4
4
|
|
5
5
|
class Parser
|
6
|
-
def self.parse(contents)
|
7
|
-
parser = new(contents)
|
6
|
+
def self.parse(contents, emitter=Bookie::Emitters::Null.new)
|
7
|
+
parser = new(contents, emitter)
|
8
8
|
parser.document_tree
|
9
9
|
end
|
10
10
|
|
11
11
|
attr_reader :document_tree
|
12
12
|
|
13
|
-
def initialize(contents)
|
13
|
+
def initialize(contents, emitter)
|
14
|
+
@emitter = emitter
|
14
15
|
generate_document_tree(contents)
|
15
16
|
end
|
16
17
|
|
17
18
|
def extract_paragraphs(contents)
|
18
19
|
contents.split(/\n\n+/).each do |e|
|
19
|
-
|
20
|
+
paragraph = Paragraph.new([e])
|
21
|
+
@emitter.build_paragraph(paragraph)
|
22
|
+
document_tree.children << paragraph
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
data/lib/bookie/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bookie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gregory Brown
|
@@ -12,8 +12,18 @@ cert_chain: []
|
|
12
12
|
|
13
13
|
date: 2011-04-23 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: prawn
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.11.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
17
27
|
description: Eventually this may be a markdown to PDF, ePUB, MOBI processor. For now it's just something I'm playing around with, so use at your own risk
|
18
28
|
email:
|
19
29
|
- gregory.t.brown@gmail.com
|
@@ -25,6 +35,7 @@ extra_rdoc_files: []
|
|
25
35
|
|
26
36
|
files:
|
27
37
|
- lib/bookie/document.rb
|
38
|
+
- lib/bookie/emitters.rb
|
28
39
|
- lib/bookie/parser.rb
|
29
40
|
- lib/bookie/version.rb
|
30
41
|
- lib/bookie.rb
|
@@ -34,6 +45,7 @@ files:
|
|
34
45
|
- test/test_helper.rb
|
35
46
|
- test/units/document_test.rb
|
36
47
|
- test/units/parser_test.rb
|
48
|
+
- examples/simple_emitters.rb
|
37
49
|
- GPLv3
|
38
50
|
- README.md
|
39
51
|
- CHANGELOG.md
|