Re: Add a javascript to the page generated (guard)

Posted by mojavelinux on
URL: https://discuss.asciidoctor.org/Add-a-javascript-to-the-page-generated-guard-tp685p716.html

Charles,

It doesn't work when you use the API because you still need to set the safe mode option.

guard 'shell' do
  watch(/^*\.adoc$/) {|m|
    Asciidoctor.render_file(m[0], {
      :in_place => true,
      :safe => :unsafe,
      :attributes => {
          'backend' => 'html5',
          'linkcss' => '',
          'docinfo' => ''
      }
    })
  }
end

Btw, you can also set the backend using an option:

guard 'shell' do
  watch(/^*\.adoc$/) {|m|
    Asciidoctor.render_file(m[0], {
      :in_place => true,
      :safe => :unsafe,
      :backend => :html5,
      :attributes => {
          'linkcss' => '',
          'docinfo' => ''
      }
    })
  } 
end

Though html5 is the default, so you really don't need to set it.

You can also set the attributes using a string (or string-based array syntax) similar to how they are set on the commandline:

guard 'shell' do
  watch(/^*\.adoc$/) {|m|
    Asciidoctor.render_file(m[0], {
      :in_place => true,
      :safe => :unsafe,
      :backend => :html5,
      :attributes => 'linkcss docinfo'
    })
  }
end

Hopefully that should do the trick.

-Dan



On Fri, Oct 4, 2013 at 5:01 AM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Alan,

Many thanks. That works fine adding the option using asciidoctor command line ' asciidoctor -b html5 -a docinfo test.adoc' or attribute directly in the doc :docinfo:

Nevertheless, that does not work if I add the attribute to guard :

guard 'shell' do
  watch(/^*\.adoc$/) {|m|
    Asciidoctor.render_file(m[0], {
      :in_place => true,
      :attributes => {
          'backend' => 'html5',
          'linkcss' => 'true',
          'docinfo' => 'true'
      }
    })
  }
end

Cheers

Charles


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Add-a-javascript-to-the-page-generated-guard-tp685p704.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | http://google.com/profiles/dan.j.allen