How to change images path when converting AsciiDoc file containing diagrams to html using Asciidoctor Ruby API? - ruby

Lets suppose there is a web based documentation available at docs.project
Directory structure
/ - project root
/docs - documentation files in asciidoc format
index.adoc - documentation entry point
/public - public directory
generate.rb
Desirable workflow
I change documentation source in /docs directory.
I commit and push changes.
When pushing, the server runs ruby <project_root>/generate.rb command that rewrites the html presentation of the documentation.
index.adoc
= Documetation
Some text
[plantuml]
....
Client --> Server: Request
Server --> Client: Response
....
generate.rb
require 'asciidoctor'
require 'asciidoctor-diagram'
ROOT = File.dirname(__FILE__)
entry = ROOT + '/docs/index.adoc'
outdir = ROOT + '/public'
Asciidoctor.convert_file entry, to_dir: outdir, mkdirs: true
Problem
Current generate.rb script puts index.html file in public while images go to docs thus they are not available when you open docs.project in browser.
How to specify the images path?

You can use imagesdir
You could move all your images that are being used in your index.adoc into the public folder(since this is your output folder) and can set imagesdir document attribute like:
:imagesdir: ../public/
inside your index.adoc file. You could learn more about imagesdir here

Your problem should be that when using the Ruby API, the default safe mode is set to :secure, which should prevent access to files which reside outside of the parent directory of the source file. I am assuming to_dir is allowed to write the file, while plantuml goes through a different generation process (probably initially generates the image and then includes it, preventing access to the directory). In any case, you have two options.
Use unsafe mode with:
Asciidoctor.convert_file entry, to_dir: outdir, mkdirs: true, safe: :unsafe
It is probably not the best solution, use only if you are running it with controlled content (and no one can put something like include::/etc/passwd[] in the adoc source).
Change the base_dir with:
Asciidoctor.convert_file entry, base_dir: '.', to_dir: outdir, mkdirs: true
Which should work, assuming your directory structure looks like:
.
├── docs
│   └── index.adoc
├── generate.rb
└── public

Related

module files not downloading for themes

