class Modulizer::Dummy

Public Class Methods

compile(mod_file = "") click to toggle source
# File lib/modulizer.rb, line 6
def self.compile(mod_file = "")
  mod_name = mod_file[(mod_file.rindex('/')+1)...mod_file.rindex('.')]
  content  = File.read(mod_file)

  script   = content.match(/<script(.*?)>(.*)<\/script>/m)
  style    = content.match(/<style(.*?)>(.*)<\/style>/m)
  template = content.match(/<template(.*?)>(.*)<\/template>/m)

  script_mode   = read_attributes script[1]
  style_mode    = read_attributes style[1]
  template_mode = read_attributes template[1]

  script_content   = escape_js_variable_string script[2]
  style_content    = escape_js_variable_string(StyleBuilder.build(mod_name, style[2], style_mode))
  template_content = escape_js_variable_string template[2]

  """/* generated js file for module:#{mod_name} */
  (function(window,$){
    var script =
    '<script>#{script_content}</script>';

    var template =
    '#{template_content}';

    var style =
    '<style>#{style_content}</style>';

    $(function(){
      $('div##{mod_name}').html(style + template + script);
    });
  })(window, jQuery);
  """
end

Private Class Methods

escape_js_variable_string(str = "") click to toggle source
# File lib/modulizer.rb, line 57
def self.escape_js_variable_string(str = "")
  str.gsub("\n", "\\\n")
     .gsub("'", { "'" => "\\'" })
     .gsub("\"", "\\\"")
end
read_attributes(str = "") click to toggle source
# File lib/modulizer.rb, line 41
def self.read_attributes(str = "")
  m = {}
  str.strip.split(' ').each do |item|
    (k, v) = item.split('=')
    m[k] =
    if v.nil?
      true
    elsif (v[0] != '"' && v[-1] != '"') && (v[0] != "'" && v[-1] != "'")
      raise "attributes should be in quotes"
    else
      v[1...-1]
    end
  end
  m
end