Merge branch 'master' of github.com:botanicus/ace
This commit is contained in:
commit
fa513bdbc7
3 changed files with 29 additions and 13 deletions
1
bin/ace
1
bin/ace
|
@ -71,6 +71,5 @@ end
|
|||
puts
|
||||
|
||||
Ace::Item.all_instances.each do |item|
|
||||
puts "~ Generating #{item.output_path}"
|
||||
item.save!
|
||||
end
|
||||
|
|
17
lib/ace.rb
17
lib/ace.rb
|
@ -143,7 +143,23 @@ module Ace
|
|||
end
|
||||
end
|
||||
|
||||
def compare_mtime(one, others)
|
||||
File.exist?(one) && File.mtime(one) > others.map { |post| File.mtime(post) }.max
|
||||
end
|
||||
|
||||
def source_files
|
||||
[self.original_path]
|
||||
end
|
||||
|
||||
def fresh?
|
||||
@fresh ||= compare_mtime(self.output_path, self.source_files)
|
||||
end
|
||||
|
||||
def save!
|
||||
if self.fresh?
|
||||
puts "~ [IGNORE] #{self.output_path}"
|
||||
else
|
||||
puts "~ [UPDATE] #{self.output_path}"
|
||||
content = self.render # so filters can influence output_path
|
||||
|
||||
FileUtils.mkdir_p File.dirname(self.output_path)
|
||||
|
@ -152,6 +168,7 @@ module Ace
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Asset < Item
|
||||
end
|
||||
|
|
|
@ -7,15 +7,15 @@ require "albino"
|
|||
module Ace
|
||||
class PygmentsFilter < Filter
|
||||
def call(item, content)
|
||||
puts 'PygmentsFilter ************************'
|
||||
doc = Nokogiri::HTML(content)
|
||||
doc.css('pre').each do |pre|
|
||||
puts "\nWARNING: '#{item.original_path}' - element <pre> not contains attribute 'lang'\n" if pre['lang'].nil?
|
||||
puts "\nWARNING: '#{item.original_path}' - attribute 'lang' not contains any value\n" if !pre['lang'].nil? && pre['lang'].empty?
|
||||
puts "*** Syntax highlight using '#{pre['lang']}' lexer" unless pre['lang'].nil? || pre['lang'].empty?
|
||||
pre.replace Albino.colorize(pre.content, pre['lang']) unless pre['lang'].nil? || pre['lang'].empty?
|
||||
doc.css("pre[lang]").each do |pre|
|
||||
unless pre['lang'].nil? || pre['lang'].empty?
|
||||
# Set $VERBOSE to nil if you don't want to see this message.
|
||||
warn "~ Syntax highlight in '#{item.original_path}' using '#{pre['lang']}' lexer."
|
||||
pre.replace Albino.colorize(pre.content, pre['lang'])
|
||||
end
|
||||
doc
|
||||
end
|
||||
doc.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue