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, extra_args = []) ⇒ DocBuilder
constructor
A new instance of DocBuilder.
- #is_valid? ⇒ Boolean
Constructor Details
#initialize(options, extra_args = []) ⇒ DocBuilder
Returns a new instance of DocBuilder.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hologram/doc_builder.rb', line 50 def initialize(, extra_args = []) @pages = {} @errors = [] @dependencies = .fetch('dependencies', nil) || [] @index = ['index'] @base_path = .fetch('base_path', Dir.pwd) @renderer = .fetch('renderer', MarkdownRenderer) @source = Array(['source']) @destination = ['destination'] @documentation_assets = ['documentation_assets'] @config_yml = ['config_yml'] @plugins = Plugins.new(.fetch('config_yml', {}), extra_args) @nav_level = ['nav_level'] || 'page' @exit_on_warnings = ['exit_on_warnings'] @code_example_templates = ['code_example_templates'] @code_example_renderers = ['code_example_renderers'] @custom_extensions = Array(['custom_extensions']) @ignore_paths = .fetch('ignore_paths', []) if @exit_on_warnings DisplayMessage.exit_on_warnings! end end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def base_path @base_path end |
#config_yml ⇒ Object
Returns the value of attribute config_yml.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def config_yml @config_yml end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def dependencies @dependencies end |
#destination ⇒ Object
Returns the value of attribute destination.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def destination @destination end |
#doc_assets_dir ⇒ Object (readonly)
Returns the value of attribute doc_assets_dir.
7 8 9 |
# File 'lib/hologram/doc_builder.rb', line 7 def doc_assets_dir @doc_assets_dir end |
#doc_blocks ⇒ Object
Returns the value of attribute doc_blocks.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def doc_blocks @doc_blocks end |
#documentation_assets ⇒ Object
Returns the value of attribute documentation_assets.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def documentation_assets @documentation_assets end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/hologram/doc_builder.rb', line 6 def errors @errors end |
#footer_erb ⇒ Object (readonly)
Returns the value of attribute footer_erb.
7 8 9 |
# File 'lib/hologram/doc_builder.rb', line 7 def @footer_erb end |
#header_erb ⇒ Object (readonly)
Returns the value of attribute header_erb.
7 8 9 |
# File 'lib/hologram/doc_builder.rb', line 7 def header_erb @header_erb end |
#index ⇒ Object
Returns the value of attribute index.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def index @index end |
#input_dir ⇒ Object (readonly)
Returns the value of attribute input_dir.
7 8 9 |
# File 'lib/hologram/doc_builder.rb', line 7 def input_dir @input_dir end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
7 8 9 |
# File 'lib/hologram/doc_builder.rb', line 7 def output_dir @output_dir end |
#pages ⇒ Object
Returns the value of attribute pages.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def pages @pages end |
#renderer ⇒ Object
Returns the value of attribute renderer.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def renderer @renderer end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/hologram/doc_builder.rb', line 5 def source @source end |
Class Method Details
.from_yaml(yaml_file, extra_args = []) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hologram/doc_builder.rb', line 9 def self.from_yaml(yaml_file, extra_args = []) #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']) ), extra_args) 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hologram/doc_builder.rb', line 29 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", "code_example_templates/", "code_example_templates/markdown_example_template.html.erb", "code_example_templates/markdown_table_template.html.erb", "code_example_templates/js_example_template.html.erb", "code_example_templates/jsx_example_template.html.erb", ] DisplayMessage.created(new_files) end |
Instance Method Details
#build ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hologram/doc_builder.rb', line 74 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
93 94 95 96 97 98 99 100 101 |
# File 'lib/hologram/doc_builder.rb', line 93 def is_valid? errors.clear set_dirs validate_source validate_destination validate_document_assets errors.empty? end |