Class: Hologram::DocBuilder
- Inherits:
-
Object
- Object
- Hologram::DocBuilder
- Defined in:
- lib/hologram/doc_builder.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#config_yml ⇒ Object
Returns the value of attribute config_yml.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#doc_assets_dir ⇒ Object
readonly
Returns the value of attribute doc_assets_dir.
-
#doc_blocks ⇒ Object
Returns the value of attribute doc_blocks.
-
#documentation_assets ⇒ Object
Returns the value of attribute documentation_assets.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#footer_erb ⇒ Object
readonly
Returns the value of attribute footer_erb.
-
#header_erb ⇒ Object
readonly
Returns the value of attribute header_erb.
-
#index ⇒ Object
Returns the value of attribute index.
-
#input_dir ⇒ Object
readonly
Returns the value of attribute input_dir.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(options) ⇒ DocBuilder
constructor
A new instance of DocBuilder.
- #is_valid? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ DocBuilder
Returns a new instance of DocBuilder.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hologram/doc_builder.rb', line 38 def initialize() @pages = {} @errors = [] @dependencies = .fetch('dependencies', []) @index = ['index'] @base_path = .fetch('base_path', Dir.pwd) @renderer = .fetch('renderer', MarkdownRenderer) @source = ['source'] @destination = ['destination'] @documentation_assets = ['documentation_assets'] @config_yml = ['config_yml'] end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def base_path @base_path end |
#config_yml ⇒ Object
Returns the value of attribute config_yml.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def config_yml @config_yml end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def dependencies @dependencies end |
#destination ⇒ Object
Returns the value of attribute destination.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def destination @destination end |
#doc_assets_dir ⇒ Object (readonly)
Returns the value of attribute doc_assets_dir.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def doc_assets_dir @doc_assets_dir end |
#doc_blocks ⇒ Object
Returns the value of attribute doc_blocks.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def doc_blocks @doc_blocks end |
#documentation_assets ⇒ Object
Returns the value of attribute documentation_assets.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def documentation_assets @documentation_assets end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/hologram/doc_builder.rb', line 4 def errors @errors end |
#footer_erb ⇒ Object (readonly)
Returns the value of attribute footer_erb.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def @footer_erb end |
#header_erb ⇒ Object (readonly)
Returns the value of attribute header_erb.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def header_erb @header_erb end |
#index ⇒ Object
Returns the value of attribute index.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def index @index end |
#input_dir ⇒ Object (readonly)
Returns the value of attribute input_dir.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def input_dir @input_dir end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def output_dir @output_dir end |
#pages ⇒ Object
Returns the value of attribute pages.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def pages @pages end |
#renderer ⇒ Object
Returns the value of attribute renderer.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def renderer @renderer end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/hologram/doc_builder.rb', line 3 def source @source end |
Class Method Details
.from_yaml(yaml_file) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hologram/doc_builder.rb', line 7 def self.from_yaml(yaml_file) #Change dir so that our paths are relative to the config file base_path = Pathname.new(yaml_file) yaml_file = base_path.realpath.to_s Dir.chdir(base_path.dirname) config = YAML::load_file(yaml_file) raise SyntaxError if !config.is_a? Hash new(config.merge( 'config_yml' => config, 'base_path' => Pathname.new(yaml_file).dirname, 'renderer' => Utils.get_markdown_renderer(config['custom_markdown']) )) rescue SyntaxError, ArgumentError, Psych::SyntaxError raise SyntaxError, "Could not load config file, check the syntax or try 'hologram init' to get started" end |
.setup_dir ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hologram/doc_builder.rb', line 27 def self.setup_dir if File.exists?("hologram_config.yml") DisplayMessage.warning("Cowardly refusing to overwrite existing hologram_config.yml") return end FileUtils.cp_r INIT_TEMPLATE_FILES, Dir.pwd new_files = ["hologram_config.yml", "doc_assets/", "doc_assets/_header.html", "doc_assets/_footer.html"] DisplayMessage.created(new_files) end |
Instance Method Details
#build ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hologram/doc_builder.rb', line 51 def build set_dirs return false if !is_valid? current_path = Dir.pwd Dir.chdir(base_path) # Create the output directory if it doesn't exist if !output_dir FileUtils.mkdir_p(destination) set_dirs #need to reset output_dir post-creation for build_docs. end # the real work happens here. build_docs Dir.chdir(current_path) DisplayMessage.success("Build completed. (-: ") true end |
#is_valid? ⇒ Boolean
70 71 72 73 74 75 76 77 78 |
# File 'lib/hologram/doc_builder.rb', line 70 def is_valid? errors.clear set_dirs errors << "No source directory specified in the config file" if !source errors << "No destination directory specified in the config" if !destination errors << "No documentation assets directory specified" if !documentation_assets errors << "Can not read source directory (#{source}), does it exist?" if source && !input_dir errors.empty? end |