lib/enhancements.rb in nanoc-1.1 vs lib/enhancements.rb in nanoc-1.1.1
- old
+ new
@@ -87,30 +87,10 @@
end
class FileManager
@@stack = []
- COLORS = {
- :reset => "\e[0m",
-
- :bold => "\e[1m",
-
- :black => "\e[30m",
- :red => "\e[31m",
- :green => "\e[32m",
- :yellow => "\e[33m",
- :blue => "\e[34m",
- :magenta => "\e[35m",
- :cyan => "\e[36m",
- :white => "\e[37m"
- }
- ACTION_COLORS = {
- :create => COLORS[:bold] + COLORS[:green],
- :update => COLORS[:bold] + COLORS[:yellow],
- :identical => COLORS[:bold]
- }
-
def self.create_dir(a_name)
@@stack.push(a_name)
path = File.join(@@stack)
unless File.directory?(path)
FileUtils.mkdir_p(path)
@@ -119,19 +99,39 @@
yield if block_given?
@@stack.pop
end
def self.create_file(a_name)
- path = @@stack.empty? ? a_name : File.join(@@stack + [ a_name ])
+ path = File.join(@@stack + [ a_name ])
FileManager.create_dir(path.sub(/\/[^\/]+$/, '')) if @@stack.empty?
content = block_given? ? yield : nil
File.exist?(path) ? ( block_given? and File.read(path) == content ? log('identical', path) : log('update', path) ) : log('create', path)
open(path, 'w') { |io| io.write(content) unless content.nil? }
end
+end
- def self.log(a_action, a_path)
- puts format('%s%12s%s %s', ACTION_COLORS[a_action.to_sym], a_action, COLORS[:reset], a_path) unless $quiet == true
- end
+COLORS = {
+ :reset => "\e[0m",
+
+ :bold => "\e[1m",
+
+ :black => "\e[30m",
+ :red => "\e[31m",
+ :green => "\e[32m",
+ :yellow => "\e[33m",
+ :blue => "\e[34m",
+ :magenta => "\e[35m",
+ :cyan => "\e[36m",
+ :white => "\e[37m"
+}
+ACTION_COLORS = {
+ :create => COLORS[:bold] + COLORS[:green],
+ :update => COLORS[:bold] + COLORS[:yellow],
+ :identical => COLORS[:bold]
+}
+
+def log(a_action, a_path)
+ puts format('%s%12s%s %s', ACTION_COLORS[a_action.to_sym], a_action, COLORS[:reset], a_path) unless $quiet == true
end
def render(a_name, a_context={})
File.read('layouts/' + a_name + '.erb').eruby(a_context.merge({ :page => @page, :pages => @pages }))
end