New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook into page_classes helper? #145

Closed
ervasive opened this Issue Oct 26, 2011 · 10 comments

Comments

Projects
None yet
4 participants
@ervasive

ervasive commented Oct 26, 2011

Hi everybody!

Is it possible to hook custom classes into page_classes helper?

Thanks

@tdreyno

This comment has been minimized.

Show comment
Hide comment
@tdreyno

tdreyno Oct 26, 2011

Member

No, but you can always append them as usual.

<body class="<%= page_classes %> custom1 custom2">
Member

tdreyno commented Oct 26, 2011

No, but you can always append them as usual.

<body class="<%= page_classes %> custom1 custom2">

@tdreyno tdreyno closed this Oct 26, 2011

@ervasive

This comment has been minimized.

Show comment
Hide comment
@ervasive

ervasive Oct 27, 2011

Thanks, I guess it is possible to hack body classes with custom "yeld_content"

%body{ :class => page_classes + ' ' + yield_content( :pageClasses ) }

Just wanted to be sure that there is no more cleaner way.

BTW, Your support is super fast, thank you again!

ervasive commented Oct 27, 2011

Thanks, I guess it is possible to hack body classes with custom "yeld_content"

%body{ :class => page_classes + ' ' + yield_content( :pageClasses ) }

Just wanted to be sure that there is no more cleaner way.

BTW, Your support is super fast, thank you again!

@tdreyno

This comment has been minimized.

Show comment
Hide comment
@tdreyno

tdreyno Oct 27, 2011

Member

That should work exactly as you suggest. If you want, you can package that up as a helper:

helpers do
  def custom_page_classes
    page_classes + " " + yield_content(:pageClasses)
  end
end
Member

tdreyno commented Oct 27, 2011

That should work exactly as you suggest. If you want, you can package that up as a helper:

helpers do
  def custom_page_classes
    page_classes + " " + yield_content(:pageClasses)
  end
end
@ervasive

This comment has been minimized.

Show comment
Hide comment
@ervasive

ervasive Oct 27, 2011

Great, another candy feature from such a great tool.

Thanks

ervasive commented Oct 27, 2011

Great, another candy feature from such a great tool.

Thanks

@mattDaddie

This comment has been minimized.

Show comment
Hide comment
@mattDaddie

mattDaddie Nov 1, 2011

Hi all,
My folder structure is /en/index.html, so 'en_' will always be prepended to my body classes, ie en_index. Is it possible to not have the 'en_' prepended?
Thanks!

mattDaddie commented Nov 1, 2011

Hi all,
My folder structure is /en/index.html, so 'en_' will always be prepended to my body classes, ie en_index. Is it possible to not have the 'en_' prepended?
Thanks!

@tdreyno

This comment has been minimized.

Show comment
Hide comment
@tdreyno

tdreyno Nov 1, 2011

Member

The full implementation is below. Feel free to modify it and add it to the helpers section of your config.rb:

def page_classes
  path = request.path_info.dup
  path << settings.index_file if path.match(%r{/$})
  path = path.gsub(%r{^/}, '')

  classes = []
  parts = path.split('.')[0].split('/')
  parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }

  classes.join(' ')
end
Member

tdreyno commented Nov 1, 2011

The full implementation is below. Feel free to modify it and add it to the helpers section of your config.rb:

def page_classes
  path = request.path_info.dup
  path << settings.index_file if path.match(%r{/$})
  path = path.gsub(%r{^/}, '')

  classes = []
  parts = path.split('.')[0].split('/')
  parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }

  classes.join(' ')
end
@mattDaddie

This comment has been minimized.

Show comment
Hide comment
@mattDaddie

mattDaddie commented Nov 2, 2011

Thanks!

@JuanArreguin

This comment has been minimized.

Show comment
Hide comment
@JuanArreguin

JuanArreguin Jan 6, 2013

@tdreyno I've been digging through documentation and all.
And finally found something here. Here's my question.

I want to add an ID to my template .haml file — which this ID I want it to display the (if available) top folder + current file name

so for example
(root)/about/index.haml — would have an ID of "about-index"
(root)/index.haml — would have an ID of "index"

currently adding in "%html{:id => page_classes}

somewhat gets me there, it currently displays:
(root)/about/index.haml — ID "about about_index"
(root)/index.haml — ID "index"

Any solutions for this?

JuanArreguin commented Jan 6, 2013

@tdreyno I've been digging through documentation and all.
And finally found something here. Here's my question.

I want to add an ID to my template .haml file — which this ID I want it to display the (if available) top folder + current file name

so for example
(root)/about/index.haml — would have an ID of "about-index"
(root)/index.haml — would have an ID of "index"

currently adding in "%html{:id => page_classes}

somewhat gets me there, it currently displays:
(root)/about/index.haml — ID "about about_index"
(root)/index.haml — ID "index"

Any solutions for this?

@tdreyno

This comment has been minimized.

Show comment
Hide comment
@tdreyno

tdreyno Jan 6, 2013

Member

Same advice as above, take the default page_classes and make your own variation:

helpers do
  def my_page_classes
    current_resource.url.sub('.html', '').gsub('/', '-')
  end
end
Member

tdreyno commented Jan 6, 2013

Same advice as above, take the default page_classes and make your own variation:

helpers do
  def my_page_classes
    current_resource.url.sub('.html', '').gsub('/', '-')
  end
end
@JuanArreguin

This comment has been minimized.

Show comment
Hide comment
@JuanArreguin

JuanArreguin Jan 6, 2013

With a little bit of help, I ended up going this direction without having to recreate a new helper

%html{:id => page_classes.split(" ").last}

Thanks for the help and the quick reply!

JuanArreguin commented Jan 6, 2013

With a little bit of help, I ended up going this direction without having to recreate a new helper

%html{:id => page_classes.split(" ").last}

Thanks for the help and the quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment