srdperu-prawn-format 0.1.1.2 → 0.1.2

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/examples/document.rb DELETED
@@ -1,61 +0,0 @@
1
- #coding: utf-8
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- require "prawn"
5
- require "prawn/format"
6
-
7
- Prawn::Document.generate("document.pdf") do
8
- tags :h1 => { :font_size => "2em", :font_weight => :bold },
9
- :h2 => { :font_size => "1.5em", :font_weight => :bold },
10
- :stave => { :display => :break, :meta => { :name => :anchor }, :font_weight => :bold, :font_size => "2em" },
11
- :title => { :font_weight => :bold, :font_size => "1.5em" },
12
- :indent => { :width => "2em" }
13
-
14
- font "Times-Roman", :size => 14
15
- File.open("#{File.dirname(__FILE__)}/christmas-carol.txt") do |story|
16
- line_number = 0
17
- story.each_line do |line|
18
- line_number += 1
19
- next if line.strip == ""
20
-
21
- type, data = line.match(/^(\w+)\.\s*(.*)/)[1,2]
22
-
23
- case type
24
- when "h1"
25
- move_text_position 144
26
- text "<h1>#{data}</h1>", :align => :center
27
- move_text_position 72
28
-
29
- when "h2"
30
- text "<h2>#{data}</h2>", :align => :center
31
- move_text_position 72
32
-
33
- when "toc"
34
- bounding_box [bounds.left+bounds.width/4, y-bounds.absolute_bottom], :width => bounds.width do
35
- text(data)
36
- end
37
-
38
- when "stave"
39
- start_new_page
40
- text(data, :align => :center)
41
- move_text_position 72
42
-
43
- when "p"
44
- text("<indent/>" + data, :align => :justify)
45
-
46
- when "song"
47
- move_text_position font_size/2
48
- text(data, :align => :center)
49
- move_text_position font_size/2
50
-
51
- when "block"
52
- text(data, :align => :justify)
53
-
54
- when "stop"
55
- break
56
-
57
- else raise "unknown block type #{type.inspect} (line \##{line_number})"
58
- end
59
- end
60
- end
61
- end
data/examples/flowing.rb DELETED
@@ -1,24 +0,0 @@
1
- #coding: utf-8
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- require 'prawn'
5
- require 'prawn/format'
6
-
7
- dice = "#{Prawn::BASEDIR}/data/images/dice.png"
8
- Prawn::Document.generate "flowing.pdf" do
9
- # first, position an image that we'll flow around
10
- width = bounds.width / 2 - 18 # give us some padding on the left of the image
11
- info = image(dice, :width => width, :position => :right)
12
-
13
- # create the layout helper that we'll use to flow the text
14
- layout(DATA.read, :align => :justify) do |helper|
15
- # fill the first box
16
- y = helper.fill(bounds.left, bounds.top, width, :height => info.scaled_height + font_size - 1)
17
-
18
- # fill the rest
19
- self.y = helper.fill(bounds.left, y, bounds.width)
20
- end
21
- end
22
-
23
- __END__
24
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut neque. Maecenas scelerisque euismod purus. Nam venenatis. Sed velit mauris, cursus sit amet, semper vitae, sagittis quis, tortor. Nam at nisi. Sed ac nibh. Curabitur auctor ipsum nec tellus. Suspendisse potenti. Morbi dapibus magna a velit. Ut fringilla enim eu enim. Quisque lacinia, arcu dignissim gravida semper, eros quam tempor nisi, non scelerisque massa odio ut mi. Nullam ac ipsum. Proin volutpat tristique sem. Sed ipsum felis, volutpat vel, porttitor id, volutpat eu, mauris. Cras eget nulla sit amet dolor cursus semper. Curabitur nulla nunc, accumsan sit amet, vestibulum sit amet, adipiscing in, lorem. Pellentesque sodales purus sit amet odio. Cras commodo. Nam accumsan. Suspendisse potenti. Fusce posuere neque in nulla. Ut cursus blandit nisl. Phasellus ut nulla quis nunc tempus consequat. In hac habitasse platea dictumst. Praesent molestie nisl nec erat. Vivamus pretium nibh sit amet est. Integer dolor. Sed dictum blandit purus. Quisque et mauris vel diam dictum dignissim. Maecenas ultrices. Cras leo risus, tristique quis, hendrerit eu, condimentum tempor, mi. Nullam consectetur ante non nisl. Nulla dignissim sem in turpis. Cras purus felis, molestie ac, rhoncus sed, suscipit et, nisl. Donec tempus justo eu turpis. Aenean quis diam at dolor interdum tempor. Mauris sed nulla vitae erat lobortis lacinia. Nunc mauris. Aliquam mattis egestas ligula. Morbi magna dolor, convallis id, interdum lacinia, pellentesque eu, velit. In non arcu. Duis a nibh. Vestibulum volutpat erat et magna. Vivamus mi ante, aliquam et, vulputate sit amet, pretium non, ligula. Curabitur elementum, nisl ut gravida placerat, nisl sapien posuere augue, a placerat urna enim in velit. Cras nisi. Suspendisse volutpat. Ut eu lorem sed eros sollicitudin volutpat. Quisque blandit, libero sed mattis scelerisque, elit turpis ultricies purus, quis faucibus orci erat quis sem. Vestibulum imperdiet facilisis ante. Mauris dignissim, arcu vitae tincidunt congue, ante nulla aliquam purus, a porta tellus nisl at lectus. Phasellus commodo lacus et tortor. Etiam tortor leo, scelerisque sit amet, lobortis non, gravida vitae, mi. Donec eget augue. Sed ultrices ipsum eget risus. Aliquam rhoncus arcu vitae orci pellentesque pulvinar. Praesent ornare, lacus eget elementum ultrices, massa justo dignissim massa, a suscipit elit nibh quis arcu. Aliquam non massa. Etiam pharetra nisi at risus. Donec felis turpis, suscipit a, luctus vulputate, lobortis id, neque. Proin vitae nibh. Pellentesque nibh risus, volutpat sollicitudin, lobortis vitae, malesuada eu, elit. Duis felis nulla, sagittis id, faucibus luctus, viverra id, eros. Phasellus vulputate leo eget libero. Ut ut ipsum ac dui accumsan placerat. Integer porttitor. Quisque gravida dolor eu diam. Phasellus sodales sem sit amet urna. Morbi ornare viverra mauris.
@@ -1,12 +0,0 @@
1
- #coding: utf-8
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- require 'prawn'
5
- require 'prawn/format'
6
-
7
- Prawn::Document.generate "style-classes.pdf" do
8
- styles :quote => { :font_style => :italic },
9
- :product => { :font_weight => :bold, :color => "#007" }
10
-
11
- text "<span class='product'>Prawn</span> is a fantastic utility for formatting PDF's. Jamis Buck may once have said, speaking of <span class='product'>Prawn</span>, <span class='quote'>\"<span class='product'>Prawn</span> is <em>the</em> single most fantastic PDF creation library ever to be written. In Ruby. In 2008. By Greg Brown.\"</span>"
12
- end
@@ -1,31 +0,0 @@
1
- #coding: utf-8
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- require 'prawn'
5
- require 'prawn/format'
6
-
7
- begin
8
- require 'coderay'
9
- rescue LoadError
10
- abort "This example (#{__FILE__}) requires the 'coderay' gem.\n" +
11
- "Please make sure it is installed."
12
- end
13
-
14
- # Use CodeRay to parse the source and return HTML
15
- html = CodeRay.scan(File.read(__FILE__), :ruby).html(:line_numbers => :inline)
16
-
17
- # Use prawn and prawn/format to parse and format the HTML
18
- Prawn::Document.generate "syntax-highlighting.pdf", :page_layout => :landscape do
19
- styles :no => { :color => "gray" },
20
- :c => { :color => "#666" },
21
- :s => { :color => "#d20" },
22
- :dl => { :color => "black" },
23
- :co => { :color => "#036", :font_weight => :bold },
24
- :pc => { :color => "#038", :font_weight => :bold },
25
- :sy => { :color => "#A60" },
26
- :r => { :color => "#080" },
27
- :i => { :color => "#00D", :font_weight => :bold },
28
- :idl => { :color => "#888", :font_weight => :bold }
29
-
30
- text "<pre>#{html}</pre>"
31
- end
data/examples/tags.rb DELETED
@@ -1,24 +0,0 @@
1
- #coding: utf-8
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- require 'prawn'
5
- require 'prawn/format'
6
-
7
- CHINESE_FONT = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
8
-
9
- Prawn::Document.generate "tags.pdf" do
10
- # tweak an existing tag
11
- tags[:em][:color] = "red"
12
-
13
- # completely redefine an existing tag
14
- tags[:strong] = { :text_decoration => :underline }
15
-
16
- # define altogether new tags
17
- tags :chinese => { :font_family => CHINESE_FONT },
18
- :exp => { :vertical_align => :super, :font_size => "70%", :color => "blue", :font_weight => :bold },
19
- :header => { :font_weight => :bold, :font_size => 24, :text_decoration => :underline }
20
-
21
- text "<header>Fun with Tags</header>"
22
-
23
- text "<em>Emphasized text</em>, <strong>strong text</strong>, <chinese>汉语</chinese>, and <code>E = mc<exp>2</exp></code>"
24
- end
data/manual/html.rb DELETED
@@ -1,187 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
- require 'prawn/format/version'
3
- require 'coderay'
4
-
5
- def process_style(document, style, content, line_number)
6
- content = process_substitutions(content)
7
-
8
- case style
9
- when "h1" then h1(document, content)
10
- when "h2" then h2(document, content)
11
- when "p" then paragraph(document, content)
12
- when "fp" then paragraph(document, content, false)
13
- when "ul" then start_list(document)
14
- when "li" then list_item(document, content)
15
- when "/ul" then end_list(document)
16
- when "page" then new_page(document)
17
- when "highlight" then highlight(document, content)
18
- when "hr" then horiz_rule(document)
19
- when "center" then center(document, content)
20
- else warn "unknown style #{style.inspect}"
21
- end
22
-
23
- rescue Exception => err
24
- puts "[error occurred while processing line ##{line_number}]"
25
- raise
26
- end
27
-
28
- def process_substitutions(content)
29
- content.
30
- gsub(/%FORMAT:VERSION%/, Prawn::Format::Version::STRING).
31
- gsub(/%NOW%/, Time.now.utc.strftime("%e %B %Y at %H:%M UTC")).
32
- gsub(/%PDF\{(.*?)\}HTML\{(.*?)\}END%/, '\\2')
33
- end
34
-
35
- def center(document, content)
36
- document << "<center>#{content}</center>\n"
37
- end
38
-
39
- def horiz_rule(document)
40
- document << "<hr />\n"
41
- end
42
-
43
- def h1(document, content)
44
- document << "<h1>#{content}</h1>\n"
45
- end
46
-
47
- def h2(document, content)
48
- document << "<h2>#{content}</h2>\n"
49
- end
50
-
51
- def paragraph(document, content, indent=true)
52
- return unless content.strip.length > 0
53
- document << "<p class='#{indent ? 'indent' : ''}'>#{content}</p>\n"
54
- end
55
-
56
- def start_list(document)
57
- document << "<ul>\n"
58
- end
59
-
60
- def list_item(document, content)
61
- document << "<li>#{content}</li>\n"
62
- end
63
-
64
- def end_list(document)
65
- document << "</ul>\n"
66
- end
67
-
68
- def new_page(document)
69
- document << "<hr />\n"
70
- end
71
-
72
- def highlight(document, content)
73
- file, syntax = content.split(/,/)
74
- analyzed = CodeRay.scan(File.read(File.join(File.dirname(__FILE__), file)), syntax.to_sym)
75
- document << "<pre class='highlight'>#{analyzed.html}</pre>"
76
- end
77
-
78
- File.open("prawn-format.html", "w") do |html|
79
- html << "<html>\n<head>\n<style type='text/css'>#{DATA.read}</style>\n</head>"
80
- html << "<body>\n"
81
- File.open("#{File.dirname(__FILE__)}/manual.txt") do |source|
82
- number = 0
83
- source.each_line do |line|
84
- number += 1
85
- line.chomp!
86
- next if line.length == 0
87
-
88
- style, content = line.match(/^(\S+)\.\s*(.*)/)[1,2]
89
- process_style(html, style, content, number)
90
- end
91
- end
92
- html << "</body>\n</html>\n"
93
- end
94
-
95
- __END__
96
- body {
97
- margin-left: 15%;
98
- margin-right: 15%;
99
- margin-top: 1em;
100
- }
101
-
102
- pre.highlight {
103
- background-color: #f8f8f8;
104
- border: 1px solid silver;
105
- font-family: Courier, monospace;
106
- font-size: 90%;
107
- color: #100;
108
- line-height: 1.1em;
109
- padding: 1em;
110
- }
111
-
112
- .highlight .af { color:#00C }
113
- .highlight .an { color:#007 }
114
- .highlight .av { color:#700 }
115
- .highlight .aw { color:#C00 }
116
- .highlight .bi { color:#509; font-weight:bold }
117
- .highlight .c { color:#888 }
118
-
119
- .highlight .ch { color:#04D }
120
- .highlight .ch .k { color:#04D }
121
- .highlight .ch .dl { color:#039 }
122
-
123
- .highlight .cl { color:#B06; font-weight:bold }
124
- .highlight .co { color:#036; font-weight:bold }
125
- .highlight .cr { color:#0A0 }
126
- .highlight .cv { color:#369 }
127
- .highlight .df { color:#099; font-weight:bold }
128
- .highlight .di { color:#088; font-weight:bold }
129
- .highlight .dl { color:black }
130
- .highlight .do { color:#970 }
131
- .highlight .ds { color:#D42; font-weight:bold }
132
- .highlight .e { color:#666; font-weight:bold }
133
- .highlight .en { color:#800; font-weight:bold }
134
- .highlight .er { color:#F00; background-color:#FAA }
135
- .highlight .ex { color:#F00; font-weight:bold }
136
- .highlight .fl { color:#60E; font-weight:bold }
137
- .highlight .fu { color:#06B; font-weight:bold }
138
- .highlight .gv { color:#d70; font-weight:bold }
139
- .highlight .hx { color:#058; font-weight:bold }
140
- .highlight .i { color:#00D; font-weight:bold }
141
- .highlight .ic { color:#B44; font-weight:bold }
142
-
143
- .highlight .il { background: #eee }
144
- .highlight .il .il { background: #ddd }
145
- .highlight .il .il .il { background: #ccc }
146
- .highlight .il .dl { font-weight: bold ! important; color: #888 ! important }
147
-
148
- .highlight .in { color:#B2B; font-weight:bold }
149
- .highlight .iv { color:#33B }
150
- .highlight .la { color:#970; font-weight:bold }
151
- .highlight .lv { color:#963 }
152
- .highlight .oc { color:#40E; font-weight:bold }
153
- .highlight .on { color:#000; font-weight:bold }
154
- .highlight .op { }
155
- .highlight .pc { color:#038; font-weight:bold }
156
- .highlight .pd { color:#369; font-weight:bold }
157
- .highlight .pp { color:#579 }
158
- .highlight .pt { color:#339; font-weight:bold }
159
- .highlight .r { color:#080; font-weight:bold }
160
-
161
- .highlight .rx { background-color:#fff0ff }
162
- .highlight .rx .k { color:#808 }
163
- .highlight .rx .dl { color:#404 }
164
- .highlight .rx .mod { color:#C2C }
165
- .highlight .rx .fu { color:#404; font-weight: bold }
166
-
167
- .highlight .s { background-color:#fff0f0 }
168
- .highlight .s .s { background-color:#ffe0e0 }
169
- .highlight .s .s .s { background-color:#ffd0d0 }
170
- .highlight .s .k { color:#D20 }
171
- .highlight .s .dl { color:#710 }
172
-
173
- .highlight .sh { background-color:#f0fff0 }
174
- .highlight .sh .k { color:#2B2 }
175
- .highlight .sh .dl { color:#161 }
176
-
177
- .highlight .sy { color:#A60 }
178
- .highlight .sy .k { color:#A60 }
179
- .highlight .sy .dl { color:#630 }
180
-
181
- .highlight .ta { color:#070 }
182
- .highlight .tf { color:#070; font-weight:bold }
183
- .highlight .ts { color:#D70; font-weight:bold }
184
- .highlight .ty { color:#339; font-weight:bold }
185
- .highlight .v { color:#036 }
186
- .highlight .xt { color:#444 }
187
-
@@ -1,6 +0,0 @@
1
- require 'prawn'
2
- require 'prawn/format'
3
-
4
- Prawn::Document.generate('basics.pdf') do
5
- text "Some <b>bold</b> and <i>italic</i> text"
6
- end
@@ -1,13 +0,0 @@
1
- # renders all on one line
2
- text <<-TEXT
3
- &bull; Item one
4
- &bull; Item two
5
- &bull; Item three
6
- TEXT
7
-
8
- # renders all on three separate lines
9
- text <<-TEXT
10
- &bull; Item one<br/>
11
- &bull; Item two<br/>
12
- &bull; Item three
13
- TEXT
@@ -1,10 +0,0 @@
1
- Prawn::Document.generate('basics.pdf') do
2
- tags :h1 => { :font_size => "3em", :font_weight => :bold },
3
- :h2 => { :font_size => "2em", :font_style => :italic },
4
- :product => { :color => "red",
5
- :text_decoration => :underline }
6
-
7
- text "<h1>Manual</h1>"
8
- text "<h2>Learning to do stuff</h2>"
9
- text "<product>Prawn</product> is a PDF generator for Ruby"
10
- end
@@ -1,2 +0,0 @@
1
- tags[:em][:color] = "red"
2
- text "This really <em>matters</em>!"
@@ -1,4 +0,0 @@
1
- tags[:indent] = { :width => "2em" }
2
-
3
- text "<indent/>Once upon a time, far, far away..."
4
- text "<indent/>But the prince was not discouraged! ..."
@@ -1,15 +0,0 @@
1
- # force unformatted display
2
- text "Show <b>this</b> verbatim", :plain => true
3
-
4
- # force formatted display for full justification
5
- text "I want this to be fully justified", :plain => false,
6
- :align => :justify
7
-
8
- # assume all text is blue
9
- text "Blue text", :plain => false,
10
- :default_style => { :color => "blue" }
11
-
12
- # one-off tag and style definitions
13
- text "<nifty class='orange'>Nifty!</nifty>",
14
- :tags => { :nifty => { :font_weight => :bold } },
15
- :styles => { :orange => { :color => "#fa0" } }
@@ -1,5 +0,0 @@
1
- styles :product => { :color => "navy" },
2
- :ruby => { :color => "red", :font_family => "Courier",
3
- :white_space => :pre }
4
- text "In <b class='product'>Ruby</b>, you can write " +
5
- "<code class='ruby'>1.upto(5) { |x| puts x }</code>"
data/manual/manual.txt DELETED
@@ -1,101 +0,0 @@
1
- h1. Prawn::Format %FORMAT:VERSION%
2
- p. %PDF{}HTML{<em>A PDF version of this document may be downloaded <a href="http://jamisbuck.org/files/prawn-format-%FORMAT:VERSION%.pdf">here</a>.</em>}END%
3
- fp. Prawn::Format is an extension library for the Prawn PDF generation library for Ruby, allowing you to easily embed formatting <em>tags</em> in your documents. It features:
4
- ul.
5
- li. Out-of-the-box support for many common HTML tags
6
- li. Intra-document hyperlinks
7
- li. Easily add your own tag definitions
8
- li. Style classes
9
- /ul.
10
- p. Sound good? It's not all roses, though. Prawn::Format currently has the following known warts:
11
- ul.
12
- li. No support for block-level tags (paragraphs, divs, tables, etc.)
13
- li. No support for inline images
14
- /ul.
15
- p. If that doesn't deter you, read on! This manual currently has information about the following topics:
16
- ul.
17
- li. <a href="#basic-usage">Basic usage</a>
18
- li. <a href="#custom-tags">Custom tags</a>
19
- li. <a href="#style-classes">Style classes</a>
20
- li. <a href="#text-options"><code>text()</code> options</a>
21
- /ul.
22
- p. Prawn::Format was written by Jamis Buck (jamis@jamisbuck.org). Although there are not currently plans to extend the functionality much beyond the current incarnation, Jamis is definitely amenable to patches. What this means is that if you've got a pet feature you'd like to see in Prawn::Format, your best bet is to get to work and implement it!
23
- p. Bug reports are welcome, and may be submitted at:
24
- center. <b>http://prawn.lighthouseapp.com/projects/23476</b>
25
- p. And if you're inclined to help out with patches and the like, the code is hosted at (where else?) GitHub:
26
- center. <b>http://github.com/jamis/prawn-format</b>
27
- p. Thanks!
28
- hr.
29
- fp. <about>This manual generated for Prawn::Format version %FORMAT:VERSION% on %NOW%.</about>
30
-
31
- page.
32
- h2. <a name="basic-usage"></a>Basic usage
33
- fp. For most uses, adding text to your documents is exactly the same as it is in Prawn. The only difference is that you now add formatting tags (HTML-ish in nature) to the strings:
34
- highlight. include/basics.rb,ruby
35
- p. Prawn::Format does not support even the majority of HTML tags by default, but it does include support for the most common ones (and you can easily <a href="#custom-tags">add others</a> if you so desire). The supported tags are:
36
- ul.
37
- li. <code>a</code> &mdash; for hyperlinks (the <code>name</code> attribute is for hyperlink anchors, and the <code>href</code> attribute is for the actual links, just like in HTML)
38
- li. <code>b</code> &mdash; bold-faced text (but only if the currently selected font family supports bold text)
39
- li. <code>br</code> &mdash; line break
40
- li. <code>code</code> &mdash; switch to monospaced font (Courier, by default)
41
- li. <code>em</code> &mdash; italicized text (but only if the currently selected font family supports italicized text)
42
- li. <code>font</code> &mdash; change font attributes, include <code>face</code> (to change font family), <code>color</code>, and <code>size</code>
43
- li. <code>i</code> &mdash; italicized text (see <code>em</code>)
44
- li. <code>pre</code> &mdash; "verbatim" text (preserving whitespace and newlines). Unlike the HTML <code>pre</code> tag, this is not a block tag
45
- li. <code>span</code> &mdash; has no formatting, by default, but is recognized so that you can apply <a href="#style-classes">style classes</a> to the tag
46
- li. <code>strong</code> &mdash; bold-faced text (see <code>b</code>)
47
- li. <code>sub</code> &mdash; subscript text
48
- li. <code>sup</code> &mdash; superscript text
49
- li. <code>tt</code> &mdash; monospaced font (see <code>code</code>)
50
- li. <code>u</code> &mdash; underlined text
51
- /ul.
52
- p. You've likely noticed, already, the conspicuous absence of such common HTML tags as <code>p</code>, <code>div</code>, and <code>table</code>. The reason these are missing is simple: Prawn::Format has no real box model. Turns out, implementing such a beast is a really, really complicated thing to do right. However, you can work around this limitation without too much effort. In fact, <em>%PDF{this entire manual is formatted using Prawn::Format!}HTML{the <a href="http://jamisbuck.org/files/prawn-format-%FORMAT:VERSION%.pdf">PDF version of this manual</a> was entirely formatted using Prawn::Format!}END%</em> (The source code for the manual is included in the Prawn::Format distribution; see <code>manual/pdf.rb</code> and <code>manual/html.rb</code>. Also, <code>examples/document.rb</code> has a simpler demonstration of wholesale document formatting.)
53
- p. One particularly important thing to note about Prawn::Format tags: these are XML tags, and not HTML tags! The distinction is moot in most cases, but what this means in practical terms is that you <em>cannot</em> have unclosed tags in Prawn::Format. Even tags like <code>&lt;br&gt;</code> (which HTML allows to exist unclosed) must be closed. However, Prawn::Format allows you to use the abbreviated "open/close" XML syntax, e.g., <code>&lt;br/&gt;</code>.
54
- p. Lastly, Prawn::Format will ignore whitespace, just like HTML. (Unless you're operating in verbatim mode, usually introduced via the <code>&lt;pre&gt;</code> tag.) This means that newlines in your text will <em>not</em> translate to newlines in your output; you need to use the line-break tag <code>&lt;br/&gt;</code> to put line-breaks in your output.
55
- highlight. include/breaks.rb,ruby
56
- p. Got all that? Great! Time to move on to more tricky stuff. Next up: <a href="#custom-tags">custom tags</a>!
57
-
58
- page.
59
- h2. <a name="custom-tags"></a>Custom tags
60
- fp. Prawn::Format makes it very easy to define your own tags, either for clearer semantic markup or to add support for HTML tags that are not supported out-of-the-box.
61
- highlight. include/custom-tags.rb,ruby
62
- p. If you want to tweak the definition of an existing tag, you can reach right into the tags hash directly and add or modify existing styles:
63
- highlight. include/custom-tags2.rb,ruby
64
- p. The supported style options are:
65
- ul.
66
- li. <code>font_size</code>
67
- li. <code>font_family</code> (this may be any font name that Prawn's <code>Document#font</code> method will support)
68
- li. <code>font_style</code> &mdash; either <code>:normal</code> or <code>:italic</code>
69
- li. <code>font_weight</code> &mdash; either <code>:normal</code> or <code>:bold</code>
70
- li. <code>color</code> &mdash; may be any valid HTML color definition
71
- li. <code>vertical_align</code> &mdash; either <code>:super</code> or <code>:sub</code>, or a number to indicate the vertical offset from the baseline
72
- li. <code>text_decoration</code> &mdash; either <code>:none</code> or <code>:underline</code>
73
- li. <code>white_space</code> &mdash; either <code>:normal</code>, or <code>:pre</code> (for verbatim text, where whitespace is preserved)
74
- li. <code>width</code> &mdash; a number, used primarily to fake text indents at paragraph starts. Any tag with this attribute will have a width of that value (in addition to any contents of the tag)
75
- li. <code>kerning</code> &mdash; either true or false, to indicate whether kerning should be done on the text
76
- /ul.
77
- p. As you can see, for the most part these follow the same naming and value schemes as CSS3, though of course the similarity is only superficial. Prawn::Format doesn't support cascading styles, or specifying <a href="#style-classes">style classes</a> by anything other than a bare class name. (Maybe someday this will change. If it does, it'll be thanks to some enterprising programmer who submits a patch.)
78
- p. Still, even with the limitations, you can do quite a bit. For example, suppose you want indent the first line of a paragraph in your own document. Prawn::Format doesn't support this out of the box, but it's easy to do; just define an <code>&lt;indent&gt;</code> tag and give it a width the size of the text indent; then prepend that tag to every paragraph:
79
- highlight. include/indent.rb,ruby
80
- p. Oh, and did you catch that? Just like in CSS, you can specify most measurements in ems (e.g. <code>"2em"</code>), picas (<code>"3pc"</code>), inches (<code>"0.5in"</code>), or PDF "points" (<code>14</code>). There are 72 PDF points to an inch, and 6 picas to an inch. Also, like CSS, you can specify relative measurements, using percentages, in which case it is relative to some appropriate value. (Setting width to <code>"25%"</code> will set it to 25% of the width of the line. Setting the font size to <code>"80%"</code> will set it to 80% of the current font size.)
81
-
82
- page.
83
- h2. <a name="style-classes"></a>Style classes
84
- fp. Adding a new tag for every different style in your document can get to be pretty cumbersome. For that reason, you can also define <em>style classes</em>. This is simply a style definition (just like you would use for <a href="#custom-tags">defining a new tag</a>). To apply the style to a tag, do just like you would in HTML: specify the style class in the <code>class</code> attribute of the tag:
85
- highlight. include/style-classes.rb,ruby
86
- p. As mentioned before, Prawn::Format doesn't support cascading styles (i.e. you can't specify the format of an element by the chain of elements and styles in it's ancestor elements). And sadly, in practice, this does limit the ease with which you can apply complex styles. However, with judicious use of both style classes and <a href="#custom-tags">custom tags</a> you can do quite a bit.
87
-
88
- page.
89
- h2. <a name="text-options"></a><code>text()</code> options
90
- fp. Prawn::Format overloads the existing functionality of Prawn's <code>Document#text</code> method. In fact, unless formatting tags or XML entities are detected in the text, Prawn::Format's <code>text</code> method will simply fall back to the original. (Why? Because if you don't need the formatting, it's <em>much</em> faster to skip all the extra work that Prawn::Format does.)
91
- p. What this means is that Prawn::Format tries very hard to support all of the options that Prawn's <code>text</code> method accepts.
92
- p. Prawn::Format does <em>add</em> several new options to <code>text</code>, though. They are as follows:
93
- ul.
94
- li. <code>:plain</code> &mdash; a boolean indicating whether the text is "plain" or not. Plain text is processed by the original <code>text</code> method. By default, Prawn::Format analyzes the text to determine plainness, but this option lets you force it one way or the other.
95
- li. <code>:align => :justify</code> &mdash; the original <code>text</code> method understood several text alignment methods, but not full-justification. Prawn::Format will understand all the original methods, and also <code>:justify</code>, for full justification.
96
- li. <code>:tags</code> &mdash; a hash of tag definitions to use for this one call. Prawn::Format will always use the tags defined via <code>Document#tags</code>, but anything you specify via the <code>:tags</code> option takes precedent.
97
- li. <code>:styles</code> &mdash; a hash of style class definitions to use for this one call. Prawn::Format will always use the style classes defined via <code>Document#styles</code>, but anything you specify via the <code>:styles</code> option takes precedent.
98
- li. <code>:default_style</code> &mdash; a hash of style definitions that defines the default style to use for any otherwise-unstyled text. This defaults to the current font and color settings on the document, but you can set something else via this option.
99
- /ul.
100
- p. Here are a few examples using these options:
101
- highlight. include/options.rb,ruby