dinbrief 0.0.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -2,7 +2,7 @@ h1. DIN Brief gem for prawn.
2
2
 
3
3
  h2. Mission Objective
4
4
 
5
- This gem tries to make producing letters from Ruby apps simpler. The resulting letter mostly meet the <a href="http://de.wikipedia.org/wiki/DIN_5008" target="_blank">DIN 2008</a> standard.
5
+ This gem tries to make producing letters from Ruby apps simpler. The resulting letter mostly meet the <a href="http://de.wikipedia.org/wiki/DIN_5008" target="_blank">DIN 5008</a> standard.
6
6
 
7
7
  It is (mainly) a semantic DSL on top of <a href="http://prawn.majesticseacreature.com/" target="_blank">Prawn 1.x</a>.
8
8
 
@@ -115,9 +115,37 @@ But, as always, things may be more complicated, and you may want to add fancy pd
115
115
 
116
116
  The result then looks a little bit like this:
117
117
 
118
- <img src="https://github.com/provideal/dinbrief/raw/master/example/example.png" />
118
+ <img src="https://github.com/metaminded/dinbrief/raw/master/example/example.png" />
119
119
 
120
- Almost every property of an element is defined in <tt>lib/dinbrief/letter/constants.rb</tt>, and can be overridden in your subclass.
120
+ If you're unhappy with the default info block, you may call <tt>info</tt> giving either a string:
121
+
122
+ <pre>
123
+ MyLetter.letter('more_serious.pdf') do |db|
124
+ db.return_address 'metaminded UG – Ulmer Straße 176 – 73233 Aalen'
125
+ db.subject "Thanks a lot for giving us Rails"
126
+ db.info "Thing: something\nStuff: somestuff"
127
+ ...
128
+ </pre>
129
+
130
+ or – even more advanced – a block as with the <tt>body</tt> method:
131
+
132
+ <pre>
133
+ MyLetter.letter('more_serious.pdf') do |db|
134
+ db.return_address 'metaminded UG – Ulmer Straße 176 – 73233 Aalen'
135
+ db.subject "Thanks a lot for giving us Rails"
136
+ db.info do |box|
137
+ 4.times do |i|
138
+ box.text "Line #{i}", size: 10.pt
139
+ end
140
+ end
141
+ ...
142
+ </pre>
143
+
144
+ inside the block, you may use virtually every prawn method. If <tt>info</tt> is given, all other info-methods (as <tt>yourmessage</tt>, <tt>oursign</tt> and the like) are disabled.
145
+
146
+ h2.
147
+
148
+ Almost every property (positions, sizes, fontsizes, ...) of an element is defined in <tt>lib/dinbrief/letter/constants.rb</tt>, and can be overridden in your subclass.
121
149
 
122
150
  h2. Disclaimer
123
151
 
@@ -128,7 +156,7 @@ Nevertheless, bug reports and improvements are highly appreciated:
128
156
  h2. Contributing to dinbrief
129
157
 
130
158
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
131
- * Check out the <a href="https://github.com/provideal/dinbrief/issues">issue tracker</a> to make sure someone already hasn't requested it and/or contributed it
159
+ * Check out the <a href="https://github.com/metaminded/dinbrief/issues">issue tracker</a> to make sure someone already hasn't requested it and/or contributed it
132
160
  * Fork the project
133
161
  * Start a feature/bugfix branch
134
162
  * Commit and push until you are happy with your contribution
data/dinbrief.gemspec CHANGED
@@ -5,11 +5,11 @@ require "dinbrief/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "dinbrief"
7
7
  s.version = Dinbrief::VERSION
8
- s.authors = ["Peter Horn"]
9
- s.email = ["peter.horn@provideal.net"]
10
- s.homepage = ""
8
+ s.authors = ["Peter Horn, metaminded"]
9
+ s.email = ["peter.horn@metaminded.com"]
10
+ s.homepage = "http://github.com/metaminded/dinbrief"
11
11
  s.summary = %q{DIN Letter gem for Prawn}
12
- s.description = %q{DIN Brief gem for Prawn. Creating letters that confirm to the DIN specifications. For Ruby.}
12
+ s.description = %q{DIN Brief gem for Prawn. Creating letters that confirm to the DIN 5008 specifications.}
13
13
 
14
14
  s.rubyforge_project = "dinbrief"
15
15
 
@@ -55,6 +55,7 @@ MyLetter.letter('more_serious.pdf') do |db|
55
55
  db.email "ph@metaminded.com"
56
56
  db.address "David Heinemeier-Hansson\n37signals, LLC\n30 North Racine Avenue #200\nChicago, Illinois 60607\nUSA"
57
57
  db.subject "Thanks a lot for giving us Rails"
58
+ # db.info do |box| 4.times do |i| box.text "Line #{i}", size: 10.pt end end
58
59
  db.body do |letter|
