Add a javascript to the page generated (guard)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Add a javascript to the page generated (guard)

ch007m
Hi,

Is there a way to add a <script/> tag in the HTML page generated when using guard ? Example : ><script src="/javascripts/vendor/custom.modernizr.js"></script>
If I add this property to the xxx.adoc page (:scriptsdir: ./javascript/vendor), nothing is added.
Is there something else to do ?

Regards,

Charles
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard
Reply | Threaded
Open this post in threaded view
|

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

mojavelinux
Administrator
Charles,

There are (at least) two ways to add custom HTML, in this case JavaScript, to the output document.

1. docinfo file
2. passthrough block

For things like third-party JavaScript files, a docinfo file is the best way to go.
See the docinfo file section in the user manual for details: http://asciidoctor.org/docs/user-manual/#docinfo-file

For custom HTML you need to insert at a specific location, such as a badge image, a passthrough block works best.
See the passthrough block section in the user manual for details: http://asciidoctor.org/docs/user-manual/#passthrough-blocks

The scriptsdir attribute is used for resolving built-in JavaScript files (which Asciidoctor doesn't have anyway). However, you can use this attribute anywhere in the document or the docinfo file.

Let me know if something still isn't clear.

Cheers,

-Dan



On Thu, Oct 3, 2013 at 11:07 AM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi,

Is there a way to add a <script/> tag in the HTML page generated when using guard ? Example : ><script src="/javascripts/vendor/custom.modernizr.js"></script>
If I add this property to the xxx.adoc page (:scriptsdir: ./javascript/vendor), nothing is added.
Is there something else to do ?

Regards,

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-tp685.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

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

ch007m
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
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard
Reply | Threaded
Open this post in threaded view
|

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

mojavelinux
Administrator
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



--