Class: Muwu::RenderHtmlPartial::Contents

Inherits:
Object
  • Object
show all
Includes:
Muwu
Defined in:
lib/muwu/render_html_partial/render_contents.rb

Constant Summary

Constants included from Muwu

GEM_HOME_LIB, GEM_HOME_LIB_MUWU, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Muwu

debug, read

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def destination
  @destination
end

#href_helperObject

Returns the value of attribute href_helper.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def href_helper
  @href_helper
end

#html_attr_idObject

Returns the value of attribute html_attr_id.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def html_attr_id
  @html_attr_id
end

#item_depth_maxObject

Returns the value of attribute item_depth_max.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def item_depth_max
  @item_depth_max
end

#projectObject

Returns the value of attribute project.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def project
  @project
end

#sectionsObject

Returns the value of attribute sections.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def sections
  @sections
end

#text_root_nameObject

Returns the value of attribute text_root_name.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def text_root_name
  @text_root_name
end

#will_render_section_numbersObject

Returns the value of attribute will_render_section_numbers.



12
13
14
# File 'lib/muwu/render_html_partial/render_contents.rb', line 12

def will_render_section_numbers
  @will_render_section_numbers
end

Instance Method Details

#renderObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/muwu/render_html_partial/render_contents.rb', line 28

def render
  @destination.margin_to_zero
  @destination.padding_vertical(1) do
    write_tag_div_open
    render_contents_heading
    render_contents_element(@sections)
    write_tag_div_close
  end
  @destination.margin_to_zero
end

#render_contents_element(sections) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/muwu/render_html_partial/render_contents.rb', line 40

def render_contents_element(sections)
  @destination.margin_indent do
    case @will_render_section_numbers
    when false
      render_ol(sections)
    when true
      render_table(sections)
    end
  end
end

#render_contents_headingObject



52
53
54
# File 'lib/muwu/render_html_partial/render_contents.rb', line 52

def render_contents_heading
  write_tag_h1_contents_heading
end

#render_ol(text_item) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/muwu/render_html_partial/render_contents.rb', line 57

def render_ol(text_item)
  write_tag_ol_open
  @destination.margin_indent do 
    text_item.each do |section|
      render_ol_li(section)
    end
  end
  write_tag_ol_close
end

#render_ol_li(text_item) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/muwu/render_html_partial/render_contents.rb', line 68

def render_ol_li(text_item)
  if task_depth_is_within_range(text_item)
    if text_item.is_parent_heading
      write_tag_li_open
      @destination.margin_indent do 
        render_ol_li_heading_and_subsections(text_item)
      end
      write_tag_li_close_outline
    elsif text_item.is_not_parent_heading
      write_tag_li_open
      render_ol_li_heading(text_item)
      write_tag_li_close_inline
    end
  end
end

#render_ol_li_heading(text_item) ⇒ Object



85
86
87
# File 'lib/muwu/render_html_partial/render_contents.rb', line 85

def render_ol_li_heading(text_item)
  render_tag_a_section_heading(text_item)
end

#render_ol_li_heading_and_subsections(text_item) ⇒ Object



90
91
92
93
# File 'lib/muwu/render_html_partial/render_contents.rb', line 90

def render_ol_li_heading_and_subsections(text_item)
  render_tag_a_section_heading(text_item, trailing_line_feed: true)
  render_ol(text_item.sections)
end

#render_table(text_item) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/muwu/render_html_partial/render_contents.rb', line 96

def render_table(text_item)
  write_tag_table_open
  @destination.margin_indent do 
    text_item.each do |section|
      render_table_tr(section)
    end
  end
  write_tag_table_close
end

#render_table_tr(section) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/muwu/render_html_partial/render_contents.rb', line 107

def render_table_tr(section)
  if task_depth_is_within_range(section)
    html_id = ['contents', @text_root_name, section.numbering.join('_')].join('_')
    write_tag_tr_open(html_id)
    @destination.margin_indent do 
      if section.is_parent_heading
        render_table_tr_td_number(section)
        render_table_tr_td_heading_and_subsections(section)
      elsif section.is_not_parent_heading
        render_table_tr_td_number(section)
        render_table_tr_td_heading(section)
      end
    end
    write_tag_tr_close
  end
end

#render_table_tr_td_heading(text_item) ⇒ Object



125
126
127
128
129
# File 'lib/muwu/render_html_partial/render_contents.rb', line 125

def render_table_tr_td_heading(text_item)
  write_tag_td_open(attr_list: "class='heading'")
  render_tag_a_section_heading(text_item)
  write_tag_td_close_inline
end

#render_table_tr_td_heading_and_subsections(text_item) ⇒ Object



132
133
134
135
136
137
138
139
# File 'lib/muwu/render_html_partial/render_contents.rb', line 132

def render_table_tr_td_heading_and_subsections(text_item)
  write_tag_td_open(attr_list: "class='heading'")
  render_tag_a_section_heading(text_item, trailing_line_feed: true)
  @destination.margin_indent do
    render_table(text_item.sections)
  end
  write_tag_td_close_outline
end

#render_table_tr_td_number(text_item) ⇒ Object



142
143
144
145
146
# File 'lib/muwu/render_html_partial/render_contents.rb', line 142

def render_table_tr_td_number(text_item)
  write_tag_td_open(attr_list: "class='number'")
  render_tag_a_section_number(text_item, attr_list: "tabindex='-1'")
  write_tag_td_close_inline
end

