Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Require and depend on paths directly on concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 24, 2011
1 parent 821899a commit e28d7a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
14 changes: 8 additions & 6 deletions lib/sprockets/concatenation.rb
Expand Up @@ -8,13 +8,16 @@

module Sprockets
class Concatenation
attr_reader :environment, :content_type
attr_reader :environment
attr_reader :content_type, :format_extension
attr_reader :paths, :source
attr_accessor :length, :mtime

def initialize(environment)
@environment = environment
@content_type = nil

@content_type = nil
@format_extension = nil

@paths = Set.new
@source = []
Expand Down Expand Up @@ -76,11 +79,10 @@ def requirable?(pathname)
end

def require(pathname)
@content_type ||= pathname.content_type
@content_type ||= pathname.content_type
@format_extension ||= pathname.format_extension

if pathname.directory?
depend pathname
elsif requirable?(pathname)
if requirable?(pathname)
unless paths.include?(pathname.to_s)
depend pathname
self << process(pathname)
Expand Down
28 changes: 15 additions & 13 deletions lib/sprockets/processor.rb
Expand Up @@ -11,9 +11,7 @@ class Processor < Tilt::Template
def prepare
@pathname = Pathname.new(file)

@depended_pathnames = []
@included_pathnames = []
@required_pathnames = []
@compat = false
end

Expand All @@ -25,7 +23,7 @@ def evaluate(context, locals, &block)
end

protected
attr_reader :depended_pathnames, :included_pathnames, :required_pathnames
attr_reader :included_pathnames
attr_reader :context

def process_directives
Expand All @@ -39,8 +37,6 @@ def process_directives
def process_source
result = ""

required_pathnames.each { |p| context.require(p) }

unless @directive_parser.processed_header.empty?
result << @directive_parser.processed_header << "\n"
end
Expand All @@ -51,8 +47,6 @@ def process_source
body += "\n" if body != "" && body !~ /\n\Z/m
result << body

depended_pathnames.each { |p| context.depend(p) }

# LEGACY
if compat? && constants.any?
result.gsub!(/<%=(.*?)%>/) { constants[$1.strip] }
Expand Down Expand Up @@ -80,7 +74,7 @@ def process_compat_directive
end

def process_depend_directive(path)
depended_pathnames << context.resolve(path)
context.depend(context.resolve(path))
end

def process_include_directive(path)
Expand All @@ -106,7 +100,7 @@ def process_require_directive(path)

context.resolve(path) do |candidate|
if self.pathname.content_type == candidate.content_type
required_pathnames << candidate
context.require(candidate)
return
end
end
Expand All @@ -118,13 +112,17 @@ def process_require_directory_directive(path = ".")
if relative?(path)
root = base_path.join(path).expand_path

required_pathnames << root
context.depend(root)

Dir["#{root}/*"].sort.each do |filename|
pathname = Pathname.new(filename)
if pathname.file? &&
pathname.content_type == self.pathname.content_type
required_pathnames << pathname
if pathname.file?
context.require(pathname)
else
context.depend(pathname)
end
end
end
else
Expand All @@ -136,10 +134,14 @@ def process_require_tree_directive(path = ".")
if relative?(path)
root = base_path.join(path).expand_path

required_pathnames << root
context.depend(root)

each_pathname_in_tree(path) do |pathname|
required_pathnames << pathname
if pathname.file?
context.require(pathname)
else
context.depend(pathname)
end
end
else
raise ArgumentError, "require_tree argument must be a relative path"
Expand Down

0 comments on commit e28d7a4

Please sign in to comment.