Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension for Sign languages #45

Open
edusantana opened this issue Jun 6, 2015 · 8 comments
Open

Extension for Sign languages #45

edusantana opened this issue Jun 6, 2015 · 8 comments

Comments

@edusantana
Copy link
Contributor

Hi,

I'm trying to write a extension for placing videos from a Sign Language. It would be some thing like this:

libras.yaml:

"casa": https://www.youtube.com/watch?v=xjxjTMBoNjE

sample.adoc:

:sign-lang: libras

sign::casa[]

It would read casa from libras.yaml and translate to:

video::https://www.youtube.com/watch?v=xjxjTMBoNjE[]

It would be more complex, but this would be a start.

Can someone help me?

Here's what I have done so far:

  • I think it would be a subclasse of BlockMacroProcessor, like gist-block-macro
  • A made a copy of gist-block-macro and replace gist to sign:
(...)
class SignBlockMacro < Extensions::BlockMacroProcessor
  use_dsl

  named :sign
(...)

sample.adoc

= Sign Block Macro Extension

.Guard setup to live preview AsciiDoc output
sign::mojavelinux/5546622[]
  • And I run it with -r:
asciidoctor-extensions-lab$ asciidoctor --trace -r lib/sign-languages/extension.rb lib/sign-languages/sample.adoc  
/home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- lib/sign-languages/extension.rb (LoadError)
    from /home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

  • It didn't work. So I have tests gist alone:
asciidoctor-extensions-lab$ asciidoctor --trace -r lib/gist-block-macro/extension.rb lib/gist-block-macro/sample.adoc 
/home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- lib/gist-block-macro/extension.rb (LoadError)
    from /home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  • Since I don't know if gist is working, then I have tested an other BlockMacroProcessor extension, the TreeBlockMacro. I changed the sample file to directory of mine, and tested it:
asciidoctor-extensions-lab$ asciidoctor --trace -r lib/tree-block-macro/extension.rb lib/tree-block-macro/sample.adoc 
/home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- lib/tree-block-macro/extension.rb (LoadError)
    from /home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

Can someone guide me? What I am doing wrong?

@mojavelinux
Copy link
Member

Fascinating idea!

I think that you need to start the require path with ./. It works in some environments without the ./, but safest is to use it. Just looks to me like Ruby isn't understanding where the extension is.

Of course, this would be partially solved by fixing #44, which we desperately need.

I'd say that the emoji inline macro is pretty close to this one as well, except that it is an inline macro instead of a block macro. So take a look at that one too.

@edusantana
Copy link
Contributor Author

asciidoctor-extensions-lab$ asciidoctor -r ./lib/gist-block-macro/extension.rb ./lib/gist-block-macro/sample.adoc 

With ./ it runs, but... here's the output:

sample.html:

(...)
<h1>Gist Block Macro Extension</h1>
</div>
<div id="content">
<div class="paragraph">
<div class="title">Guard setup to live preview AsciiDoc output</div>
<p>gist::mojavelinux/5546622[]</p>
</div>
</div>
(...)

I don't know... but for if I think it's missing the registration somewhere in the code. How does it know that we have an new extension available without it?

For me, the emoji isn't working ether:

(...)
<h1>Emoji Inline Macro Extension</h1>
</div>
<div id="content">
<div class="paragraph">
<p>Faster than a emoji:turtle[1x]!</p>
</div>
<div class="paragraph">
<p>This is an example of how you can emoji:heart[lg] Asciidoctor and Twitter Emoji.</p>
</div>(...)

@ggrossetie
Copy link
Member

Hello @edusantana

I don't know... but for if I think it's missing the registration somewhere in the code. How does it know that we have an new extension available without it?

The registration is done by the Ruby files in the root of the lib directory: https://github.com/asciidoctor/asciidoctor-extensions-lab/tree/master/lib

So the command line for gist-block-macro is:

asciidoctor -r ./lib/gist-block-macro.rb ./lib/gist-block-macro/sample.adoc 

@edusantana
Copy link
Contributor Author

If my extension returns video::https://www.youtube.com/watch?v=xjxjTMBoNjE[]it would no work. It's probably because it already processed the macros.

How can I call the code to produce the video after that?

@mojavelinux
Copy link
Member

There are two approaches you can inside the block processor. Before I mention them, it's important to understand that the purpose of the block processor is to contribute zero or more nodes to the AST tree during parsing.

The first approach is to return an AST node, in this case a video node. That code would look something like:

attrs['poster'] = 'youtube'
attrs['target'] = 'xjxjTMBoNjE'
return create_block parent, :video, nil, attrs, {}

The second approach is to parse the new content inside the processor. That code would look something like:

parse_content parent, 'video::https://www.youtube.com/watch?v=xjxjTMBoNjE[]'
return nil

parse_content is a helper method in the extension API. See https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/extensions.rb#L107-L119.

@mojavelinux
Copy link
Member

edusantana added a commit to edusantana/asciidoctor-extensions-lab that referenced this issue Jun 11, 2015
@edusantana
Copy link
Contributor Author

It's working...

Now the work will be to create and populate a nice repository, where users will be able no navigate and search for signs to use.

The inline macro will be used to create links, and the block to display videos.

@mojavelinux
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants