class Qwik::WemaHtmlGenerator

Public Class Methods

generate(wemas, pagename) click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 316
def self.generate(wemas, pagename)
  ar = [:div]
  ar << load_css            # At the first, load CSS.
  ar << make_menu           # Then, make menu.
  wemas.each {|wema|
    ar << get_div(wema)    # Create all divs for wemas.
  }
  ar << editor_html(pagename)       # Create an editor.
  ar << load_js             # At the last, load JavaScript.
  return ar
end

Private Class Methods

bg_color() click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 430
def self.bg_color
  ar = ['Background'+': ', [:input, {:id=>'bg', :name=>'bg'}]]
  ar += ['#fff', '#fcc', '#cfc', '#ccf', '#ffc', '#000'].map {|c|
    radio_color('bg', c)
  }
  return [:p, ar]
end
editor_html(pagename) click to toggle source
editor window
# File vendor/qwik/lib/qwik/act-wema.rb, line 403
def self.editor_html(pagename)
  action = "#{pagename}.wema"
  return [:div, {:id=>'editor', :class=>'wema'},
    [:div, {:class=>'menubar'},
      [:span, {:class=>'handle'}, 'editor'],
      [:span, {:class=>'close'},
        [:a, {:href=>'javascript:wema_editor_hide()'}, 'X']]],
    [:div, {:class=>'cont'},
      [:form, {:method=>'POST', :action=>action,
          :id=>'frm', :name=>'frm'},
        [:p, {:class=>'save'},
          [:input, {:type=>'submit', :value=>'Save'}]],
        [:textarea, {:name=>'body', :cols=>'40', :rows=>'7'}, ''],
        font_color,
        bg_color,
        [:p, 'Draw Line: ', text('ln')],
        [:p, 'x:', text('l'), ' y:', text('t')],
        param('id', ''),
        param('mode', 'edit')]]]
end
font_color() click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 424
def self.font_color
  ar = ['Text color: ', [:input, {:id=>'tc', :name=>'tc'}]]
  ar += ['#000', '#600', '#060', '#006'].map {|c| radio_color('tc', c) }
  return [:p, ar]
end
get_div(wema) click to toggle source
wema window
# File vendor/qwik/lib/qwik/act-wema.rb, line 345
def self.get_div(wema)
  k = wema.get_id

  text = wema.text || ''

  tokens = TextTokenizer.tokenize(text, true)
  h = TextParser.make_tree(tokens)

  h = resolve_href(h)

  h << '' if h.length == 0

  fg = wema.fg
  fg = '#000' if fg.nil? || fg.empty?
  bg = wema.bg
  bg = '#fff' if bg.nil? || bg.empty?

  x = wema.x
  y = wema.y

  div = [:div, {:id=>k, :class=>'wema',
      :style=>"left:#{x}px;top:#{y}px;color:#{fg};background:#{bg};",
      :wema_tc=>wema.fg,
      :wema_bg=>wema.bg,
      :wema_ln=>wema.connected,
      :wema_d=>wema.text},
    [:div, {:class=>'menubar'}, [:span, {:class=>'handle'}, k],
      [:span, {:class=>'cmd'},
        [:a, {:href=>"javascript:wema_setpos('#{k}')"}, 'set'],
        [:a, {:href=>"javascript:wema_edit('#{k}')"}, 'edit'],
        [:a, {:href=>"javascript:wema_link('#{k}')"}, 'link']]],
    [:div, {:class=>'cont'}, h]]
  return div
end
hidden(a='', b=nil) click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 456
def self.hidden(a='', b=nil)
  h = {:type=>'hidden'}
  h.update(:name=>a) if a
  h.update(:value=>b) if b
  return [:input, h]
end
load_css() click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 330
def self.load_css
  return [:style, "@import '.theme/css/wema.css';"]
end
load_js() click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 340
def self.load_js
  [:script, {:type=>'text/javascript', :src=>'.theme/js/wema.js'}, '']
end
make_menu() click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 334
def self.make_menu
  return [:span, {:class=>'attribute'}, 'Post-it', ': ',
    [:a, {:href=>'javascript:wema_editor_show()'}, 'New Post-it'],
    ' (', [:a, {:href=>'javascript:wema_help_show()'}, 'Help'], ')']
end
param(*a) click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 444
def self.param(*a)
  return text(*a) if $wema_debug
  return hidden(*a)
end
radio_color(name, color) click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 438
def self.radio_color(name, color)
  return [:a, {:href=>"javascript:wema_set_color('#{name}', '#{color}')",
      :class=>'color',
      :style=>"color:#{color};background:#{color};"}, '[_]']
end
resolve_href(wabisabi) click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 380
def self.resolve_href(wabisabi)
  wabisabi.each_tag(:a){|w|
    ww = resolve_ref(w)
    w = ww ? ww : [w]
    w
  }
end
resolve_ref(w) click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 388
def self.resolve_ref(w)
  attr = w[1]
  return nil if attr.nil? || !attr.is_a?(Hash)
  href = attr[:href].to_s

  if /^(?:http|https|ftp|file):\/\// =~ href        # external link
    w.set_attr :class=>'external', :rel=>'nofollow',
      :href=>".redirect?url=#{href}"
    return [w]
  end

  return nil
end
text(a='', b=nil) click to toggle source
# File vendor/qwik/lib/qwik/act-wema.rb, line 449
def self.text(a='', b=nil)
  h = {}
  h.update(:name=>a) if a
  h.update(:value=>b) if b
  return [:input, h]
end