RefineryCMS:将引导样式应用于导航菜单 [英] RefineryCMS: apply bootstrap styles to navigation menu

查看:115
本文介绍了RefineryCMS:将引导样式应用于导航菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Refinery CMS升级到最新版本(2.1.0),其中有一种新的呈现导航菜单的方法:

I have upgraded Refinery CMS to the newest version (2.1.0), where there is a new approach in rendering the navigation menu :

c $ c> _header.html.erb )

(in partial _header.html.erb)

<%= Refinery::Pages::MenuPresenter.new(refinery_menu_pages, self).to_html %>

同一部分的旧版本:

<%= render(:partial => "/refinery/menu", :locals => {
         :dom_id => 'menu',
         :css => 'menu'
       }) %>

我如何使用 MenuPresenter

推荐答案

这可以做,但解决方案不漂亮,因为Refinery 2.1中的Menu Presenter不支持所有CSS选项开箱即用。但有了一点坚持,这大致上是做什么:

It can be done, but the solution is not pretty because the Menu Presenter in Refinery 2.1 doesn't support all the right CSS options out of the box. But with a bit of perseverance, this is roughly what to do:

首先,在这里创建一个新的空白文件: config / initializers / refinery / monkey_patch_menu_presenter.rb

Firstly, create a new blank file here: config/initializers/refinery/monkey_patch_menu_presenter.rb

在此补丁文件中,粘贴菜单演示者更新版本的内容(2013年10月发布): menu_presenter.rb

In this patch file, paste in the contents of this updated version of the menu presenter (published October 2013): menu_presenter.rb

接下来,根据菜单演示者指南第5节中的说明,在您的 app / helpers / application_helper.rb 文件中,添加一个名为 navigation_menu / p>

Next, based on the instructions in section 5 of the menu presenter guide, in your app/helpers/application_helper.rb file, add a new method called navigation_menu:

def navigation_menu
  presenter = Refinery::Pages::MenuPresenter.new(refinery_menu_pages, self)
  presenter.css = "navbar-inner"
  presenter.menu_tag = :div
  presenter.list_tag_css = "nav"
  presenter.selected_css = "active"
  presenter.first_css = ""
  presenter.last_css = ""
  presenter.max_depth = 0 # prevents dropdown menus, which don't render correctly
  presenter
end

最后,在 app / views / refinery / _header.html.erb 文件 $ bundle exec rake refinery:override view = refinery / _header 如果不存在),替换以下调用:

Finally, in your app/views/refinery/_header.html.erb file (use $ bundle exec rake refinery:override view=refinery/_header if it doesn't exist), replace the call for:

<%= Refinery::Pages::MenuPresenter.new(refinery_menu_pages, self).to_html %>

其中:

<div class="navbar">
  <%= navigation_menu.to_html %>
</div>

确保您已加载Bootstrap CSS / JS文件并将整个页面包装在< div class =container> 元素。然后重新启动您的应用程序,使补丁生效,希望您会看到一个熟悉的引导导航栏。

Ensure that you have the loaded the Bootstrap CSS/JS files and have wrapped the whole page in a <div class="container"> element. Then restart your application for the patch to take affect and hopefully you'll see a familiar bootstrap navigation bar.

祝你好运!

Martyn。

这篇关于RefineryCMS:将引导样式应用于导航菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