Created
July 23, 2012 16:52
-
-
Save rjmcdonald83/3164685 to your computer and use it in GitHub Desktop.
Markdown to Prawn Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TermsPdf < Prawn::Document | |
def initialize(application) | |
super() | |
@application = application | |
@listing = @application.listing | |
@host = @listing.organization | |
@guest = @application.guest_organization | |
font "Times-Roman" | |
default_leading 2 | |
data = {} | |
data['HOST_NAME'] = @host.name | |
data['GUEST_NAME'] = @guest.name | |
data['LISTING_NAME'] = @listing.name | |
data['LISTING_ADDR1'] = @listing.address_1 | |
data['LISTING_ADDR2'] = @listing.address_2 | |
data['LISTING_CITY'] = @listing.city | |
data['LISTING_STATE'] = @listing.state | |
data['LISTING_POSTAL_CODE'] = @listing.postal_code | |
data['APPLICATION_START_DATE'] = @application.start_date | |
data['APPLICATION_OCCUPANTS'] = @application.occupants.map(&:name).join(', ') | |
data['LISTING_SPACE_PRICE'] = @listing.space_price | |
data['LISTING_HOUSE_RULES'] = @listing.house_rules | |
filename = 'app/pdfs/terms.md' | |
contents = File.readlines(filename) | |
contents.each do |line| | |
### TO DO: IMAGE, FIX BOTTOM INUTS, BELOW TEXT ENTRY MARGIN, TRY AND FIX THE SECOND ADDRESS(CONDITIONAL), FUCKING UNDERLINES ### | |
# If the line starts with ==, text with big format | |
# otherwise, just "text line" | |
line.gsub!( /__(.+)__/ ) { '<u>' + $1 + '</u>' } | |
line.gsub!( /%%(.+?)%%/ ) { data[$1] } | |
if line.match /^== / | |
line.gsub! /^== /, "" | |
indent(20) do | |
text line, style: :bold, size: 25, align: :center | |
end | |
elsif line.match /^-- / | |
line.gsub! /^-- /, "" | |
text line, style: :bold, size: 18, align: :center | |
elsif line.match /^### / | |
line.gsub! /^### /, "" | |
text line, style: :bold, size: 16 | |
elsif line.match /^\s*[A-Z]\. / | |
indent(30) do | |
text line, :indent_paragraphs => -15, inline_format: true, final_gap: true | |
end | |
elsif line.match /^\s*\d{1,2}\. / | |
indent(30) do | |
text line, :indent_paragraphs => -15, inline_format: true | |
end | |
elsif line.match /^\s*[a-z]\. / | |
indent(50) do | |
text line, :indent_paragraphs => -15, inline_format: true | |
end | |
else | |
text line | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment