Textile question: redcloth anchor links - ruby-on-rails

How do I write this in textile (i'm using the redcloth gem)
Visit the Useful Tips Section
<a name="tips">Useful Tips Section</a>
I know the first part, "Visit the Useful Tips Section":#tips but how do I make the named anchor?
Thanks!
Deb

The textile manual seems to indicate that there's no way to do so other than just using straight HTML:
<a name="tips"></a>
<h1>Useful Tips Section</h1>
The answer that suggests:
h1(#tips). Useful Tips Section
is incorrect as it will generate:
<h1 id="tips">Useful Tips Section</h1>
which is not a named anchor. However, you could use some Javascript to make this work.

h1(#tips) Useful Tips Section. -- Achieves the same effect (with some css)

Related

Rails render - get partial source instead of output HTML

I don't really have a big issue and my bad if it's obvious but I couldn't find this on SO or google which is quite rare, anyways... I'm using Ruby on Rails to create a pattern library which ofcourse contains code snippets to go along with examples, now what I did was create a partial in a folder somewhere in my views - now it's no problem to render this partial using:
= render partial: '/snippets/grid/single-column.html.slim'
However, for these snippets I would also want to render the actual source of the slim file itself e.g.
.container
ul.test
li: a href="#"
li: a href="#"
li: a href="#"
li: a href="#"
I would like the output of the 'plain' render to be as the above snippet.
The reason for doing this is that I'm using Google Code Prettify to beautify this code for readability and since we're using slim as a templating engine here it's easy to just copy the snippet and paste it into a view anyways.
I'm not sure wether or not this is possible or if this type of rendering has a specific name - If so please do tell :)
For reference I looked in the following places to see if I could get a grip on this:
github - rails render
apidock - rails render
slim-lang - verbatim text
However I did not find my answer here.
Furthermore I'm a freshman when it comes to rails so I haven't got alot of experience yet in building these kinds of functions (it's nice to understand the resources you're working with ;)).
As usual, all help is appriciated.
Thanks in advance - Sidney Liebrand
EDIT
Yeah, what might also be smart is to include rails / slim versions:
Rails 4.2.1
Slim 3.0.1
You have to read the content of the file like a string in the controller for example:
#code = File.open('app/views/snippets/grid/single-column.html.slim').read
And in the view something like this:
<code class="prettyprint"><%= #code %></code>

Elegant code annotation for tutorials?

I've been writing some tutorials, and I'm trying to figure out an elegant way to add line-by-line annotations to the code in the tutorials.
For example, suppose I have some code like this:
<h1>Demo of web page</h1>
<p>This is a paragraph</p>
I'd like to be able to add something (maybe a tooltip or some kind of lightbox effect) that allows me to present an explanation of each line to the reader, while still letting them see the line in context. The best I've been able to come up with is prose explanations that say things like "The line that starts with <h1> is a headline."
Anyone ever seen something like this?
You might want to check out docco:
http://jashkenas.github.com/docco/
It's written in CoffeeScript and generates an HTML doc from a source file breaking up the comment sections and the code. It sets up the comments as annotations for each section in one column and the corresponding properly highlighted code in the other column. I think it's a great simple way to grok annotations while keeping the code in context. Oh, and it also knows markdown.
What about using title attributes?
<h1 title="your hover text">your text</h1>
I think I might have found something to rival Docco: the popover feature of Twitter Bootstrap: http://twitter.github.com/bootstrap/javascript.html#popover
I'm not sure that it will actually look good, but it seems like a good start.
Old but good question, I was searching for similar things when I found this. There are tons of ways of doing HTML annotation, see this article for a very nice listing and explanations.
If you want annotation that simply tells the user what each line does, I would write HTML comments for small pieces of code, and larger external annotations for large amounts of code. You could then parse them using custom JS to show prettier boxes if you so wish.
<h1>Heading</h1> <!-- A heading element -->
<p>paragraph</p> <!-- A paragraph element -->
<p>Paragraph with
<b>Bold</b> <!-- An inline Bold element -->
text</p>
For larger amounts of code, I would consider using something like the documentation that Docco creates. Sure, it's for JavaScript but who says a similar one can't be done for HTML. As this was tagged with jquery-UI, you also might be interested in a jQuery text annotater.

WMD + Rails: how to?

I was looking at http://wmd-editor.com/ but couldn't figure out how to use this in rails. I am pretty new. If someone can lead me to the right direction that would be very appreiciated. Thanks!
You shouldn't do much.
Just make a form with a <textarea> for the attribute you want to edit with WMD, include wmd.js like this javascript_include_tag wmd.js
Taken from WMD readme.txt:
By default, WMD will turn the first
textarea on your page into an editor.
You can modify this behavior with the
wmd-ignore class, described below.

RoR - make links clickable that show up in a user comment

I am looking for a Ruby script that takes a piece of text, and makes any links click-able that show up in it... Does anyone have something like this? For example, if I wrote a comment and said "Come check out my site at http://www.example.com", then the link would be click-able like an html tag.
Thanks,
Josh
Rails has a View helper called auto_link, e.g.:
<%= auto_link("Please visit my site: http://www.example.org/") %>
would produce:
Please visit my site: http://www.example.org/
Update: You can find more information about it here.

Wiki-like formatting in Rails

I forgotten the name of this library. But it's sort of like Wiki how you type certain characters in front of your text, and then it'll make the text bold/italic/underline.
I'm not asking for the way Wiki is formatted but I'm aware there is something similar built into Rails. It's at the tip of my tongue. Thanks.
Are you looking for the textilize view helper? In your view, just say:
<%= textilize( post.body_text ) %>
Many of these are implemented in Ruby:
Comparison of lightweight markup languages
I like Markdown, through RDiscount.
RedCloth does this. It gives you textile markup (which is among the markup languages listed in Daniel's answer).
http://redcloth.org/

Resources