I want to change my site using Hugo. I get stuck with modules. As per documentation (e.g. this theme) I just add theme = "github.com/nodejh/hugo-theme-mini" to the config file. It fails like this:
WARN ... found no layout file for "HTML" for kind "term": You should ...
if I perform hugo mod vendor the directory structure of the theme seems created in the _vendor dir, but there is not a single file inside. which explains the "not found" error in my eyes.
nothing (!) is rendered.
I also have this effect with a couple of other themes (I thinknoteworthy being one of them).
Set up a clean project
hugo new site testModules
cd testModules
and enable Hugo modules
hugo mod init randomName`
Paste the following lines in config.toml:
baseURL = "http://example.org/"
title = "Hugo Modules Test"
[module]
[[module.imports]]
path = "github.com/nodejh/hugo-theme-mini"
Start Hugo
hugo serve -D
Done!
The content of github.com/nodejh/hugo-theme-mini" will be downloaded and used as theme.
See the theme's documentation to add content
Optional:
hugo mod vendor
will make the content of the remote repo available in the _vendor folder.
(Surprisingly the content of exampleSite was not downloaded during the quick test I made)

Middleman Output Path

EDIT for clarity:
I'm wondering if it is possible to have set an output path for files in a Middleman build. For organizational purposes I want to group a type of page into a folder to keep it out of the main source directory. However on build/server I would like it to render to a different path:
/source
index.html
/landingpages
landingpage1.html
landingpage2.html
I have :directory_indexes enabled in my config file would like to be able to have the files in landingpage output to the root directory:
/build
index.html
/landingpage1
index.html
/landingpage2
index.html
Is this possible to achieve this somehow using the config.rb file and still show up properly in the sitemap? I would prefer to not have to do this using .htaccess
Thanks
A technique I used in a current project is based around proxies and should also solve your case:
landingpage_templates = Dir['source/landingpages/*.html']
landingpage_templates.map! do |tpl_name|
tpl_name = File.basename(tpl_name).gsub(/.html$/, '')
proxy "/#{tpl_name}/index.html", "/landingpages/#{tpl_name}.html", :ignore => true
end
You should be able to do something like that:
page "/file1/index.html", :proxy => "/somefolder/file1.html"
page "/file2/index.html", :proxy => "/somefolder/file2.html"
I think you're better off using directory indexes instead though and organising your files like:
/source
index.html
file1.html
file2.html
In your config.rb
activate :directory_indexes

Why would I get "Errno::ENOENT: No such file or directory" when viewing a Sinatra form?

I am trying to follow this tutorial:
http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra/
Got stuck in "We’ll also make use of a “view file”, which allows us to split the markup for a view into a separate file. "
I have my basics.rb file running fine.
And My files are stored as follows:
Desktop/RubyForm/basics.rb
Desktop/RubyForm/view/form.erb
However, now when i go to http://localhost:9393/form , I am greeted with:
Errno::EIO at /form
Input/output error - <STDERR> file: lint.rb location: write line: 398
sinatra.error
Errno::ENOENT: No such file or directory -
/Users/HelenasMac/Desktop/views/form.erb
UPDATE! : Got the form to work right after running ruby basics.rb and going to http://localhost:4567/form .
However, after I run "shotgun basics.rb" , I have to go to
http://localhost:9393/form, and that's when the form doesn't show up.
What am I doing wrong? Disclaimer: mega beginner to ruby and using the terminal.
Thanks in advance!
If you cannot get shotgun to work then the new recommended way to reload Sinatra seems to be rerun.
To use it:
> gem install rerun
> cd /Users/HelenasMac/Desktop/RubyForm
> rerun ruby basics.rb
Explicity Set a Views Directory
Unless you're using inline template for your views with enable :inline_templates, you may need to explicitly define a template directory if the default values aren't working for you. The docs describe how to set your views directory as follows:
:views - view template directory
A string specifying the directory where view templates are located. By default, this is assumed to be a directory named “views” within the application’s root directory (see the :root setting). The best way to specify an alternative directory name within the root of the application is to use a deferred value that references the :root setting:
set :views, Proc.new { File.join(root, "templates") }
You may also need to explicitly set :root, and make sure that both :root and :views make sense from your current working directory.

MoinMoin seperate theme folder from MoinMoin htdocs folder

I'd like to seperate my custom theme folder from the default MoinMoin htdocs folder. Here is my directory structure of my current installation:
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/...
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/index.html
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/classic
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/modern
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/mytheme
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/mytheme/style.css
And my custom Git-versioned wiki/data directory:
/path/to/git-repo/wikiconfig.py
/path/to/git-repo/wikiserver.py
/path/to/git-repo/wiki/data/...
/path/to/git-repo/wiki/data/plugin/theme/mytheme.py
/path/to/git-repo/wiki/underlay/...
The wikiconfig.py contains the following configuration:
class LocalConfig(multiconfig.DefaultConfig):
wikiconfig_dir = os.path.abspath(os.path.dirname(__file__))
instance_dir = os.path.join(wikiconfig_dir, 'wiki')
data_dir = os.path.join(instance_dir, 'data', '') # path with trailing /
data_underlay_dir = os.path.join(instance_dir, 'underlay', '') # path with trailing /
DesktopEdition = True # give all local users full powers
acl_rights_default = u"All:read,write,delete,revert,admin"
surge_action_limits = None # no surge protection
sitename = u'Foo'
logo_string = u'<span><img src="...">Bar</span>' % url_prefix_static
page_front_page = u'StartPage'
theme_default = 'mytheme'
I would like to move the theme's static files to the /path/to/git-repo folder, because this directory is a Git repository which should contain all custom modifications, and also the theme's static files.
Any ideas how this could be done?
Regards
I suggest you just leave the builtin static stuff where it is.
What you can do for custom and separate theme development is to serve your static stuff at some specific URL and catch that URL in the web server before it gets given to moin.wsgi (and ends up being served by MoinMoin's builtin static file server), something like:
Alias /moin_static196/mytheme /path/to/git-repo/static
WSGIScriptAlias / /..../moin.wsgi
/moin_static196 is the url path moin 1.9.6 uses by default, you can modify it in wikiconfig.py to use anything you like.
You would put the theme python code also into your git repo and just symlink it from the instances data/plugin/theme/ directory.

newbie sinatra question

To return a file using sinatra, I had been using this:
get '/:name' do
x = File.open('c:/mywebsite/' + params[:name],'r')
end
where the incoming url is "http://localserver:4567/myfile.html.
It works, but it occurs to me there must be a better way, yet I can't find the preferred mechanism on the sinatra site.
put static files in the public/ folder within the app's directory
Static Files
Static files are served from the
./public directory. You can specify a
different location by setting the
:public option:
set :public, File.dirname(__FILE__)
+ '/static'
Note that the public directory name is
not included in the URL. A file
./public/css/style.css is made
available as
example.com/css/style.css.
from:
http://www.sinatrarb.com/intro.html
Is this a static file? If so, I'd put it in the application's public directory. You can read more about static files here (scroll about a quarter of the way down the page to find the section marked "Static Files").

Resources