Sha256: 41e561503b158a8193fa355639a40619034201597534d985c8722a755dbb5da2

Contents?: true

Size: 1.91 KB

Versions: 13

Compression:

Stored size: 1.91 KB

Contents

require 'stitch-rb'

class SerenadeCompiler < Stitch::Compiler
  
  extensions :serenade
  
  def compile(path)
    content= File.read(path)
    viewname= File.basename(path).gsub('.serenade', '').gsub('.html', '').gsub('.', '_')
    %{
      Serenade.view(#{ viewname.to_json }, #{content.to_json});
    }
  end
  
end

class HoganCompiler < Stitch::Compiler
  # List of supported extensions
  extensions :mustache

  # A compile method which takes a file path,
  # and returns a compiled string
  def compile(path)
    content = File.read(path)
    %{
      var template = Hogan.compile(#{content.to_json});
      module.exports = (function(data){ return template.render(data); });
    }
  end
end

module CssJsCode
  
  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

  def transpile(content, ext)
    content
  end

end

class CssCompiler < Stitch::Compiler
  include CssJsCode

  extensions :css

  def compile(path)
    export_js_code path
  end

end


begin
  require 'sass'

  class SassCompiler < Stitch::Compiler
    include CssJsCode

    extensions :sass, :scss

    def compile(path)
      export_js_code path
    end

    def transpile(content, ext)
      type = (ext == '.sass') ? :sass : :scss
      Sass::Engine.new(content, :syntax=>type).render
    end
  end

rescue
  # Sass Not available
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gumdrop-0.6.1 lib/gumdrop/stitch_compilers.rb
gumdrop-0.6.0 lib/gumdrop/stitch_compilers.rb
gumdrop-0.5.2 lib/gumdrop/stitch_compilers.rb
gumdrop-0.5.1 lib/gumdrop/stitch_compilers.rb
gumdrop-0.5 lib/gumdrop/stitch_compilers.rb
gumdrop-0.4.0 lib/gumdrop/stitch_compilers.rb
gumdrop-0.3.10 lib/gumdrop/stitch_compilers.rb
gumdrop-0.3.9 lib/gumdrop/stitch_compilers.rb
gumdrop-0.3.8 lib/gumdrop/stitch_compilers.rb
gumdrop-0.3.7 lib/gumdrop/stitch_compilers.rb
gumdrop-0.3.6 lib/gumdrop/stitch_compilers.rb
gumdrop-0.3.5 lib/gumdrop/stitch_compilers.rb
gumdrop-0.3.4 lib/gumdrop/stitch_compilers.rb