Class: Martile
- Inherits:
-
Object
- Object
- Martile
- Defined in:
- lib/martile.rb
Instance Attribute Summary collapse
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#to_html ⇒ Object
readonly
Returns the value of attribute to_html.
-
#to_s ⇒ Object
readonly
Returns the value of attribute to_s.
Instance Method Summary collapse
- #create_form(s) ⇒ Object
- #create_form_input(raw_name) ⇒ Object
-
#initialize(raw_s = '', ignore_domainlabel: nil, toc: true, embedded: false, debug: false, log: nil, plugins: {}) ⇒ Martile
constructor
embedded: Is the Martile object being run inside another Martile object?.
- #to_css ⇒ Object
- #to_js ⇒ Object
- #to_webpage ⇒ Object
Constructor Details
#initialize(raw_s = '', ignore_domainlabel: nil, toc: true, embedded: false, debug: false, log: nil, plugins: {}) ⇒ Martile
embedded: Is the Martile object being run inside another Martile object?
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/martile.rb', line 106 def initialize(raw_s='', ignore_domainlabel: nil, toc: true, embedded: false, debug: false, log: nil, plugins: {}) @debug = debug @data_source = {} @ignore_domainlabel, @log = ignore_domainlabel, log @css, @js = [], [] @plugins = initialize_plugins(plugins || []) raw_s.gsub!("\r",'') mmd = MindmapDoc.new(debug: debug) s5 = apply_filter(raw_s) {|x| mmd.to_mmd(x) } s10 = apply_filter(s5) {|x| mmd.transform(s5) } #puts 's10: ' + s10.inspect if debug #s10 = raw_s s20 = s10 =~ /^__DATA__$/ ? parse__data__(s10) : s10 puts ('s20: ' + s20.inspect).debug if debug s25 = apply_filter(s20) {|x| commentout x } s30 = apply_filter(s25) {|x| slashpre x } puts ('s30: ' + s30.inspect).debug if @debug #puts 's1 : ' + s1.inspect s40 = apply_filter(s30) {|x| code_block_to_html(x.strip + "\n") } puts ('s40: ' + s40.inspect).debug if @debug s45 = if ! then s40.gsub(/<pre[^>]*>/,'\0{::nomarkdown2}').gsub(/<\/pre>/,'{:2/}\0') else s40 end puts ('s45: ' + s45.inspect).debug if @debug #puts 's2 : ' + s2.inspect #s3 = apply_filter(s2, %w(ol ul)) {|x| explicit_list_to_html x } #puts 's3 : ' + s3.inspect s50 = apply_filter(s45) {|x| ordered_list_to_html x } puts ('s50: ' + s50.inspect).debug if @debug s60 = apply_filter(s50) {|x| unordered_list_to_html x } puts ('s60: ' + s60.inspect).debug if @debug s70 = apply_filter(s60) {|x| dynarex_to_markdown x } puts ('s70: ' + s70.inspect).debug if @debug s80 = apply_filter(s70) {|x| table_to_html x } puts ('s80: ' + s80.inspect).debug if @debug s90 = apply_filter(s80) {|x| underline x} puts ('s90: ' + s90.inspect).debug if @debug s100 = apply_filter(s90) {|x| section x } puts ('s100: ' + s100.inspect).debug if @debug s110 = apply_filter(s100) {|x| smartlink x } puts 's110: ' + s110.inspect if @debug #s11 = section s9 #puts 's11 : ' + s11.inspect s120 = apply_filter(s110) {|x| audiotag x } puts 's120 : ' + s120.inspect if @debug s130 = apply_filter(s120) {|x| videotag x } puts 's130 : ' + s130.inspect if @debug s140 = apply_filter(s130) {|x| x } puts 's140 : ' + s140.inspect if @debug s150 = apply_filter(s140) {|x| kvx_to_dl x } puts 's150 : ' + s150.inspect if @debug s160 = apply_filter(s150) {|x| list_item_to_hyperlink x } puts 's160 : ' + s160.inspect if @debug s165 = apply_filter(s160) {|x| formify x } puts 's165 : ' + s165.inspect if @debug s170 = apply_filter(s165) {|x| mtlite_utils x } puts 's170 : ' + s170.inspect if @debug s180 = apply_filter(s170) {|x| hyperlinkify x } puts 's180 : ' + s180.inspect if @debug s190 = apply_filter(s180) {|x| highlight x } puts 's190 : ' + s190.inspect if @debug s200 = apply_filter(s190) {|x| details x } puts 's200 : ' + s200.inspect if @debug s210 = apply_filter(s200) {|x| qrcodetag x } puts 's210 : ' + s210.inspect if @debug s220 = apply_filter(s210) {|x| svgtag x } puts 's220 : ' + s220.inspect if @debug s230 = apply_filter(s220) {|x| x } puts 's230 : ' + s230.inspect if @debug s240 = apply_filter(s230) {|x| script_out x } puts 's240 : ' + s240.inspect if @debug s245 = s240.gsub(/\{::nomarkdown2\}/,'').gsub(/\{:2\/\}/,'') puts 's245 : ' + s245.inspect if @debug s246 = mindwords(s245) s248 = @plugins.inject(s246) do |r, x| puts 'plugin x: ' + x.inspect if @debug x.apply(r) if x.respond_to? :apply end @to_s = s248.to_s s250 = apply_filter(s246) {|x| nomarkdown x } puts 's250 : ' + s250.inspect if @debug s252 = sidenav(s250) puts 's252 : ' + s252.inspect if @debug s253 = bang_xml(s252) puts ('s253 after bang_xml: ' + s253.inspect).debug if @debug s255 = tabs(s253) puts ('s255 after tabs: ' + s255.inspect).debug if @debug s257 = accordion(s255) puts 's257 : ' + s257.inspect if @debug toc = false if s257 =~ /class=['"]sidenav['"]>/ s260 = if toc then Yatoc.new(Kramdown::Document.new(s257).to_html, debug: debug).to_html else s257 end puts ('s260: ' + s260.inspect).debug if debug #puts 's17 : ' + s17.inspect @to_html = s260 end |
Instance Attribute Details
#data_source ⇒ Object (readonly)
Returns the value of attribute data_source.
102 103 104 |
# File 'lib/martile.rb', line 102 def data_source @data_source end |
#to_html ⇒ Object (readonly)
Returns the value of attribute to_html.
102 103 104 |
# File 'lib/martile.rb', line 102 def to_html @to_html end |
#to_s ⇒ Object (readonly)
Returns the value of attribute to_s.
102 103 104 |
# File 'lib/martile.rb', line 102 def to_s @to_s end |
Instance Method Details
#create_form(s) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/martile.rb', line 238 def create_form(s) a = LineTree.new(s, ignore_blank_lines: true).to_a def create_form_input(raw_name) name = raw_name.downcase[/\w+/] type = name =~ /password/ ? :password : :text ['div', {}, ['label', {for: name}, raw_name], ['input', {type: type, id: name, name: name}] ] end a2 = a[0][1..-1].select {|x| x[0] =~ /[^:]+\:/}.map do |items| line = items[0] case line when /^\w/ create_form_input(line[/^\w[^:]+\:/]) when /!/ name, value = line.match(/\[\s*!\s+([^:]+):\s+([^\]]+)/).captures ['input', {type: 'hidden', name: name, value: value}] end end , link = s.match(/\[([^\]]+)\]\(([^\)]+)\)/).captures a2 << ['div', {class: 'button'}, ['button', {type: 'submit'}, ]] a2.insert 0, 'form', {id: a[0][0], action: link, method: 'post'} doc = Rexle.new(a2) doc.root.element('div/input').attributes['autofocus'] = 'true' doc.xml pretty: true, declaration: false end |
#create_form_input(raw_name) ⇒ Object
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/martile.rb', line 242 def create_form_input(raw_name) name = raw_name.downcase[/\w+/] type = name =~ /password/ ? :password : :text ['div', {}, ['label', {for: name}, raw_name], ['input', {type: type, id: name, name: name}] ] end |
#to_css ⇒ Object
276 277 278 |
# File 'lib/martile.rb', line 276 def to_css() @css.join("\n") end |
#to_js ⇒ Object
280 281 282 |
# File 'lib/martile.rb', line 280 def to_js() @js.join("\n") end |
#to_webpage ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/martile.rb', line 284 def to_webpage() a = RexleBuilder.build do |xml| xml.html do xml.head do xml. name: "viewport", content: \ "width=device-width, initial-scale=1" xml.style "\nbody {font-family: Arial;}\n\n" + @css.join("\n") end xml.body to_html() end end doc = Rexle.new(a) doc.root.element('body').add \ Rexle::Element.new('script').add_text "\n" + @js.join("\n").gsub(/^ +\/\/[^\n]+\n/,'') "<!DOCTYPE html>\n" + doc.xml(pretty: true, declaration: false)\ .gsub(/<\/div>/,'\0' + "\n").gsub(/\n *<!--[^>]+>/,'') end |