Sha256: 9286e6bbaa381186df7da405dce84ce54ecc744d89a1beead9e7d419af9e62dd

Contents?: true

Size: 966 Bytes

Versions: 3

Compression:

Stored size: 966 Bytes

Contents

module Flutterby
  module Filters
    def apply!(node)
      node.body = node.source

      # Apply all filters
      node.filters.each do |filter|
        meth = "process_#{filter}!"

        if Filters.respond_to?(meth)
          Filters.send(meth, node)
        end
      end
    end

    def process_rb!(node)
      # extend the node
      mod = Module.new
      mod.class_eval(node.body)
      node.extend(mod)
      node.filter! if node.respond_to?(:filter!)
    end

    def process_erb!(node)
      node.body = tilt("erb", node.body).render(node.view)
    end

    def process_slim!(node)
      node.body = tilt("slim", node.body).render(node.view)
    end

    def process_md!(node)
      node.body = Slodown::Formatter.new(node.body).complete.to_s
    end

    def process_scss!(node)
      node.body = Sass::Engine.new(node.body, syntax: :scss).render
    end

    def tilt(format, body)
      Tilt[format].new { body }
    end

    extend self
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flutterby-0.0.16 lib/flutterby/filters.rb
flutterby-0.0.15 lib/flutterby/filters.rb
flutterby-0.0.14 lib/flutterby/filters.rb