Class: Giblish::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/configurator.rb

Overview

configure all parts needed to execute the options specified by the user

Direct Known Subclasses

GitRepoConfigurator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_opts) ⇒ Configurator

config_opts

a Cmdline::Options instance with config info



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/giblish/configurator.rb', line 73

def initialize(config_opts)
  @config_opts = config_opts
  @build_options = {
    pre_builders: [],
    post_builders: [],
    adoc_api_opts: {},
    # add a hash where all values are initiated as empty arrays
    adoc_extensions: Hash.new { |h, k| h[k] = [] }
  }

  # Initiate the doc attribute repo used during 'run-time'
  @doc_attr = DocAttrBuilder.new(
    GiblishDefaultDocAttribs.new
  )

  layout_config = case config_opts
  in format: "html" then HtmlLayoutConfig.new(config_opts)
  in format: "pdf" then PdfLayoutConfig.new(config_opts)
  else
    raise OptionParser::InvalidArgument, "The given cmd line flags are not supported: #{config_opts.inspect}"
  end

  # setup all options from the chosen layout configuration but
  # override doc attributes with ones from the supplied configuration to
  # ensure they have highest pref
  @doc_attr.add_doc_attr_providers(
    *layout_config.docattr_providers, CmdLineDocAttribs.new(config_opts)
  )

  setup_docid(config_opts, @build_options, @doc_attr)
  setup_index_generation(config_opts, @build_options, @doc_attr)

  # setup all pre,post, and build options
  @build_options[:adoc_api_opts] = layout_config.adoc_api_opts
  @build_options[:pre_builders] += layout_config.pre_builders
  @build_options[:post_builders] += layout_config.post_builders
  layout_config.adoc_extensions.each do |type, instance|
    @build_options[:adoc_extensions][type] << instance
  end

  # add copy of asset dirs if options stipulates this
  @build_options[:post_builders] << CopyAssetDirsPostBuild.new(@config_opts) unless @config_opts.copy_asset_folders.nil?
end

Instance Attribute Details

#build_optionsObject (readonly)

Returns the value of attribute build_options.



70
71
72
# File 'lib/giblish/configurator.rb', line 70

def build_options
  @build_options
end

#config_optsObject (readonly)

Returns the value of attribute config_opts.



70
71
72
# File 'lib/giblish/configurator.rb', line 70

def config_opts
  @config_opts
end

#doc_attrObject (readonly)

Returns the value of attribute doc_attr.



70
71
72
# File 'lib/giblish/configurator.rb', line 70

def doc_attr
  @doc_attr
end