Skip to content

Commit

Permalink
generators
Browse files Browse the repository at this point in the history
  • Loading branch information
logicalhan committed Mar 7, 2012
1 parent 41c24f1 commit 0f74b42
Show file tree
Hide file tree
Showing 28 changed files with 611 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
.DS_Store
Binary file modified lib/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/bootstrapped-rails/version.rb
@@ -1,5 +1,5 @@
module Bootstrapped
module Rails
VERSION = "2.0.3"
VERSION = "2.0.3.1.rc1"
end
end
53 changes: 53 additions & 0 deletions lib/generators/bootstrapped/install/install_generator.rb
@@ -0,0 +1,53 @@
require 'rails/generators'

module Bootstrapped
module Generators
class InstallGenerator < ::Rails::Generators::Base

source_root File.expand_path("../templates", __FILE__)
desc "This generator installs Twitter Bootstrap to Asset Pipeline"

def add_assets

if File.exist?('app/assets/javascripts/application.js')
insert_into_file "app/assets/javascripts/application.js", "//= require bootstrapped\n", :after => "jquery_ujs\n"
else
copy_file "application.js", "app/assets/javascripts/application.js"
end

if File.exist?('app/assets/stylesheets/application.css')
# Add our own require:
content = File.read("app/assets/stylesheets/application.css")
if content.match(/require_tree\s+\./)
# Good enough - that'll include our bootstrap_and_overrides.css.less
else
style_require_block = " *= require bootstrapped\n"
insert_into_file "app/assets/stylesheets/application.css", style_require_block, :after => "require_self\n"
end
else
copy_file "application.css", "app/assets/stylesheets/application.css"
end

end

# def add_bootstrap
# copy_file "bootstrap.coffee", "app/assets/javascripts/bootstrap.js.coffee"
# copy_file "bootstrap_and_overrides.less", "app/assets/stylesheets/bootstrap_and_overrides.css.less"
# end

# def cleanup_legacy
# # Remove old requires (if any) that included twitter/bootstrap directly:
# gsub_file("app/assets/stylesheets/application.css", %r|\s*\*=\s*twitter/bootstrap\s*\n|, "")
# gsub_file("app/assets/stylesheets/application.css", %r|\s*\*=\s*twitter/bootstrap_responsive\s*\n|, "")
# if File.exist?('app/assets/stylesheets/bootstrap_override.css.less')
# puts <<-EOM
# Warning:
# app/assets/stylesheets/bootstrap_override.css.less exists
# It should be removed, as it has been superceded by app/assets/stylesheets/bootstrap_and_overrides.css.less
# EOM
# end
# end

end
end
end
7 changes: 7 additions & 0 deletions lib/generators/bootstrapped/install/templates/application.css
@@ -0,0 +1,7 @@
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree .
*/
10 changes: 10 additions & 0 deletions lib/generators/bootstrapped/install/templates/application.js
@@ -0,0 +1,10 @@
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .
@@ -0,0 +1,4 @@
jQuery ->
$("a[rel=popover]").popover()
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()
23 changes: 23 additions & 0 deletions lib/generators/bootstrapped/layout/layout_generator.rb
@@ -0,0 +1,23 @@
require 'rails/generators'

module Bootstrappped
module Generators
class LayoutGenerator < ::Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
desc "This generator generates layout file with navigation."
argument :layout_name, :type => :string, :default => "application"
argument :layout_type, :type => :string, :default => "fixed",
:banner => "*fixed or fluid"

attr_reader :app_name, :container_class

def generate_layout
app = ::Rails.application
@app_name = app.class.to_s.split("::").first
@container_class = layout_type == "fluid" ? "container-fluid" : "container"
ext = app.config.generators.options[:rails][:template_engine] || :erb
template "layout.html.#{ext}", "app/views/layouts/#{layout_name}.html.#{ext}"
end
end
end
end
99 changes: 99 additions & 0 deletions lib/generators/bootstrapped/layout/templates/layout.html.erb
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= app_name %></title>
<%%= csrf_meta_tags %>

<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]-->

<!-- Le styles -->
<%%= stylesheet_link_tag "application", :media => "all" %>

<!-- Le fav and touch icons -->
<link href="images/favicon.ico" rel="shortcut icon">
<link href="images/apple-touch-icon.png" rel="apple-touch-icon">
<link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon" sizes="72x72">
<link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon" sizes="114x114">
</head>
<body>

<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<%- if layout_type == "fluid" -%>
<div class="container-fluid">
<%- else -%>
<div class="container">
<%- end -%>
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#"><%= app_name %></a>
<div class="<%= container_class %> nav-collapse">
<ul class="nav">
<%- (1..3).each do |i| -%>
<li><%%= link_to "Link<%= i %>", "#" %></li>
<%- end -%>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>

<div class="<%= container_class %>">
<%- if layout_type == "fluid" -%>
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Sidebar</li>
<%- (1..3).each do |i| -%>
<li><%%= link_to "Link<%= i %>", "#" %></li>
<%- end -%>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<%%= yield %>
</div>
</div><!--/row-->
<%- else -%>
<div class="content">
<div class="row">
<div class="span9">
<%%= yield %>
</div>
<div class="span3">
<div class="well sidebar-nav">
<h3>Sidebar</h3>
<ul class="nav nav-list">
<li class="nav-header">Sidebar</li>
<%- (1..3).each do |i| -%>
<li><%%= link_to "Link<%= i %>", "#" %></li>
<%- end -%>
</ul>
</div><!--/.well -->
</div><!--/span-->
</div><!--/row-->
</div><!--/content-->
<%- end -%>

<footer class='well'>
<p>&copy; Company 2012</p>
</footer>

</div> <!-- /container -->

<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<%%= javascript_include_tag "application" %>

