Class: Guard::Asciidoctor

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/asciidoctor.rb,
lib/guard/asciidoctor/notifier.rb

Defined Under Namespace

Classes: Notifier

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Asciidoctor

Initializes a Guard plugin. Don’t do any work here, especially as Guard plugins get initialized even if they are not in an active group!

Parameters:

  • options (Hash) (defaults to: {})

    the custom Guard plugin options

Options Hash (options):

  • watchers (Array<Guard::Watcher>)

    the Guard plugin file watchers

  • group (Symbol)

    the group this Guard plugin belongs to

  • any_return (Boolean)

    allow any object to be returned from a watcher



17
18
19
20
21
22
23
24
25
26
# File 'lib/guard/asciidoctor.rb', line 17

def initialize(options = {})
  @patterns = []

  opts = {
    notifications:  true,
    helper_modules: []
  }.merge(options)

  super(opts)
end

Instance Method Details

#reloadObject

Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when reload has failed



54
55
56
57
# File 'lib/guard/asciidoctor.rb', line 54

def reload
  Compat::UI.info "method reload"
  run_all
end

#run_allObject

Called when just enter is pressed This method should be principally used for long action like running all specs/tests/…

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_all has failed



65
66
67
68
# File 'lib/guard/asciidoctor.rb', line 65

def run_all
  Compat::UI.info "run all"
  run_on_changes(Compat.matching_files(self, Dir.glob(File.join('**', '*.*'))))
end

#run_on_changes(paths) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/guard/asciidoctor.rb', line 71

def run_on_changes(paths)
  paths.each do |file|
    output_paths = _output_paths(file)
    compiled_asciidoc = compile_asciidoc(file)

    output_paths.each do |output_file|
      FileUtils.mkdir_p File.dirname(output_file)
      File.open(output_file, 'w') { |f| f.write(compiled_asciidoc) }
    end

    message = "Successfully compiled asciidoc!\n"
    message += "# #{file} -> #{output_paths.join(', ')}".gsub("#{::Bundler.root}/", '')
    Compat::UI.info message
    Notifier.notify(true, message) if options[:notifications]
  end
end

#startObject

Called once when Guard starts. Please override initialize method to init stuff.

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when start has failed



33
34
35
36
# File 'lib/guard/asciidoctor.rb', line 33

def start
  Compat::UI.info "method start"
  run_all #if options[:run_at_start]
end

#stopObject

Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when stop has failed



43
44
45
46
# File 'lib/guard/asciidoctor.rb', line 43

def stop
  Compat::UI.info "method stop"
  true
end