Markaby 0.3 #
Now that Markaby’s had some life experiences, Tim and I have sucker-punched it a bit here and there. And the sum of those shapings is 0.3.
You already know to gem install markaby
.
- Finally, full documentation.
- A new render_markaby method for quickly outputting from inside a controller.
- Cleaned up for general Ruby use, just attach a block to
Markaby::Builder.new
containing all your HTML calls.
A tip: you know how all calls to helpers are automatically output to the builder stream? Well, if you need the helper method’s output, just call it against the @helpers
instance var.
p "Total is: #{@helpers.number_to_human_size @file_bytes}"
At least until we decide upon something fancier.
jakdak
great stuff !
jakdak
I guess it’s a personal style thing, but isn’t using {}’s rather than do/end better in terms of representing the hierarchical nature of XML ? e.g.
html { body { } }
rather than :
html do body do end end
(I did have them spaced over several lines, but it gets messed with by the rouge cloth)
Branstrom
Superb.
murphy
Thank you for the docu!
Danno
What’s the easiest way to work on a page’s markup using Markaby (y’know, without anything else)?
Binding a folder with Markaby template files to Webrick (or Mongrel) and then editing and refreshing from there?
tim
jakdak: yeah, a lot of people seem to prefer using braces in this context. looks neater.
Josie
Danno – thats a fair point. Maybe we need an .xhtml → .mab converter :p :o)
Danno
Don’t you mean .mab → .xhtml?
Hrmm… then I could tell vi to invoke that whenever I saved a .mab file and just look back and forth at the changes.
tim
HTML preview?
TextMate users can add a command…
Save: Nothing
Command(s):
ruby -rrubygems -e "require 'markaby'; puts Markaby::Builder.new { eval(STDIN.read) }"
Input: Entire Document
Output: Show as HTML
Scope Selector: source.ruby
Danno
Yeah, that’s what I’m talking about.
Now I, just have to figure out how to do it in vim.
Josie
thats very cool stuff
an .xhtml → .mab would be useful too :)
JM
How do you add attributes to tags other than id and class?
dvoodoo
JM: you can pass a hash after the text:
p.important "Bla.", :lang=>"de"
Ben
Nice, very, very nice
JM
dvoodoo: Thank you sir!
grant
It would be cool if you could change the charset used by head in its meta tag. builder.rb can check @helpers.headers[‘Content-Type’], but that only works if the header was explicitly set (with before_filter, for instance). I’m not sure how to get at the final Content-Type header Rails decides on, or even where Rails decides what that is.
Danno
I started building a page in Markaby (it’s taking me a while since I’m horrible at CSS ) and one thing I noticed that’d be nice is if Markaby had some kind of placeholder for the Rails helpers, I don’t know if that’s possible… or maybe I should just stick the dang file into a view and test through script/server…
Danf
Changes to the value of instance variables inside a Markaby template should be transported to the layout, like it happens with regular .rhtml templates.
Thijs
Hmm. I’m wondering about the nicest way to html-escape stuff like the decription in
self << category.description
?Thijs
Hmm again. Is there a way to set the class dynamically that’s nicer than doing
eval "span.status.#{story.status} story.status"
?why
Thijs: Fall back to:
To html escape stuff use the
text
method:Which is identical to:
Dopey
J’ai un petite Question:
I have a method called “logged_in?” defined in mon ApplicationHelper.
When I use that method from inside un .mab file, I get cette petite error:
builder.rb:161:in `instance_variable_get': `@logged_in?' is not allowed as an instance variable name
Vous avez any ideas what that is?
Looks very alien to moi
tim
Dopey: that’s a bug! Should work ok now (as of rev 28)
Dopey
Merci beaucoup monsieur
(I’m not actually french. I just . umm .. yeah you can see by my screename)
Jerry
<td> <%= name %> <% if condition %> <%= extrainfo %> <% end %> </td>
To convert this to markaby, it seems the way is:td { a = name if condition a += extrainformation end a }
I was wondering if having the temporary variable is how it’s supposed to be done.
Second. How do I get<br/>
into a string? For example:th "A" + br + "B"
seems to break.why
Maybe the first could be:
A lot of times I’ll use RedCloth for formatting with breaks in it, italics, bold and the like.
Luke
I think you should consider adding an option to enable/disable the XML instruction that is inserted before the doctype – adding this will throw IE into quirks mode which is often what you don’t want.
carmen
trying to figure out how to use this neat blob of code. so far ive added:
require ‘markaby’ ActionView::Base::register_template_handler :mab, Markaby::Template
to my app (id love to try the plugin but the code server seems down and additionally goggles seems to not want to show the cache)
`@html do’ is not allowed as an instance variable name /usr/lib64/ruby/gems/1.8/gems/markaby-0.3/lib/markaby/builder.rb:55:in `instance_variable_set’
c
went on a spelunking mission and found out i was delegating to the wrong class. of course now the SVN server has returned where all this is bleedingly obvious. next quest: write a regex, or manually convert? /me flips a coin…
AntRamm
Hi there, it would seem that as of rails edge version 3989 the plugin does not work, it just displays the source of the template rather than rendering it. Not sure why this is. It definitely seems to be version 3988 which is the last to work. I’ve tried previous and subsequent versions, subsequent ones don’t work, previous ones do.
Thanks
frukas
so attempting to get the instance variables that are created inside a .mab (as opposed to a rails controller) to exist in markaby partials this peculiar error message:
[””, ”\n”]
[””, ”\n”, “[\”\”, \”\\n\”] \n \n”, ””, ”\n”]
[””, ”\n”, “[\”\”, \”\\n\”] \n \n”, ””, ”\n”, “[\”\”, \”\\n\”, \”[\\\”\\\”, \\\”\\\\n\\\”] \\n \\n\”, \”\”, \”\\n\”] \n \n”, ””, ”\n”]
i think it says ‘i love you’, in escape-squeak..
Comments are closed for this entry.