Sha256: 6e052c02ca1a6815a9d986a2099a4d9ae2c559a29ee2a891dd5384bd5c80ec63

Contents?: true

Size: 1.71 KB

Versions: 13

Compression:

Stored size: 1.71 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 writelines(dst_path, lines)
      FileUtils.mkdir_p(File.dirname(dst_path))
      File.open(dst_path, 'w') do |f|
        f.write lines
      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

13 entries across 13 versions & 1 rubygems

Version Path
sproutcore-1.4.2-java lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.2 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.1-java lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.1 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.0-java lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.0 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.0.rc.5 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.0.rc.4 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.0.rc.3 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.0.rc.2 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.4.0.rc lib/sproutcore/builders/stylesheet.rb
sproutcore-1.0.1049.pre.2 lib/sproutcore/builders/stylesheet.rb
sproutcore-1.0.1049.pre.1 lib/sproutcore/builders/stylesheet.rb