Class: Rabbit::HTML::Generator

Inherits:
Object
  • Object
show all
Includes:
ERB::Util, GetText
Defined in:
lib/rabbit/html/generator.rb

Constant Summary

Constants included from GetText

GetText::DOMAIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GetText

included

Constructor Details

#initialize(canvas, base_name, image_type, output_html, output_index_html, rss_base_uri) ⇒ Generator

Returns a new instance of Generator.


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rabbit/html/generator.rb', line 52

def initialize(canvas, base_name, image_type,
               output_html, output_index_html, rss_base_uri)
  @canvas = canvas
  @suffix = "html"
  @rss_info = []
  @rss_filename = "index.rdf"
  rss_base_uri = rss_base_uri.chomp('/') + '/' if rss_base_uri
  @rss_base_uri = rss_base_uri
  @base_name = base_name
  @base_dir = File.dirname(@base_name)
  @image_type = image_type
  @output_html = output_html
  @output_index_html = output_index_html
  @pdf_filename = nil
  @source_filename = nil
  FileUtils.mkdir_p(Filename.new(@base_dir).encode)
end

Instance Attribute Details

#pdf_filenameObject

Returns the value of attribute pdf_filename.


51
52
53
# File 'lib/rabbit/html/generator.rb', line 51

def pdf_filename
  @pdf_filename
end

#source_filenameObject

Returns the value of attribute source_filename.


51
52
53
# File 'lib/rabbit/html/generator.rb', line 51

def source_filename
  @source_filename
end

Instance Method Details

#index_href(slide_number) ⇒ Object


120
121
122
123
124
# File 'lib/rabbit/html/generator.rb', line 120

def index_href(slide_number)
  with_outputting_index(true) do
    href(slide_number)
  end
end

#index_image_title(slide_number) ⇒ Object


132
133
134
135
136
137
138
# File 'lib/rabbit/html/generator.rb', line 132

def index_image_title(slide_number)
  @canvas.with_index_mode(true) do
    with_outputting_index(true) do
      image_title(slide_number)
    end
  end
end

#number_of_places(num) ⇒ Object


98
99
100
101
102
103
104
105
106
# File 'lib/rabbit/html/generator.rb', line 98

def number_of_places(num)
  n = 1
  target = num
  while target >= 10
    target /= 10
    n += 1
  end
  n
end

#output_html?Boolean

Returns:

  • (Boolean)

112
113
114
# File 'lib/rabbit/html/generator.rb', line 112

def output_html?
  @output_html
end

#output_index_html?Boolean

Returns:

  • (Boolean)

108
109
110
# File 'lib/rabbit/html/generator.rb', line 108

def output_index_html?
  @output_index_html
end

#output_slide_html?Boolean

Returns:

  • (Boolean)

116
117
118
# File 'lib/rabbit/html/generator.rb', line 116

def output_slide_html?
  output_html? and !@index_mode
end

#outputting_index?Boolean

Returns:

  • (Boolean)

148
149
150
# File 'lib/rabbit/html/generator.rb', line 148

def outputting_index?
  @outputting_index
end

#saveObject


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rabbit/html/generator.rb', line 70

def save
  save_environment do
    @outputting_index = false
    @canvas.each_slide_pixbuf do |slide, pixbuf, slide_number|
      message = _("Creating a image for the %dth page") % slide_number
      @canvas.logger.info(message)
      save_slide(slide, pixbuf, slide_number)
      true
    end
    if output_index_html?
      @canvas.with_index_mode(true) do
        @canvas.slides.each_with_index do |slide, slide_number|
          save_index(slide, slide_number)
        end
      end
    end
    unless save_rss
      @canvas.logger.warn(_("can't generate RSS"))
    end
  end
end

#save_pixbuf(pixbuf, optional = nil) ⇒ Object


92
93
94
95
96
# File 'lib/rabbit/html/generator.rb', line 92

def save_pixbuf(pixbuf, optional=nil)
  pixbuf.save(pixbuf_filename(@slide_number, optional),
              normalized_image_type)
  image_src(@slide_number, optional)
end

#slide_href(slide_number) ⇒ Object


126
127
128
129
130
# File 'lib/rabbit/html/generator.rb', line 126

def slide_href(slide_number)
  with_outputting_index(false) do
    href(slide_number)
  end
end

#slide_image_title(slide_number) ⇒ Object


140
141
142
143
144
145
146
# File 'lib/rabbit/html/generator.rb', line 140

def slide_image_title(slide_number)
  @canvas.with_index_mode(false) do
    with_outputting_index(false) do
      image_title(slide_number)
    end
  end
end

#with_outputting_index(index) ⇒ Object


152
153
154
155
156
157
158
# File 'lib/rabbit/html/generator.rb', line 152

def with_outputting_index(index)
  _index = @outputting_index
  @outputting_index = index
  yield
ensure
  @outputting_index = _index
end