class Middleman::RemoveIndent::Extension
Public Class Methods
new(app, options_hash = {}, &block)
click to toggle source
Calls superclass method
# File lib/middleman-remove-indent/extension.rb, line 8 def initialize(app, options_hash = {}, &block) super extension = self build_dir = app.config.build_dir exts = options.exts exts = Array(exts) if exts.instance_of? String app.after_build do targets = extension.target_files(build_dir, exts) extension.update_file!(targets) end end
Public Instance Methods
remove_indent(line)
click to toggle source
# File lib/middleman-remove-indent/extension.rb, line 42 def remove_indent(line) line.gsub!(/^(\s|\t)+/, '') (line.empty? && !options.remove_blank_line) ? "\n" : line end
target_files(dir, exts)
click to toggle source
# File lib/middleman-remove-indent/extension.rb, line 21 def target_files(dir, exts) paths = [] exts.each do |ext| paths.concat(Dir.glob(dir + "/**/*#{ext}")) end paths end
update_file!(target_files)
click to toggle source
# File lib/middleman-remove-indent/extension.rb, line 29 def update_file!(target_files) target_files.each do |file| open(file) do |f| data = [] f.each_line do |line| line = remove_indent(line) data.push(line) end File.write(file, data.join) end end end