Class: Quarto::Generator

Inherits:
Object
  • Object
show all
Includes:
UrlHelper
Defined in:
lib/quarto/generator.rb

Overview

This class responds to all the directives that are available for use within a generate.rb file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UrlHelper

#abs_path, #abs_url, included, #link_to, #relative_path, #url_for, #url_for_with_element_wrapper, #urlize

Constructor Details

#initialize(project_path, options = {}) ⇒ Generator

Options:

  • :console_output - Boolean. If true, the generator will print what it’s currently doing.

  • :console - By default, console messages will be printed to stdout. You can override this by passing in an object that responds to puts.

Raises:

  • (ArgumentError)


70
71
72
73
74
75
76
77
# File 'lib/quarto/generator.rb', line 70

def initialize(project_path, options = {})
  raise ArgumentError, "Expected string, but got #{project_path.inspect}" unless project_path.is_a?(String) and !project_path.empty?
  raise ArgumentError, "Project path #{project_path} doesn't exist" unless File.exists?(project_path)
  @project_path = project_path
  @output_path = project_path + '/output'
  @options = {:console_output => true, :console => Kernel}.merge(options)
  @console = @options[:console]
end

Instance Attribute Details

#default_layoutObject

Sets the name of the default layout file in the layouts directory. If default_layout isn’t specified, the default layout is the first file matching default.*.



51
52
53
# File 'lib/quarto/generator.rb', line 51

def default_layout
  @default_layout
end

#output_pathObject (readonly)

:nodoc:



91
92
93
# File 'lib/quarto/generator.rb', line 91

def output_path
  @output_path
end

Class Method Details

.current_output_file_pathObject



79
80
81
# File 'lib/quarto/generator.rb', line 79

def self.current_output_file_path
  @current_output_file_path
end

.current_output_file_path=(path) ⇒ Object



83
84
85
# File 'lib/quarto/generator.rb', line 83

def self.current_output_file_path=(path)
  @current_output_file_path = path
end

Instance Method Details

#generate(&block) ⇒ Object

Generate the project according to the directives given in the block.

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
# File 'lib/quarto/generator.rb', line 54

def generate(&block)
  raise ArgumentError, 'generate must be called with a block' unless block_given?
  if !File.exists? @output_path
    Dir.mkdir @output_path
  end
  instance_eval(&block)
end

#generate_file_pathObject

:nodoc:



62
63
64
# File 'lib/quarto/generator.rb', line 62

def generate_file_path # :nodoc:
  @project_path + '/generate.rb'
end

#urls_file_pathObject

:nodoc:



87
88
89
# File 'lib/quarto/generator.rb', line 87

def urls_file_path # :nodoc:
  @project_path + '/urls.rb'
end