59
60
  letter.text %{Dear David and all you colleagues,
60
61
 
@@ -50,6 +50,7 @@ class Dinbrief::Letter
50
50
  :info_block_x => 125.mm,
51
51
  :info_block_y => -45.mm,
52
52
  :info_block_width => 75.mm,
53
+ :info_block_height => 40.mm,
53
54
  :info_block_fontsize => 9.pt,
54
55
 
55
56
  # Date
@@ -5,16 +5,28 @@ class Dinbrief::Letter
5
5
  # typeset info block (sign, name, phone...)
6
6
  #
7
7
  def typeset_info
8
- info = [:yoursign, :yourmessage, :oursign, :ourmessage,
9
- :name, :phone, :fax, :email].map do |nam|
10
- iv = lb_get nam
11
- iv ? "#{InfoTranslations[nam]}: #{iv}" : nil
12
- end.compact.join("\n")
13
- return unless info
14
- text_box(info,
15
- :at => [info_block_x, info_block_y],
16
- :size => info_block_fontsize
17
- )
8
+ bounding_box([info_block_x, info_block_y],
9
+ :width => info_block_width,
10
+ :height => info_block_height
11
+ ) do
12
+ #stroke_bounds
13
+ i = lb_get(:info)
14
+ case i
15
+ when String
16
+ text i, :size => info_block_fontsize
17
+ when Proc
18
+ i.(self)
19
+ else
20
+ info = [:yoursign, :yourmessage, :oursign, :ourmessage,
21
+ :name, :phone, :fax, :email].map do |nam|
22
+ iv = lb_get nam
23
+ iv ? "#{InfoTranslations[nam]}: #{iv}" : nil
24
+ end.compact.join("\n")
25
+ return unless info
26
+ text info,
27
+ :size => info_block_fontsize
28
+ end
29
+ end
18
30
  date = lb_get(:date) || Time.now.strftime("%d.%m.%Y")
19
31
  text_box("#{InfoTranslations[:date]}: #{date}",
20
32
  :at => [date_x, date_y],
@@ -4,20 +4,32 @@ module Dinbrief
4
4
 
5
5
  class Letter < Prawn::Document
6
6
 
7
- def self.letter(filename,options={},&block)
8
- self.generate(filename, DocumentDefaults.merge(options)) do |letter|
9
- yield(letter.letter_builder)
10
- letter.meta_header()
11
- letter.meta_footer()
12
- letter.methods.map(&:to_s).select{|m|m.start_with?("typeset_")}.each do |m|
13
- next if m=='typeset_body'
14
- letter.send(m)
7
+ def self.letter(pdf_or_filename, options={}, &block)
8
+ case pdf_or_filename
9
+ when Dinbrief::Letter
10
+ make_letter(pdf_or_filename, &block)
11
+ pdf_or_filename
12
+ when Prawn::Document
13
+ raise "Give an instance of Dinbrief::Letter to letter method."
14
+ when String
15
+ self.generate(pdf_or_filename, DocumentDefaults.merge(options)) do |pdf|
16
+ make_letter(pdf, &block)
15
17
  end
16
- letter.typeset_body
17
- letter.add_page_numbers
18
18
  end
19
19
  end
20
20
 
21
+ def self.make_letter(letter, &block)
22
+ yield(letter.letter_builder)
23
+ letter.meta_header()
24
+ letter.meta_footer()
25
+ letter.methods.map(&:to_s).select{|m|m.start_with?("typeset_")}.each do |m|
26
+ next if m=='typeset_body'
27
+ letter.send(m)
28
+ end
29
+ letter.typeset_body
30
+ letter.add_page_numbers
31
+ end
32
+
21
33
  def add_page_numbers
22
34
  if show_page_numbers?
23
35
  number_pages page_numbering_string, {
@@ -22,5 +22,9 @@ module Dinbrief
22
22
  @body = block_given? ? block : b
23
23
  end
24
24
 
25
+ def info(b=nil, &block)
26
+ @info = block_given? ? block : b
27
+ end
28
+
25
29
  end
26
30
  end
@@ -1,3 +1,3 @@
1
1
  module Dinbrief
2
- VERSION = "0.0.1"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dinbrief
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Peter Horn
8
+ - Peter Horn, metaminded
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-04 00:00:00.000000000 Z
12
+ date: 2012-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: prawn
16
- requirement: &70283461717780 !ruby/object:Gem::Requirement
16
+ requirement: &70351984540660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,11 +21,11 @@ dependencies:
21
21
  version: 1.0.0.rc1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70283461717780
25
- description: DIN Brief gem for Prawn. Creating letters that confirm to the DIN specifications.
26
- For Ruby.
24
+ version_requirements: *70351984540660
25
+ description: DIN Brief gem for Prawn. Creating letters that confirm to the DIN 5008
26
+ specifications.
27
27
  email:
28
- - peter.horn@provideal.net
28
+ - peter.horn@metaminded.com
29
29
  executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
@@ -47,7 +47,7 @@ files:
47
47
  - lib/dinbrief/letter/typeset_methods.rb
48
48
  - lib/dinbrief/letter_builder.rb
49
49
  - lib/dinbrief/version.rb
50
- homepage: ''
50
+ homepage: http://github.com/metaminded/dinbrief
51
51
  licenses: []
52
52
  post_install_message:
53
53
  rdoc_options: []