Coder Social home page Coder Social logo

bootstrap-helper's Introduction

Twitter Bootstrap Helper for Rails 3

Bootstrap is a toolkit from Twitter designed to kickstart development of webapps and sites. It includes base CSS and HTML for typography, forms, buttons, tables, grids, navigation, and more.

bootstrap_helper auto generates Bootstrap HTML codes.

Rails 3.1

include Bootstrap Helper in Gemfile;

gem 'bootstrap_helper', '3.2.2.0'

Rails 4.0+

or you can install from latest build;

gem 'bootstrap_helper', '4.2.2.1'

USAGE

render_page_title

SETUP

edit your config/application.rb

SITE_NAME = "YOUR SITE NAME"

in application.html.erb, replace <title> with

<%= render_page_title %> 

define page title in your action

def index
  @page_title = "Posts Index"
end

will render

<title>Posts Index | YOUR SITE NAME</title>

render_list

render_list generates ul & li, auto append: "first", "last" class . If link matches current controller and acttion, it will auto add "active" class. Perfact for "menu"

<%= render_list :class => "nav" do |li|
     li << link_to(t("menu.topics"), topics_path)
     li << link_to(t("menu.wiki"), wikis_path )
     li << link_to(t("menu.sites"), sites_path )
     li << link_to(t("menu.users"), users_path)
end %>

render_body_tag

in application.html.erb, replace <body> with

<%= render_body_tag %> 

render_body_tag auto inserts "controller name" & "action name" in to body class, and generates �IE conditional comment.

<!--[if lt IE 7 ]>
<body class="topics-controller index-action ie6"><![endif]-->
<!--[if gte IE 7 ]>
<body class="topics-controller index-action ie"><![endif]-->
<!--[if !IE]>-->
<body class="topics-controller index-action">
<!--<![endif]-->

breadcrumb

in application.html.erb, place this helper

<%= render_breadcrumb %>

drop breadcrumb in your action

def show
  @post = Posts.find(params[:id])
  drop_breadcrumb("Posts", posts_path)
  drop_breadcrumb(@post.title)
end

it will generate breadcrumb with link for you

Home / Post / YourPostTitle

notice_message

in application.html.erb, place this helper

<%= notice_message %>

write notice message in your action, will generate bootstrap style notice message

def create
  # ….
  redirect_to posts_path, :notice => "Create Success!"
end

def update
  redirect_to root_path, :flash => { :warning => "Update Success!" }
end
def no_permission
  redirect_to root_path, :flash => { :error => "no permission" }
end

Pagination

Support will_paginate, ~> 3.0.3

Markup Example

see example

Other

Form

Support simple_form, ~> 2.0.2

You can use simple_form 2.0 with bootstrap form template

<%= simple_form_for @article do |f| %>
   <%= f.input :title, :input_html => {:class => "xxlarge"} , :hint => "this is post title" %>
<% end >

Thanks

Thanks Twitter for Bootstrap http://twitter.github.com/bootstrap

Thanks Handlino for HandicraftHelper https://github.com/handlino/handicraft_helper

License

Copyright (C) 2011 by xdite

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bootstrap-helper's People

Contributors

linyiru avatar matiss avatar mingc00 avatar sebjacobs avatar wuwx avatar xdite avatar zhusee2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootstrap-helper's Issues

Support for devise

Hello
First of all, this is not a bug
but it might be annoying if someone uses this gem with Devise gem
I mean is, in the Devise gem, there timeoutable module that store its data in a flash

check this heartcombo/devise#1777

so it will show

   class = " .... alert_timedout"> true </ div>

so what if the method notice_message be like this

def notice_message
  flash_messages = []
  filtered_flash = flash.delete(:timedout)
  filtered_flash.each do |type, message|        
    type = :success if type == :notice
    text = content_tag(:div, link_to("x", "#", :class => "close", "data-dismiss" => "alert") + message, :class => "alert fade in alert-#{type}")
    flash_messages << text if message
  end
  flash_messages.join("\n").html_safe
end

or maybe you could make it more customizable

Will_paginate dependency

I'm not familiar with how this is supposed to be implemented but putting bootstrap_helper in my Gemfile is not sufficient to get will_paginate installed. Instead if I run rake -T I get this error:

no such file to load -- will_paginate/view_helpers/link_renderer

Not clear why the gem has this dependency though, maybe it can be removed or at least don't be so specific in required verion?

j3: gem list will

*** LOCAL GEMS ***


j3: gem inst will_paginate
Fetching: will_paginate-3.0.2.gem (100%)
Successfully installed will_paginate-3.0.2
1 gem installed
j3: rake -T db            
rake aborted!
no such file to load -- will_paginate/view_helpers/link_renderer

