hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Markaby 0.3 #

by why in inspect

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.

said on 02 Feb 2006 at 02:49

great stuff !

said on 02 Feb 2006 at 03:20

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)

said on 02 Feb 2006 at 03:48

Superb.

said on 02 Feb 2006 at 04:35

Thank you for the docu!

said on 02 Feb 2006 at 06:49

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?

said on 02 Feb 2006 at 06:51

jakdak: yeah, a lot of people seem to prefer using braces in this context. looks neater.

said on 02 Feb 2006 at 09:59

Danno – thats a fair point. Maybe we need an .xhtml → .mab converter :p :o)

said on 02 Feb 2006 at 11:43

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.

said on 02 Feb 2006 at 12:07

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

said on 02 Feb 2006 at 12:28

Yeah, that’s what I’m talking about.

Now I, just have to figure out how to do it in vim.

said on 02 Feb 2006 at 14:23

thats very cool stuff

an .xhtml → .mab would be useful too :)

said on 02 Feb 2006 at 16:29

How do you add attributes to tags other than id and class?

said on 03 Feb 2006 at 01:22

JM: you can pass a hash after the text:

p.important "Bla.", :lang=>"de"
said on 03 Feb 2006 at 10:00

Nice, very, very nice

said on 03 Feb 2006 at 10:36

dvoodoo: Thank you sir!

said on 03 Feb 2006 at 18:19

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.

said on 05 Feb 2006 at 22:09

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…

said on 06 Feb 2006 at 16:17

Changes to the value of instance variables inside a Markaby template should be transported to the layout, like it happens with regular .rhtml templates.

said on 08 Feb 2006 at 14:46

Hmm. I’m wondering about the nicest way to html-escape stuff like the decription in self << category.description ?

said on 09 Feb 2006 at 14:50

Hmm again. Is there a way to set the class dynamically that’s nicer than doing eval "span.status.#{story.status} story.status" ?

said on 09 Feb 2006 at 16:56

Thijs: Fall back to:

 span story.status, :class => "status #{story.status}" 

To html escape stuff use the text method:

 div do
   text category.description
 end

Which is identical to:

 div category.description
said on 10 Feb 2006 at 19:57

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

said on 12 Feb 2006 at 08:23

Dopey: that’s a bug! Should work ok now (as of rev 28)

said on 14 Feb 2006 at 17:52

Merci beaucoup monsieur

(I’m not actually french. I just . umm .. yeah you can see by my screename)

said on 15 Feb 2006 at 10:44
A few newbie questions: <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.
said on 15 Feb 2006 at 11:08

Maybe the first could be:

 td "#{name}#{extrainformation if condition}" 

A lot of times I’ll use RedCloth for formatting with breaks in it, italics, bold and the like.

said on 18 Feb 2006 at 06:53

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.

said on 05 Mar 2006 at 17:54

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’

said on 06 Mar 2006 at 10:57

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…

said on 21 Mar 2006 at 13:26

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

said on 30 Mar 2006 at 21:41

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.