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

#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

#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

#topicsObject

Returns the value of attribute topics.



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

def topics
  @topics
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



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

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

#render_contents_element(topics) ⇒ Object



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

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

#render_contents_headingObject



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

def render_contents_heading
  write_tag_h1_contents_heading
end

#render_ol(topics) ⇒ Object



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

def render_ol(topics)
  write_tag_ol_open
  @destination.margin_indent do
    topics.each do |topic|
      render_ol_li(topic)
    end
  end
  write_tag_ol_close
end

#render_ol_li(topic) ⇒ Object



67
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 67

def render_ol_li(topic)
  if task_depth_is_within_range(topic)
    html_id = Helper::HrefHelper.id_contents_item(topic)
    if topic.is_parent_heading
      write_tag_li_open(html_id)
      @destination.margin_indent do
        render_ol_li_heading_and_subsections(topic)
      end
      write_tag_li_close_outline
    elsif topic.is_not_parent_heading
      write_tag_li_open(html_id)
      render_ol_li_heading(topic)
      write_tag_li_close_inline
    end
  end
end

#render_ol_li_heading(topic) ⇒ Object



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

def render_ol_li_heading(topic)
  render_tag_a_section_heading(topic)
end

#render_ol_li_heading_and_subsections(topic) ⇒ Object



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

def render_ol_li_heading_and_subsections(topic)
  render_tag_a_section_heading(topic, trailing_line_feed: true)
  render_ol(topic.subtopics)
end

#render_table(topics) ⇒ Object



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

def render_table(topics)
  write_tag_table_open
  @destination.margin_indent do
    topics.each do |topic|
      render_table_tr(topic)
    end
  end
  write_tag_table_close
end

#render_table_tr(topic) ⇒ 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(topic)
  if task_depth_is_within_range(topic)
    html_id = Helper::HrefHelper.id_contents_item(topic)
    write_tag_tr_open(html_id)
    @destination.margin_indent do
      if topic.is_parent_heading
        render_table_tr_td_number(topic)
        render_table_tr_td_heading_and_subsections(topic)
      elsif topic.is_not_parent_heading
        render_table_tr_td_number(topic)
        render_table_tr_td_heading(topic)
      end
    end
    write_tag_tr_close
  end
end

#render_table_tr_td_heading(topic) ⇒ Object



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

def render_table_tr_td_heading(topic)
  write_tag_td_open(attr_list: "data-contents='table-topic'")
  render_tag_a_section_heading(topic)
  write_tag_td_close_inline
end

#render_table_tr_td_heading_and_subsections(topic) ⇒ 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(topic)
  write_tag_td_open(attr_list: "data-contents='table-topic'")
  render_tag_a_section_heading(topic, trailing_line_feed: true)
  @destination.margin_indent do
    render_table(topic.subtopics)
  end
  write_tag_td_close_outline
end

#render_table_tr_td_number(topic) ⇒ Object



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

def render_table_tr_td_number(topic)
  write_tag_td_open(attr_list: "data-contents='table-number'")
  render_tag_a_section_number(topic, attr_list: "tabindex='-1'")
  write_tag_td_close_inline
end

#render_tag_a_section_heading(topic, 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(topic, trailing_line_feed: false)
  href = Helper::HrefHelper.link_to_topic_header(topic, from: :contents)
  write_tag_a_open(href)
  write_text_section_heading(topic)
  write_tag_a_close
  if trailing_line_feed
    write_lf
  end
end

#render_tag_a_section_number(topic, 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(topic, attr_list: nil)
  href = Helper::HrefHelper.link_to_topic_header(topic, from: :contents)
  write_tag_a_open(href, attr_list: attr_list)
  write_text_section_number(topic)
  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_open(html_id) ⇒ Object



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

def write_tag_li_open(html_id)
  @destination.write_inline_indented tag_li_open(html_id)
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