What is wrong with my test - slim backend

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

What is wrong with my test - slim backend

ch007m
Hi,

Whenever I try to use the attribute :notitle: true or :notitle: false in an asciidoc file with this revealjs slim template (see my gist) the title is not displayed in the HTML page generated - https://gist.github.com/9347866?

What is wrong in my test ?

Regards,

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

Re: What is wrong with my test - slim backend

ch007m
I continue my tests but I need your help as I'm bit confused.

The following syntax works fine if I define an attribute in my asciidoc file ':notitle: false' or 'notitle: true' but none if I define the property as attribute parameter of asciidoctor

- notitle = (attr 'notitle') ? (attr 'notitle') : 'false'

section id=@id data-transition=(attr 'data-transition') data-transition-speed=(attr 'data-transition-speed') data-background=(attr 'data-background') data-background-size=(attr 'data-background-size') data-background-repeat=(attr 'data-background-repeat') data-background-transition=(attr 'data-background-transition')

  p = "Value :" + notitle.to_s + "." 
  - if notitle.to_s.eql? 'false'
    h2=title
  - if attr? :scrollbar
    .scrollbar
      =content
  - else
    =content.chomp

How can I improve that code to have a by default ':notitle: false' value defined as parameter for asciidoctor command and add in the asciidoc file required just ':notitle: true' ?

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

Re: What is wrong with my test - slim backend

mojavelinux
Administrator
Please refer to the document template in the slim html5 backend.

https://github.com/asciidoctor/asciidoctor-backends/blob/master/slim/html5/document.html.slim#L71

You'll notice the logic is:

- unless notitle

notitle is a method on the document node. Since "self" in a template refers to the current node (in this case, document), you can call methods as top-level functions.

Attribute values are not true / false. They are set or not set. That's why your comparison to false doesn't work. If you wanted to do an explicit comparison, see the method definition of notitle.

https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/document.rb#L546

You would need to write as:

- no_title = (attr? :notitle) ? true : false

Though it may be less confusing to write it the other way around:

- show_title = (attr? :notitle) ? false : true

-Dan



On Wed, Mar 5, 2014 at 4:05 AM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I continue my tests but I need your help as I'm bit confused.

The following syntax works fine if I define an attribute in my asciidoc file ':notitle: false' or 'notitle: true' but none if I define the property as attribute parameter of asciidoctor

- notitle = (attr 'notitle') ? (attr 'notitle') : 'false'

section id=@id data-transition=(attr 'data-transition') data-transition-speed=(attr 'data-transition-speed') data-background=(attr 'data-background') data-background-size=(attr 'data-background-size') data-background-repeat=(attr 'data-background-repeat') data-background-transition=(attr 'data-background-transition')

  p = "Value :" + notitle.to_s + "." 
  - if notitle.to_s.eql? 'false'
    h2=title
  - if attr? :scrollbar
    .scrollbar
      =content
  - else
    =content.chomp

How can I improve that code to have a by default ':notitle: false' value defined as parameter for asciidoctor command and add in the asciidoc file required just ':notitle: true' ?

Regards,
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/What-is-wrong-with-my-test-slim-backend-tp1574p1579.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: What is wrong with my test - slim backend

ch007m
Many thanks Dan. I suspected something like that (method called in asciidoctor ;-) )

With this modification
- show_title = attr 'notitle'
section id=@id data-transition=(attr 'data-transition') data-transition-speed=(attr 'data-transition-speed') data-background=(attr 'data-background') data-background-size=(attr 'data-background-size') data-background-repeat=(attr 'data-background-repeat') data-background-transition=(attr 'data-background-transition')
  p = "Show Title : " + show_title.to_s + "."
  - if !show_title
    h2=title
  - if attr? :scrollbar
    .scrollbar
      =content
  - else
    =content.chomp

I can achieve what I would like to do
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard
Reply | Threaded
Open this post in threaded view
|

Re: What is wrong with my test - slim backend

ch007m
My test was false.

In fact, if I add the attribute :notitle: true in a document, the value of show_title is always false when the slim block is called and where we evaluate  (attr? 'notitle')

- show_title = (attr? 'notitle') ? false : true
section id=@id data-transition=(attr 'data-transition') data-transition-speed=(attr 'data-transition-speed') data-background=(attr 'data-background') data-background-size=(attr 'data-background-size') data-background-repeat=(attr 'data-background-repeat') data-background-transition=(attr 'data-background-transition')
  p = "Show Title :" + show_title.to_s + "."
  - if show_title
    h2=title
  - if attr? :scrollbar
    .scrollbar
      =content
  - else
    =content.chomp
 
Same result using also :
- show_title = (attr? :notitle) ? false : true
OR
- show_title = (@document.attr? 'notitle') ? false : true
OR
- show_title = (@document.attr?  :notitle) ? false : true

Question : Are we able to retrieve in a section block (slim) the attribute defined for an asciidoc file ?

Remark : I'm using asciidoctor 0.1.4
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard