class Middleman::Cli::GlobAction
A Thor
Action, modular code, which does the majority of the work.
Attributes
logger[R]
source[R]
Public Class Methods
new(base, config={})
click to toggle source
Setup the action
@param [Middleman::Cli::Build] base @param [Hash] config
Calls superclass method
# File lib/middleman-core/cli/build.rb, line 182 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
Public Instance Methods
invoke!()
click to toggle source
Execute the action @return [void]
# File lib/middleman-core/cli/build.rb, line 196 def invoke! queue_current_paths if cleaning? execute! clean! if cleaning? end
Protected Instance Methods
clean!()
click to toggle source
Remove files which were not built in this cycle @return [void]
# File lib/middleman-core/cli/build.rb, line 206 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
cleaning?()
click to toggle source
Whether we should clean the build @return [Boolean]
# File lib/middleman-core/cli/build.rb, line 223 def cleaning? @config.has_key?(:clean) && @config[:clean] end
directory_empty?(directory)
click to toggle source
Whether the given directory is empty @param [String] directory @return [Boolean]
# File lib/middleman-core/cli/build.rb, line 230 def directory_empty?(directory) directory.children.empty? end
execute!()
click to toggle source
Actually build the app @return [void]
# File lib/middleman-core/cli/build.rb, line 249 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
queue_current_paths()
click to toggle source
Get a list of all the paths in the destination folder and save them for comparison against the files we build in this cycle @return [void]
# File lib/middleman-core/cli/build.rb, line 237 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 !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/ end end