Class: Jekyll::Converters::DyndocConverter

Inherits:
Converter
  • Object
show all
Defined in:
lib/jekyll-dyndoc.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DyndocConverter

Returns a new instance of DyndocConverter.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll-dyndoc.rb', line 9

def initialize(config)
  @config = config
  config['dyndoc'] ||= 'dyndoc-server'
  dyndoc_ext = (config['dyndoc_ext'] ||= 'dyn')
  config['dyndoc_ext_re'] = Regexp.new("\.(#{dyndoc_ext.tr ',', '|'})$", Regexp::IGNORECASE)
  config['dyndoc_page_attribute_prefix'] ||= 'page'
  # unless (dyndoc_config = (config['dyndoc'] ||= {})).frozen?
  #   # NOTE convert keys to symbols
  #   dyndoc_config.keys.each do |key|
  #     dyndoc_config[key.to_sym] = dyndoc_config.delete(key)
  #   end
  #   dyndoc_config[:safe] ||= 'safe'
  #   (dyndoc_config[:attributes] ||= []).tap do |attributes|
  #     attributes.unshift('notitle', 'hardbreaks', 'idprefix', 'idseparator=-', 'linkattrs')
  #     attributes.concat(IMPLICIT_ATTRIBUTES)
  #   end
  #   dyndoc_config.freeze
  # end
end

Instance Method Details

#convert(content) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jekyll-dyndoc.rb', line 56

def convert(content)
  setup
  p [:config,@config]
  case @config['dyndoc']
  when 'dyndoc'
    res=Dyndoc.convert(content, @config['dyndoc'])
    p [:res,res]
    res || ""
  when 'dyndoc-server'
    p [:content,content]
    res=Dyndoc.cli_convert(content, @config['dyndoc'])
    p [:res,res]
    res || ""
  else
    warn 'Unknown Dyndoc converter. Passing through raw content.'
    content
  end
end

#matches(ext) ⇒ Object



48
49
50
# File 'lib/jekyll-dyndoc.rb', line 48

def matches(ext)
  ext =~ @config['dyndoc_ext_re']
end

#output_ext(ext) ⇒ Object



52
53
54
# File 'lib/jekyll-dyndoc.rb', line 52

def output_ext(ext)
  '.html'
end

#setupObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jekyll-dyndoc.rb', line 29

def setup
  return if @setup
  @setup = true
  case @config['dyndoc']
  when 'dyndoc','dyndoc-server'
    begin
      require 'dyndoc-convert' unless defined? ::Dyndoc
    rescue LoadError
      STDERR.puts 'You are missing a library required to convert Dyndoc files. Please run:'
      STDERR.puts '  $ [sudo] gem install dyndoc-ruby'
      raise FatalException.new('Missing dependency: dyndoc')
    end
  else
    STDERR.puts "Invalid Dyndoc processor: #{@config['dyndoc']}"
    STDERR.puts '  Valid options are [ dyndoc ]'
    raise FatalException.new("Invalid Dyndoc processor: #{@config['dyndoc']}")
  end
end