Open jxxcarlson opened 9 years ago
Probably best to ask for advice from @mogztter or @anthonny since they do this more frequeintly. Honestly, though, it's not much trickier than building on the Rakefile found in the Asciidoctor.js repository.
https://github.com/asciidoctor/asciidoctor.js/blob/master/Rakefile#L17-L40
Of course, that's if it works. If something fails...well, then it requires a lot more debugging :) It's still very much an effort of trial and error :)
Thanks! I will try this and contact them if necessary.
@mogzzter or @anthonny, could you help me out on this? I a am a noob (newbie:-).
What I would like to do is to cross-compile asciidoctor-latex so that it can work with live preview and atom's asciidoctor preview. The important part for now is the HTML backend of asciidoctor-latex. It adds LaTeX features to Asciidoctor so as to make mathematicians happier. (The other part translates Asciidoc to LaTeX). See http://noteshare.io/section/elliptic-curves for an example of this use of Asciidoctor -- would be great if the same could be done in atom and the main browsers.
I've done the following:
(1)
require 'opal'
# require_relative 'rake/jdk_helper' ### not a gem? don't know where to obtain this
# require_relative 'rake/tar' ### likewise
# NOTE we're no longer using ERB templates in Asciidoctor.js by default
# make Opal recognize .html.erb as valid ERB templates
#Tilt.register 'erb', Opal::ERB::Processor
#Sprockets.register_engine '.erb', Opal::ERB::Processor
#Sprockets.register_mime_type 'application/javascript', '.html'
minify = ENV['MINIFY'] == '1'
compress = ENV['COMPRESS'] == '1'
task :default => :dist
desc 'Build opal.js, asciidoctor-latex.js and endorsed extensions to build/'
task :dist do
Opal::Processor.method_missing_enabled = false
Opal::Processor.const_missing_enabled = false
Opal::Processor.source_map_enabled = false
Opal::Processor.dynamic_require_severity = :ignore
Dir.mkdir 'build' unless File.directory? 'build'
env = Opal::Environment.new
env.js_compressor = Sprockets::ClosureCompressor if minify
#env['opal'].write_to "build/opal.js#{compress ? '.gz' : nil}"
# Use use_gem if you want to build against a release
# env.use_gem 'asciidoctor-latex'
# If the Gemfile points to a git repo or local directory, be sure to use `bundle exec rake ...`
# Use append_path if you want to build against a local clone
env.append_path '/Users/carlson/dev/git/asciidoctor-latex/lib' # 'asciidoctor/lib'
#env['asciidoctor'].write_to "build/asciidoctor.js#{compress ? '.gz' : nil}"
asciidoctor_latex = env['asciidoctor-latex']
# NOTE hack to make version compliant with semver
asciidoctor_latex.instance_variable_set :@source, (asciidoctor_latex.instance_variable_get :@source)
.sub(/'VERSION', "(\d+\.\d+.\d+)\.(.*)"/, '\'VERSION\', "\1-\2"')
asciidoctor_latex.write_to "build/asciidoctor-latex.js#{compress ? '.gz' : nil}"
asciidoctor_latex_spec = Gem::Specification.find_by_name 'asciidoctor-latex'
# css_file = File.join asciidoctor_spec.full_gem_path, 'data/stylesheets/asciidoctor-default.css'
# File.copy_stream css_file, 'build/asciidoctor.css'
# File.copy_stream css_file, 'examples/asciidoctor.css'
end
(2)
$ rake -f cross-compile.rake
rake aborted!
NameError: uninitialized constant Opal::Environment
/Users/carlson/dev/git/asciidoctor-latex/cross-compile.rake:25:in `block in <top (required)>'
Tasks: TOP => default => dist
(See full trace by running task with --trace)
$ bundle exec rake -f cross-compile.rake
rake aborted!
LoadError: cannot load such file -- opal
/Users/carlson/dev/git/asciidoctor-latex/cross-compile.rake:1:in `require'
/Users/carlson/dev/git/asciidoctor-latex/cross-compile.rake:1:in `<top (required)>'
(See full trace by running task with --trace)
@mogzzter or @anthonny, to clarify (though perhaps you understood it from Jim's post) we can look at this as an additional extension to load for asciidoctor.js, potentially. The output is still HTML, it just provides extra blocks that are also interpreted when making the LaTeX.
@Moztter, I've implemented a possible workaround to the prepend
problem which was suggested by Dan -- see These lines in the converter. I've tried to test it with bundle exec rake -f cross.rake
but I get the errors listed below. Would you mind having a look at it?
Errors:
[~/dev/git/asciidoctor-latex] ruby-2.2.2 $ bundle exec rake -f cross.rake --trace
rake aborted!
NameError: uninitialized constant Opal::Tilt
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal/sprockets/processor.rb:21:in `<module:Opal>'
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal/sprockets/processor.rb:7:in `<top (required)>'
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal/sprockets/environment.rb:2:in `require'
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal/sprockets/environment.rb:2:in `<top (required)>'
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal/sprockets.rb:1:in `require'
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal/sprockets.rb:1:in `<top (required)>'
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal.rb:4:in `require'
/Users/carlson/.rvm/gems/ruby-2.2.2/gems/opal-0.6.3/lib/opal.rb:4:in `<top (required)>'
/Users/carlson/dev/git/asciidoctor-latex/cross.rake:1:in `require'
/Users/carlson/dev/git/asciidoctor-latex/cross.rake:1:in `<top (required)>'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/carlson/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/carlson/.rvm/rubies/ruby-2.2.2/bin/rake:33:in `<main>'
[~/dev/git/asciidoctor-latex] ruby-2.2.2 $
I remember hitting this when I tried Opal 0.6.3. I think it's a bug in Opal. Open up the first file mentioned in the stacktrace and add the following line:
require 'tilt'
You'll also need to add 'tilt' to your Gemfile.
gem 'tilt'
Then run bundle again:
$ bundle
And it should work!
I don't know what's going on with Opal that it broke without this hack, but I haven't had time to look into it. The problem may go away as soon as we migrate to Opal 0.8.0, but before you try that, see if the hack works out for you. It built fine for me. Now, whether it runs is a whole other story :)
@mojavelinux could you teach me how to do this?