This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Split src and full files - awesome import detection and single-file C…

…SS building.

The stylesheets under the `src` directory use @import rules to build up
larger stylesheets. This doesn't work well with asciidoc's full-file-include
default mechanism so we build full versions under the `templates` directory.
  • Loading branch information...
rtomayko committed Mar 4, 2008
1 parent 039a54d commit b2fd0cb9cf45f29ef6f3df0a1b6a8d62d05c8f70
View
@@ -1,40 +1,50 @@
require 'rake/clean'
-THEMES = %w[bare freebsdish]
+THEMES = FileList['src/*.css'].
+ reject { |f| f =~ /-(manpage|quirks)\.css/ }.
+ map { |f| File.basename(f).sub(/\.css$/, '') }.
+ uniq
-task 'default' => [ 'css', 'examples' ]
+task 'default' => 'all'
+
+task 'all' => [ 'stylesheets', 'examples' ]
desc 'Build all examples'
task 'examples'
desc 'Build CSS for all themes'
-task 'css'
+task 'stylesheets'
# ---------------------------------------------------------------------------
# Theme CSS Generation
# ---------------------------------------------------------------------------
-(THEMES - ['bare']).each do |theme|
- file "#{theme}.css" => [ "#{theme}.css.in", "bare.css" ] do |f|
- doing :css, f.name
- sh "cat bare.css #{f.name}.in > #{f.name}"
- end
- file "#{theme}-manpage.css" => [ "#{theme}-manpage.css.in", 'bare-manpage.css' ] do |f|
+FileList['src/*.css'].each do |srcfile|
+ basename = File.basename(srcfile)
+ destfile = "stylesheets/#{basename}"
+ prereqs = (File.read(srcfile, 1024) || '').
+ split("\n").
+ grep(/@import/).
+ map { |line| line.match(/@import\s+url\((.*)\)\s*;/)[1] }.
+ map { |file| "stylesheets/#{file}" }
+ file destfile => [srcfile, *prereqs] do |f|
doing :css, f.name
- sh "cat bare-manpage.css #{f.name}.in > #{f.name}"
- end
- file "#{theme}-quirks.css" => [ "#{theme}-quirks.css.in", 'bare-quirks.css' ] do |f|
- doing :css, f.name
- sh "cat bare-quirks.css #{f.name}.in > #{f.name}"
+ src = File.read(srcfile)
+ src.gsub!(/@import\s+url\((.*)\)\s*;/) do |match|
+ [
+ "/* BEG #{match} */",
+ File.read("stylesheets/#{$1}"),
+ "/* END #{match} */"
+ ].join("\n")
+ end
+ mkdir_p 'stylesheets'
+ File.open(destfile, 'wb') { |io| io.write(src) }
+ # set modified time to the oldest of all prerequisites
+ mtime = f.prerequisites.map { |fn| File.mtime(fn) }.max
+ File.utime(Time.now, mtime, destfile)
end
- CLOBBER.include "#{theme}{,-manpage,-quirks}.css"
- desc "Build CSS for #{theme} only"
- task "css:#{theme}" => [
- "#{theme}.css",
- "#{theme}-manpage.css",
- "#{theme}-quirks.css"
- ]
- task 'css' => "css:#{theme}"
+ CLOBBER.include destfile
+ task 'stylesheets' => destfile
end
# ---------------------------------------------------------------------------
@@ -54,8 +64,7 @@ EX_ART_SRCS.each do |srcfile|
srcfile,
'examples/xhtml11-article.conf',
'examples/asciidoc.conf',
- "#{theme}.css",
- "#{theme}-quirks.css"
+ "src/#{theme}.css"
]
destfile = srcfile.
sub(/examples\/(.*)\.txt/, "examples/#{theme}-\\1.html")
@@ -73,9 +82,8 @@ EX_MAN_SRCS.each do |srcfile|
srcfile,
'examples/xhtml11-manpage.conf',
'examples/asciidoc.conf',
- "#{theme}.css",
- "#{theme}-quirks.css",
- "#{theme}-manpage.css"
+ "src/#{theme}.css",
+ "src/#{theme}-manpage.css"
]
destfile = srcfile.
sub(/examples\/(.*)\.txt/, "examples/#{theme}-\\1.html")
@@ -124,8 +132,9 @@ def asciidoc(src, target, *args)
else
{}
end
+ attributes = { :linkcss => '' }.merge(attributes)
doing :doc, target
- args = %W[asciidoc --unsafe -o #{target} -a stylesdir=#{Dir.pwd}] +
+ args = %W[asciidoc --unsafe -o #{target} -a stylesdir=../src] +
args +
attributes.map { |k,v| ["-a", "#{k}=#{v}"] }.flatten +
[ (verbose ? '--verbose' : nil), src].compact
View
@@ -1 +0,0 @@
-/* bare-quirks.css */
View
@@ -3,8 +3,6 @@ newline=\n
tabsize=4
[attributes]
-stylesdir=./..
quirks
icons=
warning_caption=Warning
-linkcss=
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,3 +1,4 @@
+@import url(bare-manpage.css);
/* ---------------------------------------------------------------------------
FreeBSD Manpage AsciiDoc Styles
Ryan Tomayko <r@tomayko.com>
No changes.
@@ -1,3 +1,5 @@
+@import url(bare.css);
+
body {
font-family:verdana,helvetica,arial,sans-serif;
font-size:100%;

0 comments on commit b2fd0cb

Please sign in to comment.