Class: Build
- Inherits:
-
Object
- Object
- Build
- Defined in:
- lib/liquidoc.rb
Overview
class Action
Class Method Summary collapse
Instance Method Summary collapse
- #add_attrs!(attrs) ⇒ Object
- #add_config_file(config_file) ⇒ Object
- #add_search_prop!(prop) ⇒ Object
- #add_vars!(vars) ⇒ Object
-
#attributes ⇒ Object
NOTE this section repeats in Class.AsciiDocument.
- #backend ⇒ Object
- #doctype ⇒ Object
-
#initialize(build, type) ⇒ Build
constructor
A new instance of Build.
- #message ⇒ Object
- #output ⇒ Object
- #prop_files_array ⇒ Object
- #props ⇒ Object
- #search ⇒ Object
- #set(key, val) ⇒ Object
- #style ⇒ Object
- #template ⇒ Object
- #validate ⇒ Object
- #variables ⇒ Object
Constructor Details
#initialize(build, type) ⇒ Build
Returns a new instance of Build.
356 357 358 359 360 361 362 |
# File 'lib/liquidoc.rb', line 356 def initialize build, type build['attributes'] = Hash.new unless build['attributes'] build['props'] = build['properties'] if build['properties'] @build = build @type = type @build['variables'] = {} unless @build['variables'] end |
Class Method Details
.set(key, val) ⇒ Object
493 494 495 |
# File 'lib/liquidoc.rb', line 493 def self.set key, val @build[key] = val end |
Instance Method Details
#add_attrs!(attrs) ⇒ Object
480 481 482 483 484 485 486 487 |
# File 'lib/liquidoc.rb', line 480 def add_attrs! attrs begin attrs.to_h unless attrs.is_a? Hash self.attributes.merge!attrs rescue raise "InvalidAttributesFormat" end end |
#add_config_file(config_file) ⇒ Object
497 498 499 500 501 502 503 504 505 506 |
# File 'lib/liquidoc.rb', line 497 def add_config_file config_file @build['props'] = Hash.new unless @build['props'] @build['props']['files'] = Array.new unless @build['props']['files'] begin files_array = @build['props']['files'].force_array @build['props']['files'] = files_array.push(config_file) rescue raise "PropertiesFilesArrayError" end end |
#add_search_prop!(prop) ⇒ Object
467 468 469 470 471 472 473 |
# File 'lib/liquidoc.rb', line 467 def add_search_prop! prop begin self.search.merge!prop rescue raise "PropertyInsertionError" end end |
#add_vars!(vars) ⇒ Object
392 393 394 395 |
# File 'lib/liquidoc.rb', line 392 def add_vars! vars vars.to_h unless vars.is_a? Hash self.variables.merge!vars end |
#attributes ⇒ Object
NOTE this section repeats in Class.AsciiDocument
476 477 478 |
# File 'lib/liquidoc.rb', line 476 def attributes @build['attributes'] end |
#backend ⇒ Object
380 381 382 |
# File 'lib/liquidoc.rb', line 380 def backend @build['backend'] end |
#doctype ⇒ Object
376 377 378 |
# File 'lib/liquidoc.rb', line 376 def doctype @build['doctype'] end |
#message ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/liquidoc.rb', line 397 def # dynamically build a message, possibly appending a reason unless @build['message'] reason = ", #{@build['reason']}" if @build['reason'] case @type when "parse" text = ".. Builds `#{self.output}` pressed with the template `#{self.template}`#{reason}." when "render" case self.backend when "pdf" text = ".. Uses Asciidoctor/Prawn to generate a PDF file `#{self.output}`" text.concat("#{reason}") if reason text.concat(".") when "html5" text = ".. Compiles a standard Asciidoctor HTML5 file, `#{self.output}`" text.concat("#{reason}") if reason text.concat(".") when "jekyll" text = ".. Uses Jekyll config files:\n+\n--" files = self.props['files'] if files.is_a? String if files.include? "," files = files.split(",") else files = files.split end else unless files.is_a? Array @logger.error "The Jekyll configuration file must be a single filename, a comma-separated list of filenames, or an array of filenames." end end files.each do |file| text.concat("\n * `#{file}`") end text.concat("\n\nto generate a static site") if self.props && self.props['arguments'] text.concat(" at `#{self.props['arguments']['destination']}`") end text.concat("#{reason}") if reason text.concat(".\n--\n") end return text end else @build['message'] end end |
#output ⇒ Object
368 369 370 |
# File 'lib/liquidoc.rb', line 368 def output @build['output'] end |
#prop_files_array ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/liquidoc.rb', line 445 def prop_files_array if props if props['files'] begin props['files'].force_array if props['files'] rescue Exception => ex raise "PropertiesFilesArrayError: #{ex}" end end else Array.new end end |
#props ⇒ Object
384 385 386 |
# File 'lib/liquidoc.rb', line 384 def props @build['props'] end |
#search ⇒ Object
def prop_files_list # force the array back to a list of files (for CLI)
props['files'].force_array if props['files']
end
463 464 465 |
# File 'lib/liquidoc.rb', line 463 def search props['search'] end |
#set(key, val) ⇒ Object
489 490 491 |
# File 'lib/liquidoc.rb', line 489 def set key, val @build[key] = val end |
#style ⇒ Object
372 373 374 |
# File 'lib/liquidoc.rb', line 372 def style @build['style'] end |
#template ⇒ Object
364 365 366 |
# File 'lib/liquidoc.rb', line 364 def template @build['template'] end |
#validate ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/liquidoc.rb', line 508 def validate reqs = [] case self.type when "parse" reqs = ["template,output"] when "render" reqs = ["output"] end for req in required if (defined?(req)).nil? raise "ActionSettingMissing" end end end |
#variables ⇒ Object
388 389 390 |
# File 'lib/liquidoc.rb', line 388 def variables @build['variables'] end |