bookie 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/examples/lists.rb +24 -0
- data/lib/bookie/emitters.rb +33 -0
- data/lib/bookie/parser.rb +20 -1
- data/lib/bookie/version.rb +1 -1
- data/test/fixtures/lists.md +19 -0
- data/test/units/parser_test.rb +15 -0
- metadata +4 -2
data/CHANGELOG.md
CHANGED
@@ -37,3 +37,9 @@ iPad+iBooks.
|
|
37
37
|
Hack in section headings, right now using the ## syntax from markdown.
|
38
38
|
Copy-paste lots of stuff from github.com/madriska/jambalaya, including the
|
39
39
|
DejaVu font sets. Make PDF output look pretty, but the source code look ugly.
|
40
|
+
|
41
|
+
## 0.0.8 (2011.04.28)
|
42
|
+
|
43
|
+
Basic support for unordered lists. The ePUB output has not been tested yet,
|
44
|
+
because most desktop based ePUB readers suck and I don't have an iPad. Will ask
|
45
|
+
friends to test soon.
|
data/examples/lists.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "../lib/bookie"
|
2
|
+
Prawn.debug = true
|
3
|
+
|
4
|
+
file = "#{File.dirname(__FILE__)}/../test/fixtures/lists.md"
|
5
|
+
|
6
|
+
pdf_document = Bookie::Document.new(file, Bookie::Emitters::PDF.new(
|
7
|
+
header: "Ruby Mendicant University", title: "Project Guidelines"))
|
8
|
+
|
9
|
+
pdf_document.render(file: "output.pdf")
|
10
|
+
|
11
|
+
html_document = Bookie::Document.new(file, Bookie::Emitters::HTML.new)
|
12
|
+
|
13
|
+
html_document.render(title: "Project Guidelines",
|
14
|
+
file: "output.html")
|
15
|
+
|
16
|
+
mobi_document = Bookie::Document.new(file, Bookie::Emitters::MOBI.new)
|
17
|
+
|
18
|
+
mobi_document.render(title: "Project Guidelines",
|
19
|
+
file: "output.mobi")
|
20
|
+
|
21
|
+
epub_document = Bookie::Document.new(file, Bookie::Emitters::EPUB.new)
|
22
|
+
|
23
|
+
epub_document.render(title: "Project Guidelines",
|
24
|
+
file: "output.epub")
|
data/lib/bookie/emitters.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
1
3
|
module Bookie
|
2
4
|
module Emitters
|
3
5
|
class Null
|
@@ -9,6 +11,9 @@ module Bookie
|
|
9
11
|
|
10
12
|
def build_section_heading(header)
|
11
13
|
end
|
14
|
+
|
15
|
+
def build_list(content)
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
class HTML
|
@@ -30,6 +35,11 @@ module Bookie
|
|
30
35
|
@body << "<h2>#{header.contents}</h2>"
|
31
36
|
end
|
32
37
|
|
38
|
+
def build_list(list)
|
39
|
+
list_elements = list.contents.map { |li| "<li>#{li}</li>" }.join
|
40
|
+
@body << "<ul>"+list_elements+"</ul>"
|
41
|
+
end
|
42
|
+
|
33
43
|
def render(params)
|
34
44
|
File.open(params[:file], "w") do |file|
|
35
45
|
file << %{
|
@@ -82,6 +92,8 @@ module Bookie
|
|
82
92
|
h2 { font-size: large }
|
83
93
|
p { margin-bottom: 1.1em; text-indent: 0 }
|
84
94
|
pre { font-size: xx-small }
|
95
|
+
li { margin-bottom: 1.1em }
|
96
|
+
ul { margin-top: 0em; margin-bottom: 0em;}
|
85
97
|
</style>
|
86
98
|
</head>
|
87
99
|
<body><h1>#{params[:title]}</h1>#{@body}</body>
|
@@ -106,6 +118,27 @@ module Bookie
|
|
106
118
|
render_header(params)
|
107
119
|
end
|
108
120
|
|
121
|
+
def build_list(list)
|
122
|
+
items = list.contents
|
123
|
+
|
124
|
+
@document.instance_eval do
|
125
|
+
font("serif", :size => 9) do
|
126
|
+
items.each do |li|
|
127
|
+
float { text "•" }
|
128
|
+
indent(in2pt(0.15)) do
|
129
|
+
text li.gsub(/\s+/," "),
|
130
|
+
inline_format: true,
|
131
|
+
leading: 2
|
132
|
+
end
|
133
|
+
|
134
|
+
move_down in2pt(0.05)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
move_down in2pt(0.05)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
109
142
|
def build_section_heading(section_text)
|
110
143
|
@document.move_down in2pt(0.1)
|
111
144
|
|
data/lib/bookie/parser.rb
CHANGED
@@ -2,6 +2,7 @@ module Bookie
|
|
2
2
|
Paragraph = Struct.new(:contents)
|
3
3
|
RawText = Struct.new(:contents)
|
4
4
|
SectionHeading = Struct.new(:contents)
|
5
|
+
List = Struct.new(:contents)
|
5
6
|
|
6
7
|
class Parser
|
7
8
|
def self.parse(raw_data, emitter=Bookie::Emitters::Null.new)
|
@@ -36,6 +37,12 @@ module Bookie
|
|
36
37
|
parsed_content << header
|
37
38
|
end
|
38
39
|
|
40
|
+
def extract_list(contents)
|
41
|
+
list = List.new(contents.map { |e| e.chomp })
|
42
|
+
@emitter.build_list(list)
|
43
|
+
parsed_content << list
|
44
|
+
end
|
45
|
+
|
39
46
|
private
|
40
47
|
|
41
48
|
def parse_contents(raw_data)
|
@@ -52,17 +59,27 @@ module Bookie
|
|
52
59
|
when /^ {4,}/
|
53
60
|
mode = :raw
|
54
61
|
chunk = line[4..-1]
|
62
|
+
when /^\* /
|
63
|
+
mode = :list
|
64
|
+
chunk = [line[2..-1]]
|
55
65
|
else
|
56
66
|
mode = :paragraph
|
57
67
|
chunk = line
|
58
68
|
end
|
59
69
|
when mode == :raw
|
60
|
-
chunk << (line.
|
70
|
+
chunk << (line.strip.empty? ? "\n" : line[4..-1].to_s)
|
61
71
|
|
62
72
|
if lines.first =~ /^ {0,3}\S/
|
63
73
|
mode = nil
|
64
74
|
extract_raw_text(chunk)
|
65
75
|
end
|
76
|
+
when mode == :list
|
77
|
+
chunk << line[2..-1].to_s unless line.strip.empty?
|
78
|
+
|
79
|
+
if lines.first.to_s.strip.length > 0 && lines.first !~ /^\*/
|
80
|
+
mode = nil
|
81
|
+
extract_list(chunk)
|
82
|
+
end
|
66
83
|
when mode == :paragraph
|
67
84
|
if line.chomp.empty?
|
68
85
|
mode = nil
|
@@ -78,6 +95,8 @@ module Bookie
|
|
78
95
|
extract_paragraph(chunk)
|
79
96
|
when :raw
|
80
97
|
extract_raw_text(chunk)
|
98
|
+
when :list
|
99
|
+
extract_list(chunk)
|
81
100
|
end
|
82
101
|
end
|
83
102
|
end
|
data/lib/bookie/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
Please note the following guidelines when making your proposal.
|
2
|
+
|
3
|
+
* You will be evaluated on work done via the 3/7-3/28 period only, so be sure to focus your proposal on the areas of your project that you plan to make progress on during that time period
|
4
|
+
|
5
|
+
* The core skills course involves a considerable amount of assigned work that needs to be completed in addition to your individual project. To avoid feeling overwhelmed, choose an individual project that is only slightly challenging based on your current level of experience.
|
6
|
+
|
7
|
+
* You are not expected to build a feature-complete complete application, but each checkpoint requires you to produce real, functioning features rather than just raw structures or rough prototypes.
|
8
|
+
|
9
|
+
* Your project must use a GPLv3 compatible free software license. Both the MIT and BSD licenses are popular in Ruby projects, and are the best choice if you don't know or care about the finer details of the other available options.
|
10
|
+
|
11
|
+
* Your project can be pretty much anything Ruby related, as long as it does something useful, and involves writing a reasonable amount of Ruby code.
|
12
|
+
|
13
|
+
* Up to three students can work on the same project, but each must have a clearly defined proposal for the work they plan to do, and each proposal will be evaluated individually.
|
14
|
+
|
15
|
+
* You must use a public git repository for developing your individual project (typically done via github)
|
16
|
+
|
17
|
+
If you have any questions about these requirements feel free to let me know. The
|
18
|
+
individual project is one of the most important things you can do at RbMU, so we
|
19
|
+
want to do all that we can to help you succeed.
|
data/test/units/parser_test.rb
CHANGED
@@ -35,4 +35,19 @@ context "A Parser" do
|
|
35
35
|
|
36
36
|
assert_equal "Continuations are Evil?", actual_heading_text
|
37
37
|
end
|
38
|
+
|
39
|
+
test "should know about list elements" do
|
40
|
+
sample_text = File.read(fixture("lists.md"))
|
41
|
+
parsed_content = Bookie::Parser.parse(sample_text)
|
42
|
+
|
43
|
+
assert_equal 3, parsed_content.length
|
44
|
+
|
45
|
+
assert_equal 8, parsed_content[1].contents.length
|
46
|
+
|
47
|
+
expected_li4 = "Your project can be pretty much anything Ruby related, "+
|
48
|
+
"as long as it does something useful, and involves writing "+
|
49
|
+
"a reasonable amount of Ruby code."
|
50
|
+
|
51
|
+
assert_equal expected_li4, parsed_content[1].contents[4]
|
52
|
+
end
|
38
53
|
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.
|
5
|
+
version: 0.0.8
|
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-04-
|
13
|
+
date: 2011-04-28 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/bookie/version.rb
|
52
52
|
- lib/bookie.rb
|
53
53
|
- test/fixtures/document_with_headings.md
|
54
|
+
- test/fixtures/lists.md
|
54
55
|
- test/fixtures/multi_paragraph_document.md
|
55
56
|
- test/fixtures/preformatted_blocks.md
|
56
57
|
- test/fixtures/single_paragraph.md
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- test/units/document_test.rb
|
60
61
|
- test/units/parser_test.rb
|
61
62
|
- examples/headings.rb
|
63
|
+
- examples/lists.rb
|
62
64
|
- examples/preformatted.rb
|
63
65
|
- examples/simple_emitters.rb
|
64
66
|
- doc/banner.png
|