class Craftsman::Decorator::Base

Constants

FILTER_EXT_MAPPING

Public Class Methods

new(package) click to toggle source
# File lib/craftsman/decorator/base.rb, line 9
def initialize(package)
  @package = package
end
process(package, content) click to toggle source
# File lib/craftsman/decorator/base.rb, line 17
def self.process(package, content)
  self.new(package).process(content)
end

Public Instance Methods

process(content) click to toggle source
# File lib/craftsman/decorator/base.rb, line 13
def process(content)
  raise 'need be implemented'
end

Private Instance Methods

append_indent(str) click to toggle source
# File lib/craftsman/decorator/base.rb, line 48
def append_indent(str)
  str.lines.map do |l|
    "  #{l}"
  end.join
end
build_filter(target) click to toggle source
# File lib/craftsman/decorator/base.rb, line 23
    def build_filter(target)
      target_ext = target.match(/([^.]+)$/)[1]
      filter_name = FILTER_EXT_MAPPING[target_ext] || target_ext

      target_content = @package.get(target)

      filter = <<FILTER.strip
:#{filter_name}
#{append_indent(target_content.lstrip)}
FILTER

      if ['js', 'coffee'].include? target_ext
        filter = <<FILTER.strip
- content_for :javascripts do
#{append_indent(filter)}
FILTER
      end

      <<FILTER
///////////// #{target} /////////////
#{filter}

FILTER
    end