Permalink
Browse files

first implement

  • Loading branch information...
1 parent b887cb3 commit fe300b5e625709cf3ef8b521e3b92dc4e07311f6 @xdite committed Dec 14, 2011
View
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
View
@@ -0,0 +1,6 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in bootstrap-rails.gemspec
+gemspec
+
+gem "simple_form", :require => "simple_form"
View
0 README
No changes.
View
121 README.md
@@ -0,0 +1,121 @@
+# 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;
+
+``` ruby
+gem 'bootstrap_helper'
+```
+or you can install from latest build;
+
+``` ruby
+gem 'bootstrap_helper', :git => "git://github.com/xdite/bootstrap_helper.git"
+```
+
+## USAGE
+
+
+### render_page_title
+
+#### SETUP
+
+edit your `config/application.rb `
+
+ SITENAME = "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 &raquo; 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
+
+## Example
+
+see [example](bootstrap_helper/tree/master/example/application.html.erb)
+
+## 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.
View
@@ -0,0 +1,41 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+
+desc "Update Twitter's Bootstrap"
+task "update-twitter" do
+ boostrap_version = "1.3.0"
+ Dir["vendor/assets/stylesheets/*.*"].each {|f| FileUtils.rm(f)}
+ Dir["vendor/twitter/lib/*.scss"].each do |file|
+ cp file, "vendor/assets/stylesheets/", :verbose => true
+ end
+ bootstrap_scss = File.read("vendor/assets/stylesheets/bootstrap.scss")
+
+ bootstrap_scss.gsub!(/@VERSION/, "v#{boostrap_version}")
+ bootstrap_scss.gsub!(/^.*@DATE.*/, " *")
+
+ File.open("vendor/assets/stylesheets/bootstrap.scss", "w") do |f|
+ f.write(bootstrap_scss)
+ end
+
+ Dir["vendor/assets/javascripts/*.*"].each {|f| FileUtils.rm(f)}
+ js_files = Dir["vendor/twitter/js/*.js"].map()
+ js_files.each do |file|
+ cp file, "vendor/assets/javascripts/", :verbose => true
+ end
+
+ js_priorities = {}
+ js_files.each {|f| js_priorities[File.basename(f)] = 0}
+
+ # popover depend on twipsy
+ js_priorities["bootstrap-twipsy.js"] = 1
+ js_priorities["bootstrap-popover.js"] = 2
+
+ js_list = js_priorities.to_a.sort {|a,b| a[1] <=> b[1]}.map{|p| p[0]}
+
+ File.open("vendor/assets/javascripts/bootstrap.js", "w") do |f|
+ f.write "// Bootstrap v#{boostrap_version}\n"
+ js_list.each do |js|
+ f.write "//= require #{js}\n"
+ end
+ end
+end
View
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/bootstrap_helper/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["xdite"]
+ gem.email = ["xuite.joke@gmail.com"]
+ gem.description = %q{Twitter Bootstrap HTML Helper}
+ gem.summary = %q{Twitter Bootstrap HTML Helper}
+ gem.homepage = "https://github.com/xdite/bootstrap_helper"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "bootstrap_helper"
+ gem.require_paths = ["lib"]
+ gem.version = "1.4.0"
+
+ gem.add_dependency "railties", "~> 3.0"
+ gem.add_dependency "thor", "~> 0.14"
+ gem.add_development_dependency "bundler", ">= 1.0.0"
+ gem.add_development_dependency "rails", "~> 3.0"
+end
+
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <%= render_page_title %>
+ <%= csrf_meta_tag %>
+ <%= stylesheet_link_tag "application"%>
+</head>
+<%= render_body_tag %>
+ <div class="topbar" data-dropdown="dropdown">
+ <div class="topbar-inner">
+ <div class="container">
+ <h3>
+ <a href="/"><%= Setting.app_name %></a>
+ </h3>
+ <%= 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 "common/search_form" %>
+ <%= render "common/user_navigation" %>
+ </div>
+ </div>
+ </div>
+ <div class="container">
+ <%= render_breadcrumb %>
+ <div id="main" class="container-fluid">
+ <%= notice_message %>
+ <%= yield %>
+ </div>
+ </div>
+ <footer class="footer">
+ <div class="container">
+ <%= render :partial => "common/footer" %>
+ </div>
+ </footer>
+
+ <%= javascript_include_tag "application" %>
+
+ <%= yield :page_specific_javascripts %>
+
+ <%= render :partial => "common/facebook_js" %>
+ <%= render :partial => "common/google_analytics"%>
+
+</body>
+</html>
View
@@ -0,0 +1,11 @@
+require "bootstrap_helper/version"
+
+module BootstrapHelper
+ module Rails
+ if ::Rails.version < "3.1"
+ require "bootstrap_helper/railtie"
+ else
+ require "bootstrap_helper/engine"
+ end
+ end
+end
@@ -0,0 +1,64 @@
+module BootstrapHelper
+ module Breadcrumb
+ def self.included(receiver)
+ receiver.extend ClassMethods
+ receiver.send :include, InstanceMethods
+ receiver.send :helper, Helpers
+ receiver.send :before_filter, :set_breadcrumbs
+ end
+
+ module ClassMethods
+
+ end
+
+ module InstanceMethods
+ protected
+
+ def set_breadcrumbs
+ @breadcrumbs = ["<a href='/'>Home</a>".html_safe]
+ end
+
+ def drop_breadcrumb(title=nil, url=nil)
+ title ||= @page_title
+ url ||= url_for
+ if title
+ @breadcrumbs.push("<a href=\"#{url}\">#{title}</a>".html_safe)
+ end
+ end
+
+ def drop_page_title(title)
+ @page_title = title
+ return @page_title
+ end
+
+ def no_breadcrumbs
+ @breadcrumbs = []
+ end
+ end
+
+ module Helpers
+
+ def render_breadcrumb
+ return "" if @breadcrumbs.size <= 0
+ prefix = "".html_safe
+ crumb = "".html_safe
+
+ @breadcrumbs.each_with_index do |c, i|
+ breadcrumb_class = []
+ breadcrumb_class << "first" if i == 0
+ breadcrumb_class << "last active" if i == (@breadcrumbs.length - 1)
+
+ if i == (@breadcrumbs.length - 1)
+ breadcrumb_content = c
+ else
+ breadcrumb_content = c + content_tag(:span, "/", :class => "divider")
+ end
+
+ crumb += content_tag(:li, breadcrumb_content ,:class => breadcrumb_class )
+ end
+ return prefix + content_tag(:ul, crumb, :class => "breadcrumb menu clearfix")
+ end
+ end
+ end
+
+end
@@ -0,0 +1,16 @@
+require "bootstrap_helper/helper"
+require "bootstrap_helper/breadcrumb"
+module BootstrapHelper
+ module Rails
+ class Engine < ::Rails::Engine
+ initializer "bootstrap_helper.view_helpers" do
+ ActionView::Base.send :include, BootstrapHelper::Helper
+ end
+
+ config.to_prepare do
+ ApplicationController.send :include, BootstrapHelper::Breadcrumb
+ end
+
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit fe300b5

Please sign in to comment.