webgen 0.5.10 → 0.5.11
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +487 -0
- data/Rakefile +13 -28
- data/VERSION +1 -1
- data/bin/webgen +1 -2
- data/data/webgen/passive_sources/templates/atom_feed.template +1 -0
- data/data/webgen/website_bundles/style/andreas07/src/default.css +2 -2
- data/data/webgen/website_skeleton/config.yaml +22 -5
- data/doc/contentprocessor.template +2 -2
- data/doc/contentprocessor/blocks.page +4 -4
- data/doc/contentprocessor/builder.page +2 -3
- data/doc/contentprocessor/erb.page +1 -1
- data/doc/contentprocessor/erubis.page +5 -5
- data/doc/contentprocessor/fragments.page +5 -4
- data/doc/contentprocessor/haml.page +2 -3
- data/doc/contentprocessor/head.page +16 -6
- data/doc/contentprocessor/kramdown.page +49 -0
- data/doc/contentprocessor/less.page +34 -0
- data/doc/contentprocessor/maruku.page +6 -3
- data/doc/contentprocessor/rdiscount.page +3 -3
- data/doc/contentprocessor/rdoc.page +1 -1
- data/doc/contentprocessor/redcloth.page +1 -1
- data/doc/contentprocessor/sass.page +1 -1
- data/doc/contentprocessor/tags.page +2 -2
- data/doc/contentprocessor/tidy.page +2 -2
- data/doc/extensions.page +1 -2
- data/doc/extensions.template +5 -5
- data/doc/getting_started.page +16 -12
- data/doc/index.page +21 -21
- data/doc/manual.page +109 -61
- data/doc/reference_configuration.page +63 -38
- data/doc/reference_metainfo.page +68 -45
- data/doc/reference_website_styles.page +5 -1
- data/doc/source/filesystem.page +4 -4
- data/doc/source/tararchive.page +4 -4
- data/doc/sourcehandler.template +2 -2
- data/doc/sourcehandler/feed.page +3 -4
- data/doc/sourcehandler/metainfo.page +1 -1
- data/doc/sourcehandler/page.page +3 -3
- data/doc/sourcehandler/sitemap.page +2 -3
- data/doc/sourcehandler/template.page +2 -2
- data/doc/sourcehandler/virtual.page +5 -5
- data/doc/tag.template +1 -1
- data/doc/tag/coderay.page +2 -2
- data/doc/tag/includefile.page +1 -1
- data/doc/tag/langbar.page +4 -1
- data/doc/tag/menu.page +3 -3
- data/doc/tag/relocatable.page +1 -1
- data/doc/upgrading.page +30 -31
- data/doc/webgen_page_format.page +6 -6
- data/lib/webgen/cache.rb +4 -5
- data/lib/webgen/cli/utils.rb +18 -7
- data/lib/webgen/cli/webgui_command.rb +4 -2
- data/lib/webgen/common.rb +10 -0
- data/lib/webgen/configuration.rb +1 -3
- data/lib/webgen/contentprocessor.rb +4 -2
- data/lib/webgen/contentprocessor/blocks.rb +1 -0
- data/lib/webgen/contentprocessor/builder.rb +3 -9
- data/lib/webgen/contentprocessor/erb.rb +3 -9
- data/lib/webgen/contentprocessor/erubis.rb +3 -9
- data/lib/webgen/contentprocessor/haml.rb +10 -11
- data/lib/webgen/contentprocessor/head.rb +64 -0
- data/lib/webgen/contentprocessor/kramdown.rb +26 -0
- data/lib/webgen/contentprocessor/kramdown/html.rb +32 -0
- data/lib/webgen/contentprocessor/less.rb +35 -0
- data/lib/webgen/contentprocessor/maruku.rb +14 -0
- data/lib/webgen/contentprocessor/tags.rb +25 -7
- data/lib/webgen/default_config.rb +9 -3
- data/lib/webgen/node.rb +92 -0
- data/lib/webgen/output.rb +3 -1
- data/lib/webgen/source/resource.rb +2 -1
- data/lib/webgen/source/tararchive.rb +3 -2
- data/lib/webgen/sourcehandler.rb +8 -4
- data/lib/webgen/sourcehandler/base.rb +1 -2
- data/lib/webgen/sourcehandler/feed.rb +1 -1
- data/lib/webgen/sourcehandler/virtual.rb +1 -0
- data/lib/webgen/tag/base.rb +1 -1
- data/lib/webgen/tag/langbar.rb +5 -2
- data/lib/webgen/version.rb +1 -1
- data/lib/webgen/website.rb +7 -8
- data/misc/default.template +1 -1
- data/misc/htmldoc.virtual +13 -1
- data/test/test_contentprocessor.rb +1 -1
- data/test/test_contentprocessor_blocks.rb +16 -1
- data/test/test_contentprocessor_erb.rb +1 -1
- data/test/test_contentprocessor_fragments.rb +1 -1
- data/test/test_contentprocessor_haml.rb +2 -2
- data/test/test_contentprocessor_head.rb +54 -8
- data/test/test_contentprocessor_kramdown.rb +50 -0
- data/test/test_contentprocessor_less.rb +40 -0
- data/test/test_contentprocessor_tags.rb +8 -0
- data/test/test_node.rb +102 -41
- data/test/test_source_tararchive.rb +5 -1
- data/test/test_sourcehandler_feed.rb +5 -2
- data/test/test_sourcehandler_virtual.rb +5 -0
- data/test/test_tag_langbar.rb +2 -3
- metadata +22 -16
- data/lib/webgen/deprecated.rb +0 -87
data/lib/webgen/cli/utils.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require 'facets/ansicode'
|
4
3
|
require 'rbconfig'
|
5
4
|
|
6
|
-
ANSICode.define_ansicolor_method(:lred, '1;31')
|
7
|
-
ANSICode.define_ansicolor_method(:lblue, '1;34')
|
8
|
-
|
9
5
|
module Webgen::CLI
|
10
6
|
|
11
7
|
# Provides methods for other CLI classes for formatting text in a consistent manner.
|
@@ -15,13 +11,28 @@ module Webgen::CLI
|
|
15
11
|
DEFAULT_WIDTH = if Config::CONFIG['host_os'] =~ /mswin|mingw/
|
16
12
|
72
|
17
13
|
else
|
18
|
-
((size = %x{stty size 2>/dev/null}).length > 0
|
14
|
+
((size = %x{stty size 2>/dev/null}).length > 0 && (size = size.split.last.to_i) > 0 ? size : 72) rescue 72
|
19
15
|
end
|
20
16
|
|
17
|
+
module Color
|
18
|
+
|
19
|
+
@@colors = {:bold => [0, 1], :green => [0, 32], :lred => [1, 31], :reset => [0, 0]}
|
20
|
+
|
21
|
+
@@colors.each do |color, values|
|
22
|
+
module_eval <<-EOF
|
23
|
+
def Color.#{color.to_s}(text = nil)
|
24
|
+
"\e[#{values[0]};#{values[1]}m" + (text.nil? ? '' : text + self.reset)
|
25
|
+
end
|
26
|
+
EOF
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
21
32
|
# Used for dynamically formatting the text (setting color, bold face, ...).
|
22
33
|
def self.method_missing(id, text = nil)
|
23
|
-
if USE_ANSI_COLORS &&
|
24
|
-
|
34
|
+
if USE_ANSI_COLORS && Color.respond_to?(id)
|
35
|
+
Color.send(id, text.to_s)
|
25
36
|
else
|
26
37
|
text.to_s
|
27
38
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'webgen/cli'
|
4
|
-
require 'facets/kernel/silence'
|
5
4
|
|
6
5
|
module Webgen::CLI
|
7
6
|
|
@@ -22,7 +21,8 @@ module Webgen::CLI
|
|
22
21
|
$:.unshift File.join(Webgen.data_dir, 'webgui', 'overrides')
|
23
22
|
require 'win32console'
|
24
23
|
$:.shift
|
25
|
-
|
24
|
+
begin
|
25
|
+
oldv, $VERBOSE = $VERBOSE, nil
|
26
26
|
begin
|
27
27
|
require 'ramaze/snippets/object/__dir__'
|
28
28
|
Object.__send__(:include, Ramaze::CoreExtensions::Object)
|
@@ -32,6 +32,8 @@ module Webgen::CLI
|
|
32
32
|
puts "You can install it via 'gem install ramaze --version 2009.04'"
|
33
33
|
return
|
34
34
|
end
|
35
|
+
ensure
|
36
|
+
$VERBOSE = oldv
|
35
37
|
end
|
36
38
|
def Ramaze.shutdown; # :nodoc:
|
37
39
|
end
|
data/lib/webgen/common.rb
CHANGED
@@ -7,6 +7,16 @@ module Webgen
|
|
7
7
|
|
8
8
|
autoload :Sitemap, 'webgen/common/sitemap'
|
9
9
|
|
10
|
+
# Return the constant object for the given absolute constant +name+.
|
11
|
+
def self.const_for_name(name)
|
12
|
+
name.split('::').inject(Object) {|b,n| b.const_get(n)}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return the error line by inspecting the backtrace of the given +error+ instance.
|
16
|
+
def self.error_line(error)
|
17
|
+
(error.is_a?(::SyntaxError) ? error.message : error.backtrace[0]).scan(/:(\d+)/).first.first.to_i rescue nil
|
18
|
+
end
|
19
|
+
|
10
20
|
end
|
11
21
|
|
12
22
|
end
|
data/lib/webgen/configuration.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require 'facets/symbol/to_proc'
|
4
|
-
|
5
3
|
module Webgen
|
6
4
|
|
7
5
|
# Stores the configuration for a webgen website.
|
@@ -105,7 +103,7 @@ module Webgen
|
|
105
103
|
# Complete +sh_name+ by checking if a source handler called
|
106
104
|
# <tt>Webgen::SourceHandler::SH_NAME</tt> exists.
|
107
105
|
def complete_source_handler_name(sh_name)
|
108
|
-
(Webgen::SourceHandler.constants.map
|
106
|
+
(Webgen::SourceHandler.constants.map {|c| c.to_s}.include?(sh_name) ? 'Webgen::SourceHandler::' + sh_name : sh_name)
|
109
107
|
end
|
110
108
|
private :complete_source_handler_name
|
111
109
|
|
@@ -56,9 +56,9 @@ module Webgen
|
|
56
56
|
#
|
57
57
|
# end
|
58
58
|
#
|
59
|
-
# WebsiteAccess.website.config['contentprocessor.map']['replacer'] = 'SampleProcessor'
|
59
|
+
# Webgen::WebsiteAccess.website.config['contentprocessor.map']['replacer'] = 'SampleProcessor'
|
60
60
|
# # Or one could equally write
|
61
|
-
# # WebsiteAccess.website.config['contentprocessor.map']['replacer'] = ['SampleProcessor', :text]
|
61
|
+
# # Webgen::WebsiteAccess.website.config['contentprocessor.map']['replacer'] = ['SampleProcessor', :text]
|
62
62
|
#
|
63
63
|
module ContentProcessor
|
64
64
|
|
@@ -77,6 +77,8 @@ module Webgen
|
|
77
77
|
autoload :Head, 'webgen/contentprocessor/head'
|
78
78
|
autoload :Tidy, 'webgen/contentprocessor/tidy'
|
79
79
|
autoload :Xmllint, 'webgen/contentprocessor/xmllint'
|
80
|
+
autoload :Kramdown, 'webgen/contentprocessor/kramdown'
|
81
|
+
autoload :Less, 'webgen/contentprocessor/less'
|
80
82
|
|
81
83
|
# Return the list of all available content processors.
|
82
84
|
def self.list
|
@@ -45,6 +45,7 @@ module Webgen::ContentProcessor
|
|
45
45
|
used_chain = (context[:chain].length > 1 ? context[:chain][1..-1] : context[:chain]).dup
|
46
46
|
elsif options[:chain].kind_of?(Array)
|
47
47
|
used_chain = options[:chain]
|
48
|
+
dest_node = context.content_node
|
48
49
|
else
|
49
50
|
paths = options[:chain].split(';')
|
50
51
|
used_chain = paths.collect do |path|
|
@@ -1,23 +1,18 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'webgen/common'
|
4
|
+
|
3
5
|
module Webgen::ContentProcessor
|
4
6
|
|
5
7
|
# Processes content that is valid Ruby to build an XML tree. This is done by using the +builder+
|
6
8
|
# library.
|
7
9
|
class Builder
|
8
10
|
|
9
|
-
include Deprecated
|
10
|
-
|
11
11
|
# Process the content of +context+ which needs to be valid Ruby code. The special variable +xml+
|
12
12
|
# should be used to construct the XML content.
|
13
13
|
def call(context)
|
14
14
|
require 'builder'
|
15
15
|
|
16
|
-
website = deprecate('website', 'context.website', context.website)
|
17
|
-
node = deprecate('node', 'context.node', context.content_node)
|
18
|
-
ref_node = deprecate('ref_node', 'context.ref_node', context.ref_node)
|
19
|
-
dest_node = deprecate('dest_node', 'context.dest_node', context.dest_node)
|
20
|
-
|
21
16
|
xml = ::Builder::XmlMarkup.new(:indent => 2)
|
22
17
|
eval(context.content, binding, context.ref_node.alcn)
|
23
18
|
context.content = xml.target!
|
@@ -25,8 +20,7 @@ module Webgen::ContentProcessor
|
|
25
20
|
rescue LoadError
|
26
21
|
raise Webgen::LoadError.new('builder', self.class.name, context.dest_node.alcn, 'builder')
|
27
22
|
rescue Exception => e
|
28
|
-
|
29
|
-
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, line)
|
23
|
+
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, Webgen::Common.error_line(e))
|
30
24
|
end
|
31
25
|
|
32
26
|
end
|
@@ -1,29 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'webgen/common'
|
4
|
+
|
3
5
|
module Webgen::ContentProcessor
|
4
6
|
|
5
7
|
# Processes embedded Ruby statements.
|
6
8
|
class Erb
|
7
9
|
|
8
|
-
include Deprecated
|
9
|
-
|
10
10
|
# Process the Ruby statements embedded in the content of +context+.
|
11
11
|
def call(context)
|
12
12
|
require 'erb'
|
13
13
|
extend(ERB::Util)
|
14
14
|
|
15
|
-
website = deprecate('website', 'context.website', context.website)
|
16
|
-
node = deprecate('node', 'context.node', context.content_node)
|
17
|
-
ref_node = deprecate('ref_node', 'context.ref_node', context.ref_node)
|
18
|
-
dest_node = deprecate('dest_node', 'context.dest_node', context.dest_node)
|
19
|
-
|
20
15
|
erb = ERB.new(context.content)
|
21
16
|
erb.filename = context.ref_node.alcn
|
22
17
|
context.content = erb.result(binding)
|
23
18
|
context
|
24
19
|
rescue Exception => e
|
25
|
-
|
26
|
-
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, line)
|
20
|
+
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, Webgen::Common.error_line(e))
|
27
21
|
end
|
28
22
|
|
29
23
|
end
|
@@ -1,23 +1,18 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'webgen/common'
|
4
|
+
|
3
5
|
module Webgen::ContentProcessor
|
4
6
|
|
5
7
|
# Processes embedded Ruby statements with the +erubis+ library.
|
6
8
|
class Erubis
|
7
9
|
|
8
|
-
include Deprecated
|
9
|
-
|
10
10
|
# Process the Ruby statements embedded in the content of +context+.
|
11
11
|
def call(context)
|
12
12
|
require 'erubis'
|
13
13
|
# including Erubis because of problem with resolving Erubis::XmlHelper et al
|
14
14
|
self.class.class_eval "include ::Erubis"
|
15
15
|
|
16
|
-
website = deprecate('website', 'context.website', context.website)
|
17
|
-
node = deprecate('node', 'context.node', context.content_node)
|
18
|
-
ref_node = deprecate('ref_node', 'context.ref_node', context.ref_node)
|
19
|
-
dest_node = deprecate('dest_node', 'context.dest_node', context.dest_node)
|
20
|
-
|
21
16
|
options = context.website.config['contentprocessor.erubis.options']
|
22
17
|
if context[:block]
|
23
18
|
use_pi = context[:block].options['erubis_use_pi']
|
@@ -35,8 +30,7 @@ module Webgen::ContentProcessor
|
|
35
30
|
rescue LoadError
|
36
31
|
raise Webgen::LoadError.new('erubis', self.class.name, context.dest_node.alcn, 'erubis')
|
37
32
|
rescue Exception => e
|
38
|
-
|
39
|
-
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, line)
|
33
|
+
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, Webgen::Common.error_line(e))
|
40
34
|
end
|
41
35
|
|
42
36
|
end
|
@@ -1,32 +1,31 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'webgen/common'
|
4
|
+
|
3
5
|
module Webgen::ContentProcessor
|
4
6
|
|
5
7
|
# Processes content in Haml markup using the +haml+ library.
|
6
8
|
class Haml
|
7
9
|
|
8
|
-
include Deprecated
|
9
|
-
|
10
10
|
# Convert the content in +haml+ markup to HTML.
|
11
11
|
def call(context)
|
12
12
|
require 'haml'
|
13
13
|
|
14
|
-
locals = {
|
15
|
-
:context => context,
|
16
|
-
:website => deprecate('website', 'context.website', context.website),
|
17
|
-
:node => deprecate('node', 'context.node', context.content_node),
|
18
|
-
:ref_node => deprecate('ref_node', 'context.ref_node', context.ref_node),
|
19
|
-
:dest_node => deprecate('dest_node', 'context.dest_node', context.dest_node)
|
20
|
-
}
|
14
|
+
locals = {:context => context}
|
21
15
|
context.content = ::Haml::Engine.new(context.content, :filename => context.ref_node.alcn).
|
22
16
|
render(Object.new, locals)
|
23
17
|
context
|
24
18
|
rescue LoadError
|
25
19
|
raise Webgen::LoadError.new('haml', self.class.name, context.dest_node.alcn, 'haml')
|
26
20
|
rescue ::Haml::Error => e
|
27
|
-
|
21
|
+
line = if e.line
|
22
|
+
e.line + 1
|
23
|
+
else
|
24
|
+
Webgen::Common.error_line(e)
|
25
|
+
end
|
26
|
+
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, line)
|
28
27
|
rescue Exception => e
|
29
|
-
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn)
|
28
|
+
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, Webgen::Common.error_line(e))
|
30
29
|
end
|
31
30
|
|
32
31
|
end
|
@@ -29,11 +29,16 @@ module Webgen::ContentProcessor
|
|
29
29
|
|
30
30
|
HTML_HEAD_END_RE = /<\/head\s*>/i #:nodoc:
|
31
31
|
|
32
|
+
LINK_DOCUMENT_ATTRS = {'type' => 'text/html'} #:nodoc:
|
33
|
+
LINK_DOCUMENT_TYPES = %w{start next prev contents index glossary chapter section subsection appendix help} #:nodoc:
|
34
|
+
|
32
35
|
# Insert the additional header information.
|
33
36
|
def call(context)
|
34
37
|
require 'erb'
|
35
38
|
context.content.sub!(HTML_HEAD_END_RE) do |match|
|
36
39
|
result = ''
|
40
|
+
|
41
|
+
# add content set programmatically
|
37
42
|
if context.persistent[:cp_head].kind_of?(Hash)
|
38
43
|
context.persistent[:cp_head][:js_file].uniq.each do |js_file|
|
39
44
|
result += "\n<script type=\"text/javascript\" src=\"#{js_file}\"></script>"
|
@@ -54,6 +59,65 @@ module Webgen::ContentProcessor
|
|
54
59
|
((context.persistent[:cp_head] || {})[:meta] || {}).merge(context.node['meta'] || {}).each do |name, content|
|
55
60
|
result += "\n<meta name=\"#{ERB::Util.h(name)}\" content=\"#{ERB::Util.h(content)}\" />"
|
56
61
|
end
|
62
|
+
|
63
|
+
# add links to other languages of same page
|
64
|
+
context.dest_node.tree.node_access[:acn][context.dest_node.acn].
|
65
|
+
select {|n| n.alcn != context.dest_node.alcn}.each do |node|
|
66
|
+
context.dest_node.node_info[:used_meta_info_nodes] << node.alcn
|
67
|
+
result += "\n<link type=\"text/html\" rel=\"alternate\" hreflang=\"#{node.lang}\" "
|
68
|
+
result += "href=\"#{context.dest_node.route_to(node)}\" "
|
69
|
+
if node['title'] && !node['title'].empty?
|
70
|
+
result += "lang=\"#{node.lang}\" title=\"#{ERB::Util.h(node['title'])}\" "
|
71
|
+
end
|
72
|
+
result += "/>"
|
73
|
+
end
|
74
|
+
|
75
|
+
link = (context.node['link'] || {}).dup
|
76
|
+
|
77
|
+
handle_files = lambda do |files|
|
78
|
+
[files].flatten.compact.collect do |file|
|
79
|
+
if !Webgen::Node.url(file, false).absolute?
|
80
|
+
file = context.node.resolve(file, context.dest_node.lang)
|
81
|
+
if file
|
82
|
+
context.dest_node.node_info[:used_meta_info_nodes] << file.alcn
|
83
|
+
file = context.dest_node.route_to(file)
|
84
|
+
else
|
85
|
+
log(:error) { "Could not resolve path '#{file}' used in 'link' meta information in <#{context.node.alcn}>" }
|
86
|
+
context.dest_node.flag(:dirty)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
file
|
90
|
+
end.compact
|
91
|
+
end
|
92
|
+
|
93
|
+
# Add user defined javascript and CSS links
|
94
|
+
handle_files.call(link.delete('javascript')).each do |file|
|
95
|
+
result += "\n<script type=\"text/javascript\" src=\"#{file}\"></script>"
|
96
|
+
end
|
97
|
+
handle_files.call(link.delete('css')).each do |file|
|
98
|
+
result += "\n<link rel=\"stylesheet\" href=\"#{file}\" type=\"text/css\" />"
|
99
|
+
end
|
100
|
+
|
101
|
+
# add generic links specified via the +link+ meta information
|
102
|
+
link.sort.each do |link_type, vals|
|
103
|
+
link_type = link_type.downcase
|
104
|
+
[vals.dup].flatten.each do |val|
|
105
|
+
val = {'href' => val} if val.kind_of?(String)
|
106
|
+
val['rel'] ||= link_type
|
107
|
+
val = LINK_DOCUMENT_ATTRS.merge(val) if LINK_DOCUMENT_TYPES.include?(link_type)
|
108
|
+
if href = val.delete('href')
|
109
|
+
href = handle_files.call(href).first
|
110
|
+
else
|
111
|
+
log(:error) { "No link target specified for link type '#{link_type}' in 'link' meta information in <#{context.node.alcn}>" }
|
112
|
+
end
|
113
|
+
if href
|
114
|
+
s = "\n<link href=\"#{href}\" "
|
115
|
+
val.sort.each {|k,v| s += "#{k}=\"#{ERB::Util.h(v)}\" "}
|
116
|
+
result += s + "/>"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
57
121
|
result + match
|
58
122
|
end
|
59
123
|
context
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Webgen::ContentProcessor
|
4
|
+
|
5
|
+
# Processes content in kramdown format (based on Markdown) using the +kramdown+ library.
|
6
|
+
class Kramdown
|
7
|
+
|
8
|
+
include Webgen::Loggable
|
9
|
+
|
10
|
+
# Convert the content in +context+ to HTML.
|
11
|
+
def call(context)
|
12
|
+
require 'kramdown'
|
13
|
+
require 'webgen/contentprocessor/kramdown/html'
|
14
|
+
doc = ::Kramdown::Document.new(context.content, context.website.config['contentprocessor.kramdown.options'])
|
15
|
+
context.content = KramdownHtmlConverter.convert(doc, context)
|
16
|
+
doc.warnings.each do |warn|
|
17
|
+
log(:warn) { "Warning while parsing <#{context.ref_node.alcn}> with kramdown: #{warn}" }
|
18
|
+
end
|
19
|
+
context
|
20
|
+
rescue LoadError
|
21
|
+
raise Webgen::LoadError.new('kramdown', self.class.name, context.dest_node.alcn, 'kramdown')
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'kramdown'
|
4
|
+
|
5
|
+
module Webgen::ContentProcessor
|
6
|
+
|
7
|
+
class KramdownHtmlConverter < ::Kramdown::Converter::Html
|
8
|
+
|
9
|
+
def initialize(doc, context) #:nodoc:
|
10
|
+
super(doc)
|
11
|
+
@context = context
|
12
|
+
@do_convert = context.website.config['contentprocessor.kramdown.handle_links']
|
13
|
+
end
|
14
|
+
|
15
|
+
# Convert the Kramdown document +doc+ to HTML using the webgen +context+ object.
|
16
|
+
def self.convert(doc, context)
|
17
|
+
new(doc, context).convert(doc.tree)
|
18
|
+
end
|
19
|
+
|
20
|
+
def convert_a(el, indent, opts)
|
21
|
+
el.options[:attr]['href'] = @context.tag('relocatable', {'path' => el.options[:attr]['href']}) if @do_convert
|
22
|
+
"<a#{options_for_element(el)}>#{inner(el, indent, opts)}</a>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def convert_img(el, indent, opts)
|
26
|
+
el.options[:attr]['src'] = @context.tag('relocatable', {'path' => el.options[:attr]['src']}) if @do_convert
|
27
|
+
"<img#{options_for_element(el)} />"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Webgen::ContentProcessor
|
4
|
+
|
5
|
+
# Generates valid CSS from CSS-like input, supporting variables, nesting and mixins.
|
6
|
+
class Less
|
7
|
+
|
8
|
+
include Webgen::Loggable
|
9
|
+
|
10
|
+
# Convert the content in +context+ to valid CSS.
|
11
|
+
def call(context)
|
12
|
+
require 'less'
|
13
|
+
context.content = ::Less.parse(context.content)
|
14
|
+
context
|
15
|
+
rescue ::Less::SyntaxError => e
|
16
|
+
line = e.message.scan(/on line (\d+):/).first.first.to_i rescue nil
|
17
|
+
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, line)
|
18
|
+
rescue ::Less::MixedUnitsError => e
|
19
|
+
raise Webgen::RenderError.new("Can't mix different units together: #{e}",
|
20
|
+
self.class.name, context.dest_node.alcn, context.ref_node.alcn)
|
21
|
+
rescue ::Less::VariableNameError => e
|
22
|
+
raise Webgen::RenderError.new("Variable name is undefined: #{e}",
|
23
|
+
self.class.name, context.dest_node.alcn, context.ref_node.alcn)
|
24
|
+
rescue ::Less::MixinNameError => e
|
25
|
+
raise Webgen::RenderError.new("Mixin name is undefined: #{e}",
|
26
|
+
self.class.name, context.dest_node.alcn, context.ref_node.alcn)
|
27
|
+
rescue ::Less::ImportError => e
|
28
|
+
raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn)
|
29
|
+
rescue LoadError
|
30
|
+
raise Webgen::LoadError.new('less', self.class.name, context.dest_node.alcn, 'less')
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|