Class: Bread::Basket::Poster::Layout
- Inherits:
-
Object
- Object
- Bread::Basket::Poster::Layout
- Defined in:
- lib/bread/basket/poster/layout.rb
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Returns the value of attribute bottom.
-
#boxes ⇒ Object
Returns the value of attribute boxes.
-
#css_reader ⇒ Object
readonly
Returns the value of attribute css_reader.
-
#determined ⇒ Object
Returns the value of attribute determined.
-
#font_family ⇒ Object
Returns the value of attribute font_family.
-
#font_size ⇒ Object
Returns the value of attribute font_size.
-
#height ⇒ Object
Returns the value of attribute height.
-
#image_boxes ⇒ Object
Returns the value of attribute image_boxes.
-
#left ⇒ Object
Returns the value of attribute left.
-
#margin ⇒ Object
Returns the value of attribute margin.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#pending ⇒ Object
Returns the value of attribute pending.
-
#right ⇒ Object
Returns the value of attribute right.
-
#stylesheet ⇒ Object
readonly
Returns the value of attribute stylesheet.
-
#top ⇒ Object
Returns the value of attribute top.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #create_attribute(key, value) ⇒ Object
- #determine_type ⇒ Object
- #empty_defaults ⇒ Object
- #find_stylesheet(stylesheet_name) ⇒ Object
- #flow? ⇒ Boolean
- #give_up(message) ⇒ Object
- #handle_defaults ⇒ Object
- #handle_else(layout) ⇒ Object
-
#initialize(metadata) ⇒ Layout
constructor
A new instance of Layout.
- #template ⇒ Object
- #try_to_resolve_pendings ⇒ Object
Constructor Details
#initialize(metadata) ⇒ Layout
Returns a new instance of Layout.
10 11 12 13 14 15 16 |
# File 'lib/bread/basket/poster/layout.rb', line 10 def initialize() = @type = determine_type @stylesheet = find_stylesheet(['stylesheet']) @css_reader = CSSReader.new(stylesheet, self) css_reader.do_your_thing! end |
Instance Attribute Details
#bottom ⇒ Object
Returns the value of attribute bottom.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def bottom @bottom end |
#boxes ⇒ Object
Returns the value of attribute boxes.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def boxes @boxes end |
#css_reader ⇒ Object (readonly)
Returns the value of attribute css_reader.
5 6 7 |
# File 'lib/bread/basket/poster/layout.rb', line 5 def css_reader @css_reader end |
#determined ⇒ Object
Returns the value of attribute determined.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def determined @determined end |
#font_family ⇒ Object
Returns the value of attribute font_family.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def font_family @font_family end |
#font_size ⇒ Object
Returns the value of attribute font_size.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def font_size @font_size end |
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def height @height end |
#image_boxes ⇒ Object
Returns the value of attribute image_boxes.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def image_boxes @image_boxes end |
#left ⇒ Object
Returns the value of attribute left.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def left @left end |
#margin ⇒ Object
Returns the value of attribute margin.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def margin @margin end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/bread/basket/poster/layout.rb', line 5 def end |
#pending ⇒ Object
Returns the value of attribute pending.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def pending @pending end |
#right ⇒ Object
Returns the value of attribute right.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def right @right end |
#stylesheet ⇒ Object (readonly)
Returns the value of attribute stylesheet.
5 6 7 |
# File 'lib/bread/basket/poster/layout.rb', line 5 def stylesheet @stylesheet end |
#top ⇒ Object
Returns the value of attribute top.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def top @top end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/bread/basket/poster/layout.rb', line 5 def type @type end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/bread/basket/poster/layout.rb', line 6 def width @width end |
Instance Method Details
#create_attribute(key, value) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/bread/basket/poster/layout.rb', line 59 def create_attribute(key, value) new_key = key.gsub('-', '_').sub('.', '').to_sym define_singleton_method(new_key) { value } # This is called at end of each attribute's definition try_to_resolve_pendings unless pending.nil? end |
#determine_type ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bread/basket/poster/layout.rb', line 18 def determine_type case ['layout'] when 'block' :block when 'flow' :flow else handle_else ['layout'] :flow end end |
#empty_defaults ⇒ Object
79 80 81 82 83 84 |
# File 'lib/bread/basket/poster/layout.rb', line 79 def empty_defaults @pending = [] @determined = {} @boxes = [] @image_boxes = [] end |
#find_stylesheet(stylesheet_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bread/basket/poster/layout.rb', line 30 def find_stylesheet(stylesheet_name) if stylesheet_name path = Bread::Basket::Poster.dir_path + '/' + stylesheet_name path += '.css' unless stylesheet_name.include?('.css') path else puts 'Warning: no stylesheet given, using template instead.' template end end |
#flow? ⇒ Boolean
41 42 43 |
# File 'lib/bread/basket/poster/layout.rb', line 41 def flow? type == :flow end |
#give_up(message) ⇒ Object
100 101 102 103 104 |
# File 'lib/bread/basket/poster/layout.rb', line 100 def give_up() puts '== Aborting ==' puts exit end |
#handle_defaults ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bread/basket/poster/layout.rb', line 66 def handle_defaults empty_defaults @font_size ||= 36 @font_family ||= 'Helvetica' @margin ||= 36 # add dimensions to the determined hash for reference # open to a better solution here :) %w(width height left right top bottom margin font_size font_family).each do |method_name| determined[method_name] = eval("@#{method_name}") end end |
#handle_else(layout) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/bread/basket/poster/layout.rb', line 51 def handle_else(layout) if layout puts "Warning: Unrecognized layout `#{layout}`, using flow instead" else puts 'Warning: No layout specified, defaulting to flow.' end end |
#template ⇒ Object
45 46 47 48 49 |
# File 'lib/bread/basket/poster/layout.rb', line 45 def template template = File.('./samples/block_sample.css') template = File.('./samples/flow_sample.css') if flow? template end |
#try_to_resolve_pendings ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bread/basket/poster/layout.rb', line 86 def try_to_resolve_pendings pending.reverse_each do |name| # very limited match on columns for now match = name.match(/columns\[(\d)\]/) if match index = match[1].to_i columns[index].try_to_resolve else box = send name.sub('.', '').gsub('-', '_') box.try_to_resolve end end end |