Fixed gsub! and new css rules
This commit is contained in:
parent
e0e2c311f3
commit
e5d8b42479
4 changed files with 95 additions and 23 deletions
17
Rules
17
Rules
|
@ -9,12 +9,29 @@
|
|||
|
||||
# CSS
|
||||
compile '/css/*' do
|
||||
filter :no_custom_css
|
||||
filter :sass
|
||||
filter :rainpress
|
||||
end
|
||||
route '/css/*' do
|
||||
'/Scratch/assets' + item.identifier.chop + '.css'
|
||||
end
|
||||
compile '/css/*', :rep => :mozilla do
|
||||
filter :mozilla
|
||||
filter :sass
|
||||
filter :rainpress
|
||||
end
|
||||
route '/css/*', :rep => :mozilla do
|
||||
'/Scratch/assets' + item.identifier.chop + '_mozilla.css'
|
||||
end
|
||||
compile '/css/*', :rep => :mozilla do
|
||||
filter :webkit
|
||||
filter :sass
|
||||
filter :rainpress
|
||||
end
|
||||
route '/css/*', :rep => :webkit do
|
||||
'/Scratch/assets' + item.identifier.chop + '_webkit.css'
|
||||
end
|
||||
|
||||
compile '/css/raw/*' do
|
||||
end
|
||||
|
|
48
lib/css.rb
Normal file
48
lib/css.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
class NoCustomCSS < Nanoc3::Filter
|
||||
identifier :no_custom_css
|
||||
def run(content, params={})
|
||||
res=""
|
||||
content.each do |line|
|
||||
res <<= line if not res=~/-(moz|webkit)/
|
||||
end
|
||||
return res
|
||||
end
|
||||
end
|
||||
|
||||
class MozillaCSS < Nanoc3::Filter
|
||||
identifier :mozilla
|
||||
def run(content, params={})
|
||||
res=""
|
||||
pref=[]
|
||||
depth=0
|
||||
content.each do |line|
|
||||
depth=line.sub(/^ */,'').size/2
|
||||
pref[depth]=line
|
||||
if res=~/-(moz)/
|
||||
[0..depth].each do |i|
|
||||
res <<= pref[i]+'\n'
|
||||
end
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
end
|
||||
|
||||
class WebkitCSS < Nanoc3::Filter
|
||||
identifier :webkit
|
||||
def run(content, params={})
|
||||
res=""
|
||||
pref=[]
|
||||
depth=0
|
||||
content.each do |line|
|
||||
depth=line.sub(/[^ ]*$/).size/2
|
||||
pref[depth]=line
|
||||
if res=~/-(moz)/
|
||||
[0..depth].each do |i|
|
||||
res <<= pref[i]+'\n'
|
||||
end
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
end
|
|
@ -2,10 +2,10 @@ class Graph < Nanoc3::Filter
|
|||
identifier :graph
|
||||
@@tmpfic="/tmp/graphtemp.dot"
|
||||
def run(content, params={})
|
||||
content.gsub(%r{<graph title="([^"]*)">(.+?)</graph>}m) do |full|
|
||||
content.gsub(%r{<graph( title="([^"]*)")?>(.+?)</graph>}m) do |full|
|
||||
# FileUtils.rm(@@tmpfic)
|
||||
title=$1
|
||||
str=$2
|
||||
title=$2
|
||||
str=$3
|
||||
filename=title.gsub(/[^a-zA-Z0-9_]/,"_")
|
||||
File.open(@@tmpfic,'w') do |f|
|
||||
f.write %[ digraph Source {
|
||||
|
|
|
@ -1,35 +1,42 @@
|
|||
class UltraVioletFilter < Nanoc3::Filter
|
||||
identifier :ultraviolet
|
||||
|
||||
def create_file_for_code(code, filename)
|
||||
# Create a plaintext file version for download.
|
||||
codeprefix=''
|
||||
codesuffix=''
|
||||
if filename
|
||||
webpath = @item.path
|
||||
code_path = "output#{webpath}code"
|
||||
url = webpath + 'code/' + filename
|
||||
if (url == @url)
|
||||
puts %{# erreur de redo : #{url}}
|
||||
end
|
||||
@url=url
|
||||
codeprefix=%{<div class="code"><div class="file"><a href="#{url}"> ➥ #{filename} </a></div><div class="withfile">\n}
|
||||
codesuffix=%{\n</div></div>}
|
||||
return [ codeprefix, codesuffix ]
|
||||
copy_text_to_file(code, filename, code_path)
|
||||
end
|
||||
return [ codeprefix, codesuffix ]
|
||||
end
|
||||
|
||||
def run(content, params={})
|
||||
require 'rubygems'
|
||||
require 'uv'
|
||||
code_rule = %r{(<code class="([^"]+?)"( file="([^"]+?)")?>(.+?)</code>)}m
|
||||
content.gsub!(code_rule) do |full|
|
||||
# original, lang, filename, code = full[0], full[1], full[3], full[4]
|
||||
new_content=content.gsub(code_rule) do |full|
|
||||
original, lang, filename, code = $1, $2, $4, $5
|
||||
if lang =~ /^(zsh|bash|sh|csh|shell)$/
|
||||
lang='shell-unix-generic'
|
||||
end
|
||||
# Create a plaintext file version for download.
|
||||
codeprefix=''
|
||||
codesuffix=''
|
||||
if filename
|
||||
webpath = @item.path
|
||||
code_path = "output#{webpath}code"
|
||||
url = webpath + 'code/' + filename
|
||||
if (url == @url)
|
||||
puts %{# erreur de redo : #{url}}
|
||||
break
|
||||
end
|
||||
@url=url
|
||||
copy_text_to_file(code, filename, code_path)
|
||||
codeprefix=%{<div class="code"><div class="file"><a href="#{url}"> ➥ #{filename} </a></div><div class="withfile">\n}
|
||||
codesuffix=%{\n</div></div>}
|
||||
end
|
||||
# Substitute the un-highlighted code with the highlighted code.
|
||||
codeprefix, codesuffix = create_file_for_code(code, filename)
|
||||
codeprefix+Uv.parse(code, "xhtml", lang, false, @config[:ultraviolet_theme])+codesuffix
|
||||
end
|
||||
content
|
||||
if new_content.nil?
|
||||
puts "NIL:::: #{@item.path}"
|
||||
end
|
||||
return new_content
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue