diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command.rb | 19 | ||||
| -rw-r--r-- | lib/html_converter.rb | 16 | ||||
| -rw-r--r-- | lib/parser.rb | 4 |
3 files changed, 35 insertions, 4 deletions
diff --git a/lib/command.rb b/lib/command.rb index 81692b3..5662eec 100644 --- a/lib/command.rb +++ b/lib/command.rb @@ -4,9 +4,11 @@ module NulDoc @config = config @content_dir = @config[:content_dir] @dest_dir = @config[:dest_dir] + @static_dir = @config[:static_dir] @template_dir = @config[:template_dir] @parser = NulDoc::Parser.new( { + 'stylesheets' => stylesheets, 'author' => @config[:author], 'site-copyright-year' => @config[:site_copyright_year], 'site-name' => @config[:site_name], @@ -43,7 +45,7 @@ module NulDoc end def parse_posts(post_file_paths) - post_file_paths.map { @parser.parse_file(_1) } + post_file_paths.map { @parser.parse_file(_1, 'post') } end def output_posts(posts) @@ -92,8 +94,9 @@ module NulDoc end def build_tag_doc(tag, posts) - erb = ERB.new(File.read(@template_dir + '/tag.html.erb')) + erb = ERB.new(File.read(@template_dir + '/tag.html.erb'), trim_mode: '<>') erb.result_with_hash({ + stylesheets: stylesheets, tag: tag, posts: posts, author: @config[:author], @@ -124,8 +127,9 @@ module NulDoc end def build_posts_list_doc(posts) - erb = ERB.new(File.read(@template_dir + '/posts_list.html.erb')) + erb = ERB.new(File.read(@template_dir + '/posts_list.html.erb'), trim_mode: '<>') erb.result_with_hash({ + stylesheets: stylesheets, posts: posts.reverse, author: @config[:author], site_copyright_year: @config[:site_copyright_year], @@ -148,5 +152,14 @@ module NulDoc f.puts(html) end end + + def stylesheets + stylesheet_file_names = %w[hl.css style.css custom.css] + stylesheet_file_names.map {|ss_file_name| + ss_file_path = "#{@static_dir}/#{ss_file_name}" + hash = Digest::MD5.file(ss_file_path).hexdigest + "/#{ss_file_name}?#{hash}" + } + end end end diff --git a/lib/html_converter.rb b/lib/html_converter.rb new file mode 100644 index 0000000..126d72a --- /dev/null +++ b/lib/html_converter.rb @@ -0,0 +1,16 @@ +module NulDoc + class HTMLConverter < (Asciidoctor::Converter.for 'html5') + register_for 'html5' + + def initialize(backend, opts) + super + @template_dir = opts[:template_dirs].first + end + + def convert_document(node) + template_file_name = "document__#{node.attr('document-type')}.html.erb" + erb = Tilt::ERBTemplate.new("#{@template_dir}/#{template_file_name}") + erb.render(node, {}) + end + end +end diff --git a/lib/parser.rb b/lib/parser.rb index 8ae3303..e644dc6 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -6,7 +6,7 @@ module NulDoc @template_dir = template_dir end - def parse_file(file_path) + def parse_file(file_path, document_type) Asciidoctor.load_file( file_path, backend: :html5, @@ -15,9 +15,11 @@ module NulDoc safe: :unsafe, template_dirs: [@template_dir], template_engine: 'erb', + template_engine_options: { erb: { trim: '<>' } }, attributes: @common_attributes.merge({ 'source-file-path' => file_path, 'href' => file_path.sub(@content_dir, '').sub('.adoc', '/'), + 'document-type' => document_type, }), extension_registry: Asciidoctor::Extensions.create do tree_processor Nuldoc::Extensions::RevisionHistoryProcessor |
