giraffesoft-webby 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +218 -0
- data/README.rdoc +92 -0
- data/Rakefile +62 -0
- data/bin/webby +41 -0
- data/bin/webby-gen +41 -0
- data/examples/blog/Sitefile +7 -0
- data/examples/blog/tasks/blog.rake +72 -0
- data/examples/blog/templates/atom_feed.erb +40 -0
- data/examples/blog/templates/blog/month.erb +22 -0
- data/examples/blog/templates/blog/post.erb +16 -0
- data/examples/blog/templates/blog/year.erb +22 -0
- data/examples/presentation/Sitefile +10 -0
- data/examples/presentation/content/css/uv/twilight.css +137 -0
- data/examples/presentation/content/presentation/_sample_code.txt +10 -0
- data/examples/presentation/content/presentation/index.txt +63 -0
- data/examples/presentation/content/presentation/s5/blank.gif +0 -0
- data/examples/presentation/content/presentation/s5/bodybg.gif +0 -0
- data/examples/presentation/content/presentation/s5/framing.css +23 -0
- data/examples/presentation/content/presentation/s5/iepngfix.htc +42 -0
- data/examples/presentation/content/presentation/s5/opera.css +7 -0
- data/examples/presentation/content/presentation/s5/outline.css +15 -0
- data/examples/presentation/content/presentation/s5/pretty.css +86 -0
- data/examples/presentation/content/presentation/s5/print.css +25 -0
- data/examples/presentation/content/presentation/s5/s5-core.css +9 -0
- data/examples/presentation/content/presentation/s5/slides.css +3 -0
- data/examples/presentation/content/presentation/s5/slides.js +553 -0
- data/examples/presentation/layouts/presentation.txt +43 -0
- data/examples/presentation/templates/_code_partial.erb +13 -0
- data/examples/presentation/templates/presentation.erb +40 -0
- data/examples/tumblog/Sitefile +9 -0
- data/examples/tumblog/content/css/tumblog.css +308 -0
- data/examples/tumblog/content/images/tumblog/permalink.gif +0 -0
- data/examples/tumblog/content/images/tumblog/rss.gif +0 -0
- data/examples/tumblog/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
- data/examples/tumblog/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
- data/examples/tumblog/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
- data/examples/tumblog/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
- data/examples/tumblog/content/tumblog/200807/up-a-tree/index.txt +13 -0
- data/examples/tumblog/content/tumblog/index.txt +37 -0
- data/examples/tumblog/content/tumblog/rss.txt +37 -0
- data/examples/tumblog/layouts/tumblog/default.txt +44 -0
- data/examples/tumblog/layouts/tumblog/post.txt +15 -0
- data/examples/tumblog/lib/tumblog_helper.rb +32 -0
- data/examples/tumblog/tasks/tumblog.rake +30 -0
- data/examples/tumblog/templates/atom_feed.erb +40 -0
- data/examples/tumblog/templates/tumblog/conversation.erb +12 -0
- data/examples/tumblog/templates/tumblog/link.erb +10 -0
- data/examples/tumblog/templates/tumblog/photo.erb +13 -0
- data/examples/tumblog/templates/tumblog/post.erb +12 -0
- data/examples/tumblog/templates/tumblog/quote.erb +11 -0
- data/examples/webby/Sitefile +19 -0
- data/examples/webby/content/communicate/index.txt +28 -0
- data/examples/webby/content/css/background.gif +0 -0
- data/examples/webby/content/css/blueprint/print.css +76 -0
- data/examples/webby/content/css/blueprint/screen.css +696 -0
- data/examples/webby/content/css/coderay.css +96 -0
- data/examples/webby/content/css/site.css +196 -0
- data/examples/webby/content/css/uv/twilight.css +137 -0
- data/examples/webby/content/index.txt +37 -0
- data/examples/webby/content/learn/index.txt +28 -0
- data/examples/webby/content/reference/index.txt +204 -0
- data/examples/webby/content/release-notes/index.txt +21 -0
- data/examples/webby/content/release-notes/rel-0-9-0/index.txt +74 -0
- data/examples/webby/content/release-notes/rel-0-9-1/index.txt +93 -0
- data/examples/webby/content/release-notes/rel-0-9-2/index.txt +14 -0
- data/examples/webby/content/release-notes/rel-0-9-3/index.txt +47 -0
- data/examples/webby/content/robots.txt +6 -0
- data/examples/webby/content/script/jquery.corner.js +152 -0
- data/examples/webby/content/script/jquery.js +31 -0
- data/examples/webby/content/sitemap.txt +31 -0
- data/examples/webby/content/tips_and_tricks/index.txt +97 -0
- data/examples/webby/content/tutorial/index.txt +135 -0
- data/examples/webby/content/user-manual/index.txt +419 -0
- data/examples/webby/layouts/default.txt +49 -0
- data/examples/webby/templates/page.erb +10 -0
- data/examples/website/Sitefile +7 -0
- data/examples/website/content/css/blueprint/ie.css +26 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/key.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/readme.txt +32 -0
- data/examples/website/content/css/blueprint/plugins/buttons/screen.css +97 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/screen.css +71 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/readme.txt +18 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/screen.css +40 -0
- data/examples/website/content/css/blueprint/plugins/rtl/readme.txt +10 -0
- data/examples/website/content/css/blueprint/plugins/rtl/screen.css +109 -0
- data/examples/website/content/css/blueprint/print.css +30 -0
- data/examples/website/content/css/blueprint/screen.css +251 -0
- data/examples/website/content/css/blueprint/src/forms.css +49 -0
- data/examples/website/content/css/blueprint/src/grid.css +212 -0
- data/examples/website/content/css/blueprint/src/grid.png +0 -0
- data/examples/website/content/css/blueprint/src/ie.css +59 -0
- data/examples/website/content/css/blueprint/src/print.css +85 -0
- data/examples/website/content/css/blueprint/src/reset.css +38 -0
- data/examples/website/content/css/blueprint/src/typography.css +105 -0
- data/examples/website/content/css/coderay.css +111 -0
- data/examples/website/content/css/site.css +67 -0
- data/examples/website/content/index.txt +19 -0
- data/examples/website/layouts/default.txt +61 -0
- data/examples/website/lib/breadcrumbs.rb +28 -0
- data/examples/website/templates/_partial.erb +10 -0
- data/examples/website/templates/page.erb +18 -0
- data/lib/webby.rb +233 -0
- data/lib/webby/apps.rb +12 -0
- data/lib/webby/apps/generator.rb +276 -0
- data/lib/webby/apps/main.rb +258 -0
- data/lib/webby/auto_builder.rb +157 -0
- data/lib/webby/builder.rb +172 -0
- data/lib/webby/core_ext/enumerable.rb +11 -0
- data/lib/webby/core_ext/hash.rb +28 -0
- data/lib/webby/core_ext/kernel.rb +26 -0
- data/lib/webby/core_ext/string.rb +163 -0
- data/lib/webby/core_ext/time.rb +9 -0
- data/lib/webby/filters.rb +85 -0
- data/lib/webby/filters/basepath.rb +97 -0
- data/lib/webby/filters/erb.rb +9 -0
- data/lib/webby/filters/haml.rb +18 -0
- data/lib/webby/filters/markdown.rb +16 -0
- data/lib/webby/filters/maruku.rb +16 -0
- data/lib/webby/filters/outline.rb +309 -0
- data/lib/webby/filters/sass.rb +17 -0
- data/lib/webby/filters/slides.rb +56 -0
- data/lib/webby/filters/textile.rb +16 -0
- data/lib/webby/filters/tidy.rb +76 -0
- data/lib/webby/filters/wiki_words.rb +14 -0
- data/lib/webby/helpers.rb +30 -0
- data/lib/webby/helpers/capture_helper.rb +141 -0
- data/lib/webby/helpers/coderay_helper.rb +69 -0
- data/lib/webby/helpers/graphviz_helper.rb +136 -0
- data/lib/webby/helpers/tag_helper.rb +65 -0
- data/lib/webby/helpers/tex_img_helper.rb +133 -0
- data/lib/webby/helpers/ultraviolet_helper.rb +63 -0
- data/lib/webby/helpers/url_helper.rb +241 -0
- data/lib/webby/journal.rb +126 -0
- data/lib/webby/link_validator.rb +160 -0
- data/lib/webby/renderer.rb +389 -0
- data/lib/webby/resources.rb +137 -0
- data/lib/webby/resources/db.rb +251 -0
- data/lib/webby/resources/layout.rb +54 -0
- data/lib/webby/resources/meta_file.rb +211 -0
- data/lib/webby/resources/page.rb +81 -0
- data/lib/webby/resources/partial.rb +85 -0
- data/lib/webby/resources/resource.rb +201 -0
- data/lib/webby/resources/static.rb +36 -0
- data/lib/webby/stelan/mktemp.rb +135 -0
- data/lib/webby/stelan/paginator.rb +165 -0
- data/lib/webby/tasks/build.rake +27 -0
- data/lib/webby/tasks/create.rake +25 -0
- data/lib/webby/tasks/deploy.rake +22 -0
- data/lib/webby/tasks/growl.rake +16 -0
- data/lib/webby/tasks/validate.rake +19 -0
- data/spec/core_ext/hash_spec.rb +47 -0
- data/spec/core_ext/string_spec.rb +110 -0
- data/spec/core_ext/time_spec.rb +19 -0
- data/spec/data/hooligans/bad_meta_data_1.txt +34 -0
- data/spec/data/hooligans/bad_meta_data_2.txt +34 -0
- data/spec/data/html/anchor.html +11 -0
- data/spec/data/html/external.html +10 -0
- data/spec/data/html/invalid-relative.html +10 -0
- data/spec/data/html/relative-anchor.html +10 -0
- data/spec/data/html/relative-invalid-anchor.html +10 -0
- data/spec/data/html/relative.html +10 -0
- data/spec/data/outline/basic.out +81 -0
- data/spec/data/outline/basic.txt +25 -0
- data/spec/data/outline/no_clobber.out +86 -0
- data/spec/data/outline/numbering.out +81 -0
- data/spec/data/outline/numbering_only.out +21 -0
- data/spec/data/outline/toc_range_1.out +66 -0
- data/spec/data/outline/toc_range_2.out +55 -0
- data/spec/data/outline/toc_style.out +81 -0
- data/spec/data/site/Sitefile +9 -0
- data/spec/data/site/content/_partial.txt +10 -0
- data/spec/data/site/content/css/coderay.css +111 -0
- data/spec/data/site/content/css/site.css +67 -0
- data/spec/data/site/content/css/tumblog.css +308 -0
- data/spec/data/site/content/images/tumblog/permalink.gif +0 -0
- data/spec/data/site/content/images/tumblog/rss.gif +0 -0
- data/spec/data/site/content/index.txt +19 -0
- data/spec/data/site/content/photos.txt +21 -0
- data/spec/data/site/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
- data/spec/data/site/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
- data/spec/data/site/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
- data/spec/data/site/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
- data/spec/data/site/content/tumblog/200807/up-a-tree/index.txt +13 -0
- data/spec/data/site/content/tumblog/index.txt +37 -0
- data/spec/data/site/content/tumblog/rss.txt +37 -0
- data/spec/data/site/layouts/default.txt +58 -0
- data/spec/data/site/layouts/tumblog/default.txt +44 -0
- data/spec/data/site/layouts/tumblog/post.txt +15 -0
- data/spec/data/site/lib/breadcrumbs.rb +28 -0
- data/spec/data/site/lib/tumblog_helper.rb +32 -0
- data/spec/data/site/tasks/tumblog.rake +30 -0
- data/spec/data/site/templates/_partial.erb +10 -0
- data/spec/data/site/templates/atom_feed.erb +40 -0
- data/spec/data/site/templates/page.erb +18 -0
- data/spec/data/site/templates/presentation.erb +40 -0
- data/spec/data/site/templates/tumblog/conversation.erb +12 -0
- data/spec/data/site/templates/tumblog/link.erb +10 -0
- data/spec/data/site/templates/tumblog/photo.erb +13 -0
- data/spec/data/site/templates/tumblog/post.erb +12 -0
- data/spec/data/site/templates/tumblog/quote.erb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/webby/apps/generator_spec.rb +117 -0
- data/spec/webby/apps/main_spec.rb +88 -0
- data/spec/webby/filters/basepath_spec.rb +167 -0
- data/spec/webby/filters/maruku_spec.rb +31 -0
- data/spec/webby/filters/outline_spec.rb +92 -0
- data/spec/webby/filters/textile_spec.rb +31 -0
- data/spec/webby/helpers/capture_helper_spec.rb +56 -0
- data/spec/webby/link_validator_spec.rb +154 -0
- data/spec/webby/renderer_spec.rb +139 -0
- data/spec/webby/resources/db_spec.rb +250 -0
- data/spec/webby/resources/layout_spec.rb +83 -0
- data/spec/webby/resources/meta_file_spec.rb +171 -0
- data/spec/webby/resources/page_spec.rb +111 -0
- data/spec/webby/resources/partial_spec.rb +58 -0
- data/spec/webby/resources/resource_spec.rb +219 -0
- data/spec/webby/resources/static_spec.rb +49 -0
- data/spec/webby/resources_spec.rb +69 -0
- data/tasks/mswin32.rake +38 -0
- data/tasks/website.rake +37 -0
- metadata +372 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
class Hash
|
3
|
+
|
4
|
+
def sanitize!
|
5
|
+
h = self.injecting({}) do |h, (k, v)|
|
6
|
+
h[k] = case v
|
7
|
+
when 'none', 'nil'; nil
|
8
|
+
when 'true', 'yes'; true
|
9
|
+
when 'false', 'no'; false
|
10
|
+
else v end
|
11
|
+
end
|
12
|
+
self.replace h
|
13
|
+
end
|
14
|
+
|
15
|
+
def stringify_keys
|
16
|
+
h = {}
|
17
|
+
self.each {|k,v| h[k.to_s] = v}
|
18
|
+
return h
|
19
|
+
end
|
20
|
+
|
21
|
+
def symbolize_keys
|
22
|
+
h = {}
|
23
|
+
self.each {|k,v| h[k.to_sym] = v}
|
24
|
+
return h
|
25
|
+
end
|
26
|
+
end # class Hash
|
27
|
+
|
28
|
+
# EOF
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module Kernel
|
3
|
+
|
4
|
+
# :stopdoc:
|
5
|
+
WINDOWS = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM
|
6
|
+
DEV_NULL = WINDOWS ? 'NUL:' : '/dev/null'
|
7
|
+
# :startdoc:
|
8
|
+
|
9
|
+
def cmd_available?( *args )
|
10
|
+
io = [STDOUT.dup, STDERR.dup]
|
11
|
+
STDOUT.reopen DEV_NULL
|
12
|
+
STDERR.reopen DEV_NULL
|
13
|
+
system(*(args.flatten))
|
14
|
+
ensure
|
15
|
+
STDOUT.reopen io.first
|
16
|
+
STDERR.reopen io.last
|
17
|
+
$stdout, $stderr = STDOUT, STDERR
|
18
|
+
end
|
19
|
+
|
20
|
+
def journal
|
21
|
+
@journal ||= ::Webby::Journal.new
|
22
|
+
end
|
23
|
+
|
24
|
+
end # module Kernel
|
25
|
+
|
26
|
+
# EOF
|
@@ -0,0 +1,163 @@
|
|
1
|
+
|
2
|
+
class String
|
3
|
+
|
4
|
+
def self.small_words
|
5
|
+
@small_words ||= %w(a an and as at but by en for if in of on or the to v[.]? via vs[.]?)
|
6
|
+
end
|
7
|
+
|
8
|
+
def /( path )
|
9
|
+
::File.join(self, path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def titlecase
|
13
|
+
swrgxp = self.class.small_words.join('|')
|
14
|
+
|
15
|
+
parts = self.split( %r/( [:.;?!][ ] | (?:[ ]|^)["“] )/x )
|
16
|
+
parts.each do |part|
|
17
|
+
part.gsub!(%r/\b[[:alpha:]][[:lower:].'’]*\b/) do |s|
|
18
|
+
s =~ %r/\w+\.\w+/ ? s : s.capitalize
|
19
|
+
end
|
20
|
+
|
21
|
+
# Lowercase the small words
|
22
|
+
part.gsub!(%r/\b(#{swrgxp})\b/i) {|w| w.downcase}
|
23
|
+
|
24
|
+
# If the first word is a small word, then capitalize it
|
25
|
+
part.gsub!(%r/\A([[:punct:]]*)(#{swrgxp})\b/) {$1 + $2.capitalize}
|
26
|
+
|
27
|
+
# If the last word is a small word, then capitalize it
|
28
|
+
part.gsub!(%r/\b(#{swrgxp})([^\w\s]*)\z/) {$1.capitalize + $2}
|
29
|
+
end
|
30
|
+
|
31
|
+
str = parts.join
|
32
|
+
|
33
|
+
# Special cases:
|
34
|
+
str.gsub!(/ V(s?)\. /, ' v\1. ') # "v." and "vs."
|
35
|
+
str.gsub!(/(['’])S\b/, '\1s') # 'S (otherwise you get "the SEC'S decision")
|
36
|
+
str.gsub!(/\b(AT&T|Q&A)\b/i) { |w| w.upcase } # "AT&T" and "Q&A", which get tripped up.
|
37
|
+
|
38
|
+
str
|
39
|
+
end
|
40
|
+
|
41
|
+
# Borrowed from the excellent StringEx library: git://github.com/rsl/stringex.git
|
42
|
+
|
43
|
+
# Create a URI-friendly representation of the string.
|
44
|
+
def to_url
|
45
|
+
remove_formatting.downcase.replace_whitespace("-").collapse("-")
|
46
|
+
end
|
47
|
+
|
48
|
+
# Performs multiple text manipulations. Essentially a shortcut for typing them all. View source
|
49
|
+
# below to see which methods are run.
|
50
|
+
def remove_formatting
|
51
|
+
strip_html_tags.convert_accented_entities.convert_misc_entities.convert_misc_characters.collapse
|
52
|
+
end
|
53
|
+
|
54
|
+
# Removes HTML tags from text. This code is simplified from Tobias Luettke's regular expression
|
55
|
+
# in Typo[http://typosphere.org].
|
56
|
+
def strip_html_tags(leave_whitespace = false)
|
57
|
+
name = /[\w:_-]+/
|
58
|
+
value = /([A-Za-z0-9]+|('[^']*?'|"[^"]*?"))/
|
59
|
+
attr = /(#{name}(\s*=\s*#{value})?)/
|
60
|
+
rx = /<[!\/?\[]?(#{name}|--)(\s+(#{attr}(\s+#{attr})*))?\s*([!\/?\]]+|--)?>/
|
61
|
+
(leave_whitespace) ? gsub(rx, "").strip : gsub(rx, "").gsub(/\s+/, " ").strip
|
62
|
+
end
|
63
|
+
|
64
|
+
# Converts HTML entities into the respective non-accented letters. Examples:
|
65
|
+
#
|
66
|
+
# "á".convert_accented_entities # => "a"
|
67
|
+
# "ç".convert_accented_entities # => "c"
|
68
|
+
# "è".convert_accented_entities # => "e"
|
69
|
+
# "î".convert_accented_entities # => "i"
|
70
|
+
# "ø".convert_accented_entities # => "o"
|
71
|
+
# "ü".convert_accented_entities # => "u"
|
72
|
+
#
|
73
|
+
# Note: This does not do any conversion of Unicode/Ascii accented-characters. For that
|
74
|
+
# functionality please use <tt>to_ascii</tt>.
|
75
|
+
def convert_accented_entities
|
76
|
+
gsub(/&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);/, '\1')
|
77
|
+
end
|
78
|
+
|
79
|
+
# Converts HTML entities (taken from common Textile/RedCloth formattings) into plain text formats.
|
80
|
+
#
|
81
|
+
# Note: This isn't an attempt at complete conversion of HTML entities, just those most likely
|
82
|
+
# to be generated by Textile.
|
83
|
+
def convert_misc_entities
|
84
|
+
dummy = dup
|
85
|
+
{
|
86
|
+
"#822[01]" => "\"",
|
87
|
+
"#821[67]" => "'",
|
88
|
+
"#8230" => "...",
|
89
|
+
"#8211" => "-",
|
90
|
+
"#8212" => "--",
|
91
|
+
"#215" => "x",
|
92
|
+
"gt" => ">",
|
93
|
+
"lt" => "<",
|
94
|
+
"(#8482|trade)" => "(tm)",
|
95
|
+
"(#174|reg)" => "(r)",
|
96
|
+
"(#169|copy)" => "(c)",
|
97
|
+
"(#38|amp)" => "and",
|
98
|
+
"nbsp" => " ",
|
99
|
+
"(#162|cent)" => " cent",
|
100
|
+
"(#163|pound)" => " pound",
|
101
|
+
"(#188|frac14)" => "one fourth",
|
102
|
+
"(#189|frac12)" => "half",
|
103
|
+
"(#190|frac34)" => "three fourths",
|
104
|
+
"(#176|deg)" => " degrees"
|
105
|
+
}.each do |textiled, normal|
|
106
|
+
dummy.gsub!(/&#{textiled};/, normal)
|
107
|
+
end
|
108
|
+
dummy.gsub(/&[^;]+;/, "")
|
109
|
+
end
|
110
|
+
|
111
|
+
# Converts various common plaintext characters to a more URI-friendly representation.
|
112
|
+
# Examples:
|
113
|
+
#
|
114
|
+
# "foo & bar".convert_misc_characters # => "foo and bar"
|
115
|
+
# "Chanel #9".convert_misc_characters # => "Chanel number nine"
|
116
|
+
# "user@host".convert_misc_characters # => "user at host"
|
117
|
+
# "google.com".convert_misc_characters # => "google dot com"
|
118
|
+
# "$10".convert_misc_characters # => "10 dollars"
|
119
|
+
# "*69".convert_misc_characters # => "star 69"
|
120
|
+
# "100%".convert_misc_characters # => "100 percent"
|
121
|
+
# "windows/mac/linux".convert_misc_characters # => "windows slash mac slash linux"
|
122
|
+
#
|
123
|
+
# Note: Because this method will convert any & symbols to the string "and",
|
124
|
+
# you should run any methods which convert HTML entities (convert_html_entities and convert_misc_entities)
|
125
|
+
# before running this method.
|
126
|
+
def convert_misc_characters
|
127
|
+
dummy = dup.gsub(/\.{3,}/, " dot dot dot ") # Catch ellipses before single dot rule!
|
128
|
+
{
|
129
|
+
/\s*&\s*/ => "and",
|
130
|
+
/\s*#/ => "number",
|
131
|
+
/\s*@\s*/ => "at",
|
132
|
+
/(\S|^)\.(\S)/ => '\1 dot \2',
|
133
|
+
/(\s|^)\$(\d*)(\s|$)/ => '\2 dollars',
|
134
|
+
/\s*\*\s*/ => "star",
|
135
|
+
/\s*%\s*/ => "percent",
|
136
|
+
/\s*(\\|\/)\s*/ => "slash",
|
137
|
+
}.each do |found, replaced|
|
138
|
+
replaced = " #{replaced} " unless replaced =~ /\\1/
|
139
|
+
dummy.gsub!(found, replaced)
|
140
|
+
end
|
141
|
+
dummy = dummy.gsub(/(^|\w)'(\w|$)/, '\1\2').gsub(/[\.,:;()\[\]\/\?!\^'"_]/, " ")
|
142
|
+
end
|
143
|
+
|
144
|
+
# Replace runs of whitespace in string. Defaults to a single space but any replacement
|
145
|
+
# string may be specified as an argument. Examples:
|
146
|
+
#
|
147
|
+
# "Foo bar".replace_whitespace # => "Foo bar"
|
148
|
+
# "Foo bar".replace_whitespace("-") # => "Foo-bar"
|
149
|
+
def replace_whitespace(replace = " ")
|
150
|
+
gsub(/\s+/, replace)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Removes specified character from the beginning and/or end of the string and then performs
|
154
|
+
# <tt>String#squeeze(character)</tt>, condensing runs of the character within the string.
|
155
|
+
#
|
156
|
+
# Note: This method has been superceded by ActiveSupport's squish method.
|
157
|
+
def collapse(character = " ")
|
158
|
+
sub(/^#{character}*/, "").sub(/#{character}*$/, "").squeeze(character)
|
159
|
+
end
|
160
|
+
|
161
|
+
end # class String
|
162
|
+
|
163
|
+
# EOF
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Webby
|
2
|
+
module Filters
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Register a handler for a filter
|
7
|
+
def register( filter, &block )
|
8
|
+
_handlers[filter.to_s] = block
|
9
|
+
end
|
10
|
+
|
11
|
+
# Process input through filters
|
12
|
+
def process( renderer, page, input )
|
13
|
+
# Start a new cursor for this page
|
14
|
+
Cursor.new(renderer, page).start_for(input)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Access a filter handler
|
18
|
+
def []( name )
|
19
|
+
_handlers[name]
|
20
|
+
end
|
21
|
+
|
22
|
+
# The registered filter handlers
|
23
|
+
def _handlers
|
24
|
+
@handlers ||= {}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Instances of this class handle processing a set of filters
|
28
|
+
# for a given renderer and page.
|
29
|
+
# Note: The instance is passed as the second argument to filters
|
30
|
+
# that require two parameters and can be used to access
|
31
|
+
# information on the renderer, page, or filters being
|
32
|
+
# processed.
|
33
|
+
class Cursor
|
34
|
+
|
35
|
+
attr_reader :renderer, :page, :filters
|
36
|
+
def initialize(renderer, page)
|
37
|
+
@renderer, @page = renderer, page
|
38
|
+
@filters = Array(page.filter)
|
39
|
+
@log = Logging::Logger[Webby::Renderer]
|
40
|
+
@processed = 0
|
41
|
+
@prev_cursor = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def start_for(input)
|
45
|
+
@prev_cursor = @renderer.instance_variable_get(:@_cursor)
|
46
|
+
@renderer.instance_variable_set(:@_cursor, self)
|
47
|
+
filters.inject(input) do |result, filter|
|
48
|
+
handler = Filters[filter]
|
49
|
+
raise ::Webby::Error, "unknown filter: #{filter.inspect}" if handler.nil?
|
50
|
+
|
51
|
+
args = [result, self][0, handler.arity]
|
52
|
+
_handle(filter, handler, *args)
|
53
|
+
end
|
54
|
+
ensure
|
55
|
+
@renderer.instance_variable_set(:@_cursor, @prev_cursor)
|
56
|
+
end
|
57
|
+
|
58
|
+
# The list of filters yet to be processed
|
59
|
+
def remaining_filters
|
60
|
+
filters[@processed..-1]
|
61
|
+
end
|
62
|
+
|
63
|
+
# The name of the current filter
|
64
|
+
def current_filter
|
65
|
+
filters[@processed]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Process arguments through a single filter
|
69
|
+
def _handle(filter, handler, *args)
|
70
|
+
result = handler.call(*args)
|
71
|
+
@processed += 1
|
72
|
+
result
|
73
|
+
rescue StandardError => err
|
74
|
+
raise ::Webby::Error, "#{filter} filter error: #{err.message.inspect}"
|
75
|
+
end
|
76
|
+
|
77
|
+
end # class Cursor
|
78
|
+
end # class << self
|
79
|
+
|
80
|
+
end # module Filters
|
81
|
+
end # module Webby
|
82
|
+
|
83
|
+
Webby.require_all_libs_relative_to(__FILE__)
|
84
|
+
|
85
|
+
# EOF
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'hpricot'
|
2
|
+
|
3
|
+
module Webby
|
4
|
+
module Filters
|
5
|
+
|
6
|
+
# The BasePath filter is used to rewrite URI paths in HTML documents. This
|
7
|
+
# is useful when the server location of the website is not located at the
|
8
|
+
# root of the webserver (e.g. http://my.site.com/foo/bar).
|
9
|
+
#
|
10
|
+
# The BasePath filter will adjust the URI paths in a given HTML document by
|
11
|
+
# prepending a base path to the URI. This only works for URIs that start
|
12
|
+
# with a leading slash "/". Any other character will exclude the URI from
|
13
|
+
# being modified.
|
14
|
+
#
|
15
|
+
# Assume the user specifies a new URI base in the <tt>Webby.site.base</tt>
|
16
|
+
# property:
|
17
|
+
#
|
18
|
+
# Webby.site.base = '/foo/bar'
|
19
|
+
#
|
20
|
+
# Here is a snippet from some HTML document.
|
21
|
+
#
|
22
|
+
# <a href="/some/other/page.html">Page</a>
|
23
|
+
# <img src="fractal.jpg" alt="a fractal" />
|
24
|
+
#
|
25
|
+
# When run through the BasePath filter, the resulting snippet would look
|
26
|
+
# like this.
|
27
|
+
#
|
28
|
+
# <a href="/foo/bar/some/other/page.html">Page</a>
|
29
|
+
# <img src="fractal.jpg" alt="a fractal" />
|
30
|
+
#
|
31
|
+
# The +href+ attribute of the anchor tag is modified because it started
|
32
|
+
# with a leading slash. The +src+ attribute of the image tag is not
|
33
|
+
# modified because it lacks the leading slash.
|
34
|
+
#
|
35
|
+
class BasePath
|
36
|
+
|
37
|
+
# call-seq:
|
38
|
+
# BasePath.new( html, mode )
|
39
|
+
#
|
40
|
+
# Creates a new BasePath filter that will operate on the given _html_
|
41
|
+
# string. The _mode_ is either 'xml' or 'html' and determines how Hpricot
|
42
|
+
# will handle the parsing of the input string.
|
43
|
+
#
|
44
|
+
def initialize( str, mode )
|
45
|
+
@str = str
|
46
|
+
@mode = mode.downcase.to_sym
|
47
|
+
end
|
48
|
+
|
49
|
+
# call-seq:
|
50
|
+
# filter => html
|
51
|
+
#
|
52
|
+
# Process the original html document passed to the filter when it was
|
53
|
+
# created. The document will be scanned and the basepath for certain
|
54
|
+
# elements will be modified.
|
55
|
+
#
|
56
|
+
# For example, if a document contains the following line:
|
57
|
+
#
|
58
|
+
# <a href="/link/to/another/page.html">Page</a>
|
59
|
+
#
|
60
|
+
# and the user has requested for the base path to be some other directory
|
61
|
+
# on the webserver -- <tt>/some/other/directory</tt>. The result of the
|
62
|
+
# BasePath filter would be:
|
63
|
+
#
|
64
|
+
# <a href="/some/other/directory/link/to/another/page.html">Page</a>
|
65
|
+
#
|
66
|
+
def filter
|
67
|
+
doc = @mode == :xml ? Hpricot.XML(@str) : Hpricot(@str)
|
68
|
+
base_path = ::Webby.site.base
|
69
|
+
attr_rgxp = %r/\[@(\w+)\]$/o
|
70
|
+
sub_rgxp = %r/\A(?=\/)/o
|
71
|
+
|
72
|
+
::Webby.site.xpaths.each do |xpath|
|
73
|
+
@attr_name = nil
|
74
|
+
|
75
|
+
doc.search(xpath).each do |element|
|
76
|
+
@attr_name ||= attr_rgxp.match(xpath)[1]
|
77
|
+
a = element.get_attribute(@attr_name)
|
78
|
+
element.set_attribute(@attr_name, a) if a.sub!(sub_rgxp, base_path)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
doc.to_html
|
83
|
+
end
|
84
|
+
|
85
|
+
end # class BasePath
|
86
|
+
|
87
|
+
# Rewrite base URIs in the input HTML text.
|
88
|
+
#
|
89
|
+
register :basepath do |input, cursor|
|
90
|
+
if ::Webby.site.base then BasePath.new(input, cursor.page.extension).filter
|
91
|
+
else input end
|
92
|
+
end
|
93
|
+
|
94
|
+
end # module Filters
|
95
|
+
end # module Webby
|
96
|
+
|
97
|
+
# EOF
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
# Render text via the Haml library
|
3
|
+
if try_require('haml', 'haml')
|
4
|
+
|
5
|
+
Webby::Filters.register :haml do |input, cursor|
|
6
|
+
opts = ::Webby.site.haml_options.merge(cursor.page.haml_options || {})
|
7
|
+
b = cursor.renderer.get_binding
|
8
|
+
Haml::Engine.new(input, opts).to_html(b)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Otherwise raise an error if the user tries to use haml
|
12
|
+
else
|
13
|
+
Webby::Filters.register :haml do |input, cursor|
|
14
|
+
raise Webby::Error, "'haml' must be installed to use the haml filter"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# EOF
|