Closed gryzzly closed 12 years ago
Thanks for the report. How big a problem is it causing you at the moment? I just had a quick scan of the code and it looks as though h1 tags are rendered using the appropriate rendering engine on the page, but that the Page#heading method returns them clean, without any modification (which is also what you're implying).
Did you mean that you "can't override it in app.rb"? If not, why not?
I'm wondering if there are some scenarios in which it would make sense for Page#heading to return a clean unmarked up version of the heading.
Hey Graham, thanks for your fast reply.
If I try to modify heading
, I need markup
and @format
to be available for me, what I get is NoMethodError at ... private method 'format' called for #<Nesta::Page:0x00000....>
.
The reason I need this is that in summaries.haml partial I print headings and modified body separately, so when I do
%h1
%a(href="#{page.abspath}")= page.heading
%div
= html_truncate( page.body, 30, ' [...]' )
I want the resulting %h1 to match the one that will be rendered on the page itself. So I want to have unified output for both. And since there is "page.title" for plain text, as an alternative, I think it should actually work like it does on the page itself (page.heading should be parsed).
Thanks!
Ah, I see what you mean with the scoping. There are ways around that but I haven't time to play just now to generate a working snippet for you. If you want to hack it, you can call a private method in Ruby with send
(e.g. send(:format)
). That is a hack though; I wouldn't recommend it under normal circumstances.
Unfortunately title isn't actually a plain text version of heading. There are good reasons to want to keep them separate, and you can actually override the page title by specifying "Title: ..." metadata at the top of your page.
In your code snippet, pass self
to the call to body
(see https://github.com/gma/nesta/blob/master/views/summaries.haml). If you don't then (should you ever decide to use it) articles written in .haml
files won't have access to the Ruby helper methods (which is often the point of using Haml).
I need to look at where Page#heading is already being used to see whether or not converting it with a rendering engine is a safe thing to do. If not, we need a new method.
What I'd do if I was you (rather than overriding the heading
method) is to make a new method called marked_up_heading
. In it I'd call heading
to get the raw text, and then convert_to_html
in order to get the HTML. Then call that in your template…
Hey, a quick note, I did really mean the title
from metadata
when I was referring to title, my point was that if somebody wants the plain text version of a "title" or "heading" whatever you call it, so he may have it in title:
metadata or parsed out of the first heading.
What I'd do if I was you (rather than overriding the heading method) is to make a new method called marked_up_heading. In it I'd call heading to get the raw text, and then convert_to_html in order to get the HTML. Then call that in your template…
But in order to properly "convert" it, I need the format again, right? So probably for now I'll have to use hacky send
?
Thanks!
I see. I just meant that the title and heading will often have different words in them, so you can't use one method in place of the other.
But in order to properly "convert" it, I need the format again, right? So probably for now I'll have to use hacky send?
Yeah, I would. Perhaps it shouldn't be private…
I'm closing this; it's a duplicate of #78.
If I have page with the following content:
The
page.heading
should return"JavaScript inheritance and <code>prototype</code> object"
. So that it will align with actual contents of yourh1
on the page. There ispage.title
that is supposed to hold plain text version of the page's title.I've tried to mess with the following code, but markup is a private property, so I can't override it in
app.rb
.Thanks!