(See full trace by running task with --trace)
j3: gem list will

*** LOCAL GEMS ***

will_paginate (3.0.2)

Move to central organisation?

Hi!

I am the maintainer of three gems similar to this one that make it easier to use Twitter Bootstrap in Ruby projects (https://github.com/krautcomputing/rails-bootstrap-navbar, https://github.com/krautcomputing/bootstrap-navbar, https://github.com/krautcomputing/middleman-bootstrap-navbar).

I was thinking about moving all those gems to a separate organisation (like "bootstrap-ruby") and wanted to get some feedback from other maintainers of similar gems (and the community at large) if that makes sense and if we could use this to make it easier for people to find gems to work with Bootstrap in Ruby (Rails, Sinatra, etc.)
I think it would also invite other people to contribute to those projects if they were united in a central organisation.

What do you think?
Would you be willing to move this repo to such an organisation as well?

Breaks when not using simple_form

I'm using formtastic, not simple_form.

When I include this gem in my Gemfile, it breaks with the following:

uninitialized constant SimpleForm
/Users/kmandrup/.rvm/gems/ruby-1.9.3-p125/bundler/gems/bootstrap-helper-fc4818d80dc5/config/initializers/simple_form.rb:2:in `<top (required)>'

You should wrap this piece of the code with if defined?(SimpleForm).
I will make a fork and a pull with this fix ASAP.

alerts message

when I exec that code:

<%= notice_message %>

I got this message:

<div data-alert="alert" class="alert-message success"><a class="close" href="#">x</a><p>接口成功修改.</p></div>

alert-message should change to alert alert-success

sorry , this is my fault . because my bootstrap_helper is 1.4.1 :(

bootstrap_helper 没法与 refinerycms集成

我在集成refinerycms 2.1.0 时候发生了与Issue #12 相同的问题,Issue #12 链接里面给出的需要更改will_paginate.rb的gist貌似不太好用啊,是在自己的项目config/initializers/will_paginate.rb 里面么?

升级Rails 4.0.0.rc2提示依赖问题

Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    bootstrap_helper (~> 4.2.2.1) ruby depends on
      railties (= 4.0.0.rc1) ruby

    railties (4.0.0.rc2)

uninitialized constant WillPaginate::ActionView::LinkRenderer (NameError)

When starting server, an exception is raised:

.rvm/gems/ruby-1.9.3-p194@/gems/bootstrap_helper-2.1.0/config/initializers/will_paginate.rb:10:in <module:ActionView>': uninitialized constant WillPaginate::ActionView::LinkRenderer (NameError) from /.rvm/gems/ruby-1.9.3-p194@/gems/bootstrap_helper-2.1.0/config/initializers/will_paginate.rb:4:inmodule:WillPaginate'
from/.rvm/gems/ruby-1.9.3-p194@/gems/bootstrap_helper-2.1.0/config/initializers/will_paginate.rb:3:in <top (required)>' from /.rvm/gems/ruby-1.9.3-p194@/gems/railties-3.2.6/lib/rails/engine.rb:588:inblock (2 levels) in class:Engine'

https://gist.github.com/1214011/7ffaa86636e5b5b1fe872f9273834373c58f7ab6 should solve the bug

Tests!!!

Why there'r no tests/specs? It is impossible to refactor or improve something.

slim & haml compability

bootstrap-helper does not play nice with slim. i guess same problem may occur with haml too

关于set_breadcrumbs这个方法

是否有需要修改set_breadcrumbs方法的行为?不再强制重置@breadcrumbs,添加set_breadcrumbs!方法来做这件事:

def set_breadcrumbs
  @breadcrumbs ||= ["<a href='/'>Home</a>"]
end

def set_breadcrumbs!
  @breadcrumbs = ["<a href='/'>Home</a>"]
end
  • 由于这个before_filter方法的执行会在rails项目ApplicationController的before_filter执行之后,所以导致如需在ApplicationController中动breadcrumb的时候则会报错(还没初始化@breadcrumbs),尽管这个情况可能并不多
  • 虽然不修改这里也可以很多方法解决,如自己初始化,overwrite这个方法,在下级controller中添加skip_filter等...但我觉得这个方法的行为是有歧义的(关键是filter的执行顺序的原因会导致重置),不方便开发者灵活使用这个方法.
  • 再进一步的话,我觉得这个before_filter交由开发者决定何时引入或者何时调用会好点,其实还是很多情况这个方法是无需执行的,如非text/html请求或无须呈现html页面的请求就无必要执行这个方法.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.