Module: CssJsCode

Included in:
CssCompiler
Defined in:
lib/gumdrop/stitch_support.rb

Instance Method Summary collapse

Instance Method Details

#export_js_code(path) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gumdrop/stitch_support.rb', line 50

def export_js_code(path)
  content= File.read(path)
  %{
    var css = #{ transpile(content, File.extname(path)).to_json },
        node = null;
    module.exports= {
      content: css,
      add: function(to){
        if(node != null) return;
        if(to == null) to= document.getElementsByTagName('HEAD')[0] || document.body;
        node= document.createElement('style');
        node.innerHTML= css;
        to.appendChild(node);
        return this;
      },
      remove: function() {
        if(node != null) {
          node.parentNode.removeChild(node);
          node = null;
        }
        return this;
      }
    };
  }
end

#transpile(content, ext) ⇒ Object



76
77
78
# File 'lib/gumdrop/stitch_support.rb', line 76

def transpile(content, ext)
  content
end