legal_beagle 0.0.1.a

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ require 'jekyll'
2
+ require 'pathname'
3
+ require 'legal_beagle/to_prawn'
4
+
5
+ module LegalBeagle
6
+ class Converter
7
+ include Jekyll::Convertible
8
+
9
+ attr_accessor :content, :data, :ext
10
+
11
+ def initialize(filename)
12
+ file = Pathname.new(filename)
13
+ self.ext = file.extname
14
+ self.content = file.read
15
+ read_yaml(file.dirname, file.basename)
16
+ end
17
+
18
+ def transform
19
+ Maruku.new(content).to_prawn(@pdf)
20
+ end
21
+
22
+ def render(pdf)
23
+ @pdf = pdf
24
+ self.content = Liquid::Template.parse(self.content).render(data, {})
25
+ self.transform
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module LegalBeagle
2
+ def self.name
3
+ "legal_beagle"
4
+ end
5
+
6
+ def self.version
7
+ "0.0.1.a"
8
+ end
9
+
10
+ def self.summary
11
+ "A very primitive tool for doing legal documents by converting markdown to pdf."
12
+ end
13
+
14
+ def self.description
15
+ "This tool was originally developed by Mashion.net for use in generating contracts and agreements. Hopefully it'll grow to somethign more useful eventually."
16
+ end
17
+ end
@@ -0,0 +1,104 @@
1
+ require 'prawn'
2
+
3
+ module MaRuKu::Out::Prawn
4
+ def to_prawn(pdf)
5
+ @pdf = pdf
6
+ array_to_prawn(@children)
7
+ end
8
+
9
+ def array_to_prawn(children)
10
+ children.each do |c|
11
+ send("to_prawn_#{c.node_type}", c)
12
+ end
13
+ end
14
+
15
+ def to_prawn_ul(ul)
16
+ ul.children.each do |c|
17
+ to_prawn_li_span(c)
18
+ end
19
+ @pdf.text ' '
20
+ end
21
+
22
+ def to_prawn_li_span(li)
23
+ if li.children.empty?
24
+ text = li.to_html
25
+ else
26
+ text = to_pdf_string(li.children)
27
+ end
28
+
29
+ @pdf.text " • " + text, :indent_paragraphs => 20
30
+ end
31
+
32
+ def to_prawn_paragraph(para)
33
+ text = to_pdf_string(para.children)
34
+ @pdf.text text, :inline_format => true
35
+ @pdf.text ' '
36
+ end
37
+
38
+ def to_pdf_string(children)
39
+ children.inject("") do |t, c|
40
+ if c.is_a? String
41
+ t + c
42
+ else
43
+ t + send("to_prawn_string_#{c.node_type}", c)
44
+ end
45
+ end
46
+ end
47
+
48
+ def to_prawn_string_emphasis(em)
49
+ "<em>#{to_pdf_string(em.children)}</em>"
50
+ end
51
+
52
+ def to_prawn_string_strong(strong)
53
+ "<strong>#{to_pdf_string(strong.children)}</strong>"
54
+ end
55
+
56
+ def entity_table
57
+ @table ||= {
58
+ "lsquo" => "‘",
59
+ "rsquo" => "’",
60
+ "ldquo" => "“",
61
+ "rdquo" => "”"
62
+ }
63
+ end
64
+
65
+ def to_prawn_string_paragraph(para)
66
+ para.to_html
67
+ end
68
+
69
+ def to_prawn_string_entity(entity)
70
+ name = entity.entity_name
71
+ typographic = entity_table[name]
72
+ raise "I don't know how to make a typographic #{name}" unless typographic
73
+ typographic
74
+ end
75
+
76
+ # TODO find a less ghetto way to do leading-trailing margins
77
+ def to_prawn_header(header)
78
+ size = { 1 => 16, 2 => 12 }[header.level]
79
+ @pdf.text header.children.join("\n"), :size => size, :style => :bold
80
+ @pdf.text ' '
81
+ end
82
+
83
+ def to_prawn_div(div)
84
+ if div.attributes[:class] == "signature"
85
+ signature_name = div.children.map.join(" ")
86
+ @pdf.instance_eval do
87
+ text ' ', :size => 30
88
+ stroke_horizontal_line 0, 200
89
+ stroke_horizontal_line 250, 300
90
+ text ' ', :size => 4
91
+ text signature_name
92
+ draw_text "Date", :at => [250, y - bounds.absolute_bottom + 5]
93
+ text ' ', :size => 20
94
+ stroke_horizontal_line 0, 200
95
+ text ' ', :size => 4
96
+ text signature_name + " (Print)"
97
+ end
98
+ else
99
+ puts "Didn't write div to pdf: #{div.inspect}"
100
+ end
101
+ end
102
+ end
103
+
104
+ MaRuKu::MDElement.send(:include, MaRuKu::Out::Prawn)
@@ -0,0 +1,3 @@
1
+ require 'legal_beagle/info'
2
+ require 'legal_beagle/converter'
3
+
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: legal_beagle
3
+ version: !ruby/object:Gem::Version
4
+ hash: 46
5
+ prerelease: true
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - a
11
+ version: 0.0.1.a
12
+ platform: ruby
13
+ authors:
14
+ - Mat Schaffer
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-14 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: jekyll
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ - 7
34
+ - 0
35
+ version: 0.7.0
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: prawn
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 49
47
+ segments:
48
+ - 0
49
+ - 11
50
+ - 1
51
+ version: 0.11.1
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: mocha
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id004
82
+ description: This tool was originally developed by Mashion.net for use in generating contracts and agreements. Hopefully it'll grow to somethign more useful eventually.
83
+ email: mat@mashion.net
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - README.md
92
+ - lib/legal_beagle/converter.rb
93
+ - lib/legal_beagle/info.rb
94
+ - lib/legal_beagle/to_prawn.rb
95
+ - lib/legal_beagle.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/mashion/legal_beagle
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">"
118
+ - !ruby/object:Gem::Version
119
+ hash: 25
120
+ segments:
121
+ - 1
122
+ - 3
123
+ - 1
124
+ version: 1.3.1
125
+ requirements: []
126
+
127
+ rubyforge_project: nowarning
128
+ rubygems_version: 1.3.7
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: A very primitive tool for doing legal documents by converting markdown to pdf.
132
+ test_files: []
133
+