#render_tag_a_section_heading(text_item, trailing_line_feed: false) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/muwu/render_html_partial/render_contents.rb', line 149

def render_tag_a_section_heading(text_item, trailing_line_feed: false)
  href = @href_helper.to_text_item(text_item)
  write_tag_a_open(href)
  write_text_section_heading(text_item)
  write_tag_a_close
  if trailing_line_feed
    write_lf
  end
end

#render_tag_a_section_number(text_item, attr_list: nil) ⇒ Object



160
161
162
163
164
165
# File 'lib/muwu/render_html_partial/render_contents.rb', line 160

def render_tag_a_section_number(text_item, attr_list: nil)
  href = @href_helper.to_text_item(text_item)
  write_tag_a_open(href, attr_list: attr_list)
  write_text_section_number(text_item)
  write_tag_a_close
end

#write_lfObject



168
169
170
# File 'lib/muwu/render_html_partial/render_contents.rb', line 168

def write_lf
  @destination.write_lf
end

#write_tag_a_closeObject



173
174
175
# File 'lib/muwu/render_html_partial/render_contents.rb', line 173

def write_tag_a_close
  @destination.write_inline tag_a_close
end

#write_tag_a_open(href_id, attr_list: nil) ⇒ Object



178
179
180
# File 'lib/muwu/render_html_partial/render_contents.rb', line 178

def write_tag_a_open(href_id, attr_list: nil)
  @destination.write_inline tag_a_open(href_id, attr_list: attr_list)
end

#write_tag_div_closeObject



183
184
185
# File 'lib/muwu/render_html_partial/render_contents.rb', line 183

def write_tag_div_close
  @destination.write_line tag_div_close
end

#write_tag_div_openObject



188
189
190
# File 'lib/muwu/render_html_partial/render_contents.rb', line 188

def write_tag_div_open
  @destination.write_line tag_div_open
end

#write_tag_h1_contents_headingObject



193
194
195
# File 'lib/muwu/render_html_partial/render_contents.rb', line 193

def write_tag_h1_contents_heading
  @destination.write_line tag_h1_contents_heading
end

#write_tag_li_closeObject



198
199
200
# File 'lib/muwu/render_html_partial/render_contents.rb', line 198

def write_tag_li_close
  write_tag_li_close_outline
end

#write_tag_li_close_inlineObject



203
204
205
# File 'lib/muwu/render_html_partial/render_contents.rb', line 203

def write_tag_li_close_inline
  @destination.write_inline_end tag_li_close
end

#write_tag_li_close_outlineObject



208
209
210
# File 'lib/muwu/render_html_partial/render_contents.rb', line 208

def write_tag_li_close_outline
  @destination.write_line tag_li_close
end

#write_tag_li_openObject



213
214
215
# File 'lib/muwu/render_html_partial/render_contents.rb', line 213

def write_tag_li_open
  @destination.write_inline_indented tag_li_open
end

#write_tag_ol_closeObject



218
219
220
# File 'lib/muwu/render_html_partial/render_contents.rb', line 218

def write_tag_ol_close
  @destination.write_line tag_ol_close
end

#write_tag_ol_openObject



223
224
225
# File 'lib/muwu/render_html_partial/render_contents.rb', line 223

def write_tag_ol_open
  @destination.write_line tag_ol_open
end

#write_tag_table_closeObject



228
229
230
# File 'lib/muwu/render_html_partial/render_contents.rb', line 228

def write_tag_table_close
  @destination.write_line tag_table_close
end

#write_tag_table_openObject



233
234
235
# File 'lib/muwu/render_html_partial/render_contents.rb', line 233

def write_tag_table_open
  @destination.write_line tag_table_open
end

#write_tag_td_closeObject



238
239
240
# File 'lib/muwu/render_html_partial/render_contents.rb', line 238

def write_tag_td_close
  write_tag_td_close_outline
end

#write_tag_td_close_inlineObject



243
244
245
# File 'lib/muwu/render_html_partial/render_contents.rb', line 243

def write_tag_td_close_inline
  @destination.write_inline_end tag_td_close
end

#write_tag_td_close_outlineObject



248
249
250
# File 'lib/muwu/render_html_partial/render_contents.rb', line 248

def write_tag_td_close_outline
  @destination.write_line tag_td_close
end

#write_tag_td_open(attr_list: nil) ⇒ Object



253
254
255
# File 'lib/muwu/render_html_partial/render_contents.rb', line 253

def write_tag_td_open(attr_list: nil)
  @destination.write_inline_indented tag_td_open(attr_list: attr_list)
end

#write_tag_tr_closeObject



258
259
260
# File 'lib/muwu/render_html_partial/render_contents.rb', line 258

def write_tag_tr_close
  @destination.write_line tag_tr_close
end

#write_tag_tr_open(html_id) ⇒ Object



263
264
265
# File 'lib/muwu/render_html_partial/render_contents.rb', line 263

def write_tag_tr_open(html_id)
  @destination.write_line tag_tr_open(html_id)
end

#write_text_section_heading(textobject) ⇒ Object



268
269
270
# File 'lib/muwu/render_html_partial/render_contents.rb', line 268

def write_text_section_heading(textobject)
  @destination.write_inline CGI::escape_html(textobject.heading)
end

#write_text_section_number(textobject) ⇒ Object



273
274
275
# File 'lib/muwu/render_html_partial/render_contents.rb', line 273

def write_text_section_number(textobject)
  @destination.write_inline textobject.numbering.join('.')
end