Sha256: b90f32ffbb019565c5855aefb9dc23cb18a77cae3ba22b426177518ea22aafe5

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

# ===========================================================================
# Project:   Abbot - SproutCore Build Tools
# Copyright: ©2009 Apple Inc.
#            portions copyright @2006-2009 Sprout Systems, Inc.
#            and contributors
# ===========================================================================

require "sproutcore/builders/base"
require 'fileutils'

module SC

  # This builder is used to process a single CSS stylesheet.  Converts any
  # build tool directives (such as sc_require() and sc_resource()) into
  # comments.  It will also substitute any calls to sc_static() (or
  # static_url())  This builder does NOT handle combining multiple stylesheets
  # into one.  See the Builder::CombineStylesheets builder instead.
  #
  class Builder::Stylesheet < Builder::Base

    def readlines(src_path)
      if File.exist?(src_path) && !File.directory?(src_path)
        File.read(src_path)
      else
        ""
      end
    end

    def build(dst_path)
      code = rewrite_inline_code(readlines(entry[:source_path]))
      writelines dst_path, code
    end

    # Rewrites any inline content such as static urls.  Subclasseses can
    # override this to rewrite any other inline content.
    #
    # The default will rewrite calls to static_url().
    def rewrite_inline_code(code)
      # look for sc_require, require or sc_resource.  wrap in comment
      code.gsub!(/((sc_require|require|sc_resource)\(\s*['"].*["']\s*\)\s*\;)/, '/* \1 */')
      replace_static_url(code)
      code
    end

    def static_url(url=''); "url('#{url}')" ; end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sproutcore-1.4.4-java lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.4 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.3.1 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.3-java lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.3 lib/sproutcore/builders/stylesheet.rb