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 logger.debug "== Prerendering CSS" @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 logger.debug "== Checking for Compass sprites" # Double-check for compass sprites @app.files.find_new_files((Pathname(@app.source_dir) + @app.images_dir).relative_path_from(@app.root_path)) @app.sitemap.ensure_resource_list_updated! # 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 logger.debug "== Building files" resources = @app.sitemap.resources.sort_by do |r| sort_order.index(r.ext) || 100 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) if cleaning? pn = Pathname(output_path) @cleaning_queue.delete(pn.realpath) if pn.exist? end end ::Middleman::Profiling.report("build") 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)) @logger = Middleman::Cli::Build.shared_instance.logger 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 = [] return unless File.exist?(@destination) paths = ::Middleman::Util.all_files_under(@destination) @cleaning_queue += paths.select do |path| !path.to_s.match(/\/\./) || path.to_s.match(/\.htaccess/) end end