class Middleman::Cli::GlobAction
A Thor Action, modular code, which does the majority of the work.
def clean!
-
(void)
-
def clean! files = @cleaning_queue.select { |q| q.file? } directories = @cleaning_queue.select { |q| q.directory? } files.each do |f| base.remove_file f, :force => true end directories = directories.sort_by {|d| d.to_s.length }.reverse! directories.each do |d| base.remove_file d, :force => true if directory_empty? d end end
def cleaning?
-
(Boolean)
-
def cleaning? @config.has_key?(:clean) && @config[:clean] end
def directory_empty?(directory)
-
(Boolean)
-
Parameters:
-
directory
(String
) --
def directory_empty?(directory) directory.children.empty? end
def execute!
-
(void)
-
def execute! # Sort order, images, fonts, js/css and finally everything else. sort_order = %w(.png .jpeg .jpg .gif .bmp .svg .svgz .ico .woff .otf .ttf .eot .js .css) # Pre-request CSS to give Compass a chance to build sprites puts "== Prerendering CSS" if @app.logging? @app.sitemap.resources.select do |resource| resource.ext == ".css" end.each do |resource| Middleman::Cli::Build.shared_rack.get(URI.escape(resource.destination_path)) end puts "== Checking for Compass sprites" if @app.logging? # Double-check for compass sprites @app.files.find_new_files(Pathname.new(@app.source_dir) + @app.images_dir) # Sort paths to be built by the above order. This is primarily so Compass can # find files in the build folder when it needs to generate sprites for the # css files puts "== Building files" if @app.logging? resources = @app.sitemap.resources.sort do |a, b| a_idx = sort_order.index(a.ext) || 100 b_idx = sort_order.index(b.ext) || 100 a_idx <=> b_idx end # Loop over all the paths and build them. resources.each do |resource| next if @config[:glob] && !File.fnmatch(@config[:glob], resource.destination_path) output_path = base.render_to_file(resource) @cleaning_queue.delete(Pathname.new(output_path).realpath) if cleaning? end end
def initialize(base, config={})
-
config
(Hash
) -- -
base
(Middleman::Cli::Build
) --
def initialize(base, config={}) @app = base.class.shared_instance source = @app.source @destination = @app.build_dir @source = File.expand_path(base.find_in_source_paths(source.to_s)) super(base, @destination, config) end
def invoke!
-
(void)
-
def invoke! queue_current_paths if cleaning? execute! clean! if cleaning? end
def queue_current_paths
-
(void)
-
def queue_current_paths @cleaning_queue = [] Find.find(@destination) do |path| next if path.match(/\/\./) && !path.match(/\.htaccess/) unless path == destination @cleaning_queue << Pathname.new(path) end end if File.exist?(@destination) end