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
|
puts
|
||||||
|
|
||||||
Ace::Item.all_instances.each do |item|
|
Ace::Item.all_instances.each do |item|
|
||||||
puts "~ Generating #{item.output_path}"
|
|
||||||
item.save!
|
item.save!
|
||||||
end
|
end
|
||||||
|
|
27
lib/ace.rb
27
lib/ace.rb
|
@ -143,12 +143,29 @@ module Ace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save!
|
def compare_mtime(one, others)
|
||||||
content = self.render # so filters can influence output_path
|
File.exist?(one) && File.mtime(one) > others.map { |post| File.mtime(post) }.max
|
||||||
|
end
|
||||||
|
|
||||||
FileUtils.mkdir_p File.dirname(self.output_path)
|
def source_files
|
||||||
File.open(self.output_path, "w") do |file|
|
[self.original_path]
|
||||||
file.puts(content)
|
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)
|
||||||
|
File.open(self.output_path, "w") do |file|
|
||||||
|
file.puts(content)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,15 +7,15 @@ require "albino"
|
||||||
module Ace
|
module Ace
|
||||||
class PygmentsFilter < Filter
|
class PygmentsFilter < Filter
|
||||||
def call(item, content)
|
def call(item, content)
|
||||||
puts 'PygmentsFilter ************************'
|
|
||||||
doc = Nokogiri::HTML(content)
|
doc = Nokogiri::HTML(content)
|
||||||
doc.css('pre').each do |pre|
|
doc.css("pre[lang]").each do |pre|
|
||||||
puts "\nWARNING: '#{item.original_path}' - element <pre> not contains attribute 'lang'\n" if pre['lang'].nil?
|
unless pre['lang'].nil? || pre['lang'].empty?
|
||||||
puts "\nWARNING: '#{item.original_path}' - attribute 'lang' not contains any value\n" if !pre['lang'].nil? && pre['lang'].empty?
|
# Set $VERBOSE to nil if you don't want to see this message.
|
||||||
puts "*** Syntax highlight using '#{pre['lang']}' lexer" unless pre['lang'].nil? || pre['lang'].empty?
|
warn "~ Syntax highlight in '#{item.original_path}' using '#{pre['lang']}' lexer."
|
||||||
pre.replace Albino.colorize(pre.content, pre['lang']) unless pre['lang'].nil? || pre['lang'].empty?
|
pre.replace Albino.colorize(pre.content, pre['lang'])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
doc
|
doc.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue