If-then in markdown or asciidoc based on awestruct variable

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

If-then in markdown or asciidoc based on awestruct variable

ge0ffrey
In a markdown or asciidoc file, is it possible to render something conditionally? Something like:

? if (#{site.pom.latestFinal.version} != #{site.pom.latest.version}) then render {
Download the *non-final* version #{site.pom.latest.version} ...
? }
Reply | Threaded
Open this post in threaded view
|

Re: If-then in markdown or asciidoc based on awestruct variable

LightGuard
Administrator

To my knowledge, no. What you could do though is have a site variable you change, or do it in haml / slim. 


Sent from Mailbox for iPhone


On Wed, Mar 20, 2013 at 8:12 AM, ge0ffrey <[hidden email]> wrote:

In a markdown or asciidoc file, is it possible to render something
conditionally? Something like:

? if (#{site.pom.latestFinal.version} != #{site.pom.latest.version}) then
render {
Download the *non-final* version #{site.pom.latest.version} ...
? }




--
View this message in context: http://talk-archive.awestruct.org/If-then-in-markdown-or-asciidoc-based-on-awestruct-variable-tp186.html
Sent from the Awestruct Talk mailing list archive at Nabble.com.

---------------------------------------------------------------------
Archives: http://talk-archive.awestruct.org/
To unsubscribe, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: If-then in markdown or asciidoc based on awestruct variable

ge0ffrey
Thanks for the info.

Yes, I feared that I 'd have to revert to haml.
Reply | Threaded
Open this post in threaded view
|

Re: If-then in markdown or asciidoc based on awestruct variable

mojavelinux
In reply to this post by LightGuard
Actually, the answer is yes.

Aslak and I hacked on bidirection variable passing between Awestruct and AsciiDoc...part of why I think they are so well suited for each other.

I think the one limitation is that you have to move the value to a top-level site variable (I have to double check that limitation).

Here's how it might work:

Assume:
site.latestFinalVersion = "5.1.0"
site.latestVersion = "5.0.0"

Then, in AsciiDoc, you can type:

ifeval::["{latestVersion}" > "{latestFinalVersion"]
text here
endif::[]

Here's the test that shows this working in Asciidoctor:


We are probably missing some comprehensive tests for this in Awestruct, so consider that it may need to be improved. If you have ideas for how to improve it, feel free to suggest them or hack on them.

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

Reply | Threaded
Open this post in threaded view
|

Re: If-then in markdown or asciidoc based on awestruct variable

mojavelinux
On Wed, Mar 20, 2013 at 2:05 PM, Dan Allen <[hidden email]> wrote:
Actually, the answer is yes.

Aslak and I hacked on bidirection variable passing between Awestruct and AsciiDoc...part of why I think they are so well suited for each other.

I think the one limitation is that you have to move the value to a top-level site variable (I have to double check that limitation).

Here's how it might work:

Assume:
site.latestFinalVersion = "5.1.0"
site.latestVersion = "5.0.0"

Then, in AsciiDoc, you can type:

ifeval::["{latestVersion}" > "{latestFinalVersion}"]
text here
endif::[]

If the version are semantic, the comparison should work on the string values.

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

Reply | Threaded
Open this post in threaded view
|

Re: If-then in markdown or asciidoc based on awestruct variable

LightGuard
Administrator
Cool, had no idea AsciiDoc had conditionals.


On Wed, Mar 20, 2013 at 2:06 PM, Dan Allen <[hidden email]> wrote:
On Wed, Mar 20, 2013 at 2:05 PM, Dan Allen <[hidden email]> wrote:
Actually, the answer is yes.

Aslak and I hacked on bidirection variable passing between Awestruct and AsciiDoc...part of why I think they are so well suited for each other.

I think the one limitation is that you have to move the value to a top-level site variable (I have to double check that limitation).

Here's how it might work:

Assume:
site.latestFinalVersion = "5.1.0"
site.latestVersion = "5.0.0"

Then, in AsciiDoc, you can type:

ifeval::["{latestVersion}" > "{latestFinalVersion}"]
text here
endif::[]

If the version are semantic, the comparison should work on the string values.

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597




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

Re: If-then in markdown or asciidoc based on awestruct variable

mojavelinux
In reply to this post by mojavelinux
Ah, I didn't have it quiet right. It doesn't take variables from site, but rather from page.

Thus, the assumption must be:

page.latestVersion = "5.1.0"
page.latestFinalVersion = "5.0.0"

You can move values from site to page using an extension in the pipeline:

module Awestruct::Extensions

  class VersionAssigner
    def execute(site)
      site.pages.each do |page|
        page.latestVersion = 'xxx'
        page.latestFinalVersion = 'xxx'
      end
    end
  end

end

We could also explore the idea of site keys that are transferred through a declaration or regex. Bascially, some way to determine what variables to copy into the AsciiDoc attributes before parsing.

-Dan

On Wed, Mar 20, 2013 at 2:06 PM, Dan Allen <[hidden email]> wrote:
On Wed, Mar 20, 2013 at 2:05 PM, Dan Allen <[hidden email]> wrote:
Actually, the answer is yes.

Aslak and I hacked on bidirection variable passing between Awestruct and AsciiDoc...part of why I think they are so well suited for each other.

I think the one limitation is that you have to move the value to a top-level site variable (I have to double check that limitation).

Here's how it might work:

Assume:
site.latestFinalVersion = "5.1.0"
site.latestVersion = "5.0.0"

Then, in AsciiDoc, you can type:

ifeval::["{latestVersion}" > "{latestFinalVersion}"]
text here
endif::[]

If the version are semantic, the comparison should work on the string values.

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597




--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

Reply | Threaded
Open this post in threaded view
|

Re: If-then in markdown or asciidoc based on awestruct variable

mojavelinux
In reply to this post by LightGuard
On Wed, Mar 20, 2013 at 2:15 PM, Jason Porter <[hidden email]> wrote:
Cool, had no idea AsciiDoc had conditionals.

Yep, that was part of the addition in 0.1.1 (which AsciiDoc had all along).

AsciiDoc actually has some pretty scary stuff too, which we aren't implementing. It can execute arbitrary Python and system commands.

However, the ability to execute arbitrary Ruby could be useful (though non-portable) for Awestruct. It smells like a bad idea, though, something we can solve in a more elegant way I think.

-Dan
 
--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

Reply | Threaded
Open this post in threaded view
|

Re: If-then in markdown or asciidoc based on awestruct variable

mojavelinux
In reply to this post by mojavelinux
From doing some quick experimenting, I'm seeing that we probably need to test, document and likely enhance this part of the integration better.

Feel free to post your use case in an issue for Awestruct and we can be sure we implement the right requirements. Try to write it in a BDD style so that the use case clearly comes through.

The overall goal of the two-way integration is that you could still take the document out of Awestruct, assign the variables from the commandline using attributes, and be able to render the document in a meaningful way. We disabled string interpolations in the AsciiDoc handler because that makes the document like a JSP, riddled with stuff that only works in that environment. I guess you could say this is sort of the XSLT approach to dynamic data.

-Dan 

On Wed, Mar 20, 2013 at 2:18 PM, Dan Allen <[hidden email]> wrote:
Ah, I didn't have it quiet right. It doesn't take variables from site, but rather from page.

Thus, the assumption must be:

page.latestVersion = "5.1.0"
page.latestFinalVersion = "5.0.0"

You can move values from site to page using an extension in the pipeline:

module Awestruct::Extensions

  class VersionAssigner
    def execute(site)
      site.pages.each do |page|
        page.latestVersion = 'xxx'
        page.latestFinalVersion = 'xxx'
      end
    end
  end

end

We could also explore the idea of site keys that are transferred through a declaration or regex. Bascially, some way to determine what variables to copy into the AsciiDoc attributes before parsing.

-Dan

On Wed, Mar 20, 2013 at 2:06 PM, Dan Allen <[hidden email]> wrote:
On Wed, Mar 20, 2013 at 2:05 PM, Dan Allen <[hidden email]> wrote:
Actually, the answer is yes.

Aslak and I hacked on bidirection variable passing between Awestruct and AsciiDoc...part of why I think they are so well suited for each other.

I think the one limitation is that you have to move the value to a top-level site variable (I have to double check that limitation).

Here's how it might work:

Assume:
site.latestFinalVersion = "5.1.0"
site.latestVersion = "5.0.0"

Then, in AsciiDoc, you can type:

ifeval::["{latestVersion}" > "{latestFinalVersion}"]
text here
endif::[]

If the version are semantic, the comparison should work on the string values.

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597




--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597




--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597