</body>
</html>
71 changes: 71 additions & 0 deletions lib/generators/bootstrapped/layout/templates/layout.html.haml
@@ -0,0 +1,71 @@
!!! 5
%html{:lang => "en"}
%head
%meta{:charset => "utf-8"}/
%title= content_for?(:title) ? yield(:title) : "<%= app_name %>"
= csrf_meta_tags
/ Le HTML5 shim, for IE6-8 support of HTML elements
/[if lt IE 9]
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
/ Le styles
= stylesheet_link_tag "application", :media => "all"
/ Le fav and touch icons
%link{:href => "images/favicon.ico", :rel => "shortcut icon"}/
%link{:href => "images/apple-touch-icon.png", :rel => "apple-touch-icon"}/
%link{:href => "images/apple-touch-icon-72x72.png", :rel => "apple-touch-icon", :sizes => "72x72"}/
%link{:href => "images/apple-touch-icon-114x114.png", :rel => "apple-touch-icon", :sizes => "114x114"}/


%body
.navbar.navbar-fixed-top
.navbar-inner
<%- if layout_type == "fluid" -%>
.container-fluid
<%- else -%>
.container
<%- end -%>
%a.btn.btn-navbar{"data-target" => ".nav-collapse", "data-toggle" => "collapse"}
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.brand{:href => "#"}<%= app_name %>
.<%=container_class%>.nav-collapse
%ul.nav
%li= link_to "Link 1", "/path1"
%li= link_to "Link 2", "/path2"
%li= link_to "Link 3", "/path3"

.<%= container_class %>
<%- if layout_type == "fluid" -%>

.row-fluid
.span3
.well.sidebar-nav
%ul.nav.nav-list
%li.nav-header Sidebar
%li= link_to "Link 1", "/path1"
%li= link_to "Link 2", "/path2"
%li= link_to "Link 3", "/path3"
.span9
= yield
<% else %>
.content
.row
.span9
= yield
.span3
.well.sidebar-nav
%h3 Sidebar
%ul.nav.nav-list
%li.nav-header Sidebar
%li= link_to "Link 1", "/path1"
%li= link_to "Link 2", "/path2"
%li= link_to "Link 3", "/path3"
<% end %>
%footer.well
%p &copy; Company 2012
/
Le javascript
\==================================================
/ Placed at the end of the document so the pages load faster
= javascript_include_tag "application"
72 changes: 72 additions & 0 deletions lib/generators/bootstrapped/layout/templates/layout.html.slim
@@ -0,0 +1,72 @@
doctype html
html lang="en"
head
meta charset="utf-8"
title= content_for?(:title) ? yield(:title) : "<%= app_name %>"
= csrf_meta_tags

/! Le HTML5 shim, for IE6-8 support of HTML elements
/[if lt IE 9]
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
/! Le styles
= stylesheet_link_tag "application", :media => "all"
/ Le fav and touch icons
link href="images/favicon.ico" rel="shortcut icon"
link href="images/apple-touch-icon.png" rel="apple-touch-icon"
link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon" sizes="72x72"
link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon" sizes="114x114"


body
.navbar.navbar-fixed-top
.navbar-inner
<%- if layout_type == "fluid" -%>
.container-fluid
<%- else -%>
.container
<%- end -%>
a.btn.btn-navbar data-target=".nav-collapse" data-toggle="collapse"
span.icon-bar
span.icon-bar
span.icon-bar
a.brand href="#"<%= app_name %>
.<%=container_class%>.nav-collapse
ul.nav
li= link_to "Link 1", "/path1"
li= link_to "Link 2", "/path2"
li= link_to "Link 3", "/path3"

.<%= container_class %>
<%- if layout_type == "fluid" -%>

.row-fluid
.span3
.well.sidebar-nav
ul.nav.nav-list
li.nav-header Sidebar
li= link_to "Link 1", "/path1"
li= link_to "Link 2", "/path2"
li= link_to "Link 3", "/path3"
.span9
= yield
<% else %>
.content
.row
.span9
= yield
.span3
.well.sidebar-nav
h3 Sidebar
ul.nav.nav-list
li.nav-header Sidebar
li= link_to "Link 1", "/path1"
li= link_to "Link 2", "/path2"
li= link_to "Link 3", "/path3"
<% end %>
footer.well
p &copy; Company 2012
/!
Le javascript
\==================================================
/! Placed at the end of the document so the pages load faster
= javascript_include_tag "application"
19 changes: 19 additions & 0 deletions lib/generators/bootstrapped/themed/templates/_form.html.erb
@@ -0,0 +1,19 @@
<%%= form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f| %>
<fieldset>
<legend><%%= controller.action_name.capitalize %> <%= model_name.titleize %></legend>

<%- columns.each do |column| -%>
<div class="control-group">
<%%= f.label :<%= column.name %>, :class => 'control-label' %>
<div class="controls">
<%%= f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>' %>
</div>
</div>

<%- end -%>
<div class="form-actions">
<%%= f.submit nil, :class => 'btn btn-primary' %>
<%%= link_to 'Cancel', <%= controller_routing_path %>_path, :class => 'btn' %>
</div>
</fieldset>
<%% end %>
13 changes: 13 additions & 0 deletions lib/generators/bootstrapped/themed/templates/_form.html.haml
@@ -0,0 +1,13 @@
%fieldset
%legend
= controller.action_name.capitalize
<%= model_name.titleize %>
<%- columns.each do |column| -%>
.control-group
= f.label :<%= column.name %>, :class => 'control-label'
.controls
= f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>'
<%- end -%>
.form-actions
= f.submit nil, :class => 'btn btn-primary'
= link_to "Cancel", <%= controller_routing_path %>_path, :class => 'btn'

0 comments on commit 0f74b42

Please sign in to comment.