4 | Dummy
5 | <%= stylesheet_link_tag "application", :media => "all" %>
6 | <%= javascript_include_tag "application" %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/helpers/accordion_helper.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers::Helpers::AccordionHelper
2 | # Renders a Bootstrap accordion.
3 | #
4 | # @param [String] an ID that is unique for the page
5 | def accordion (id, &block)
6 | RailsBootstrapHelpers::Renderers::AccordionRenderer.new(self, id, &block).render
7 | end
8 | end
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/renderers/row_link_renderer.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers::Renderers
2 | class RowLinkRenderer < AbstractLinkRenderer
3 | def initialize (template, *args, &block)
4 | super template, :link, *args, &block
5 | end
6 |
7 | def render
8 | append_class "rowlink"
9 | super
10 | end
11 | end
12 | end
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/renderers/renderer.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers::Renderers
2 | class Renderer
3 | abstract :render
4 | attr_reader :template
5 |
6 | def initialize (template)
7 | @template = template
8 | end
9 |
10 | def method_missing (*args, &block)
11 | @template.send(*args, &block)
12 | end
13 | end
14 | end
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4 |
5 | # Use the database for sessions instead of the cookie-based default,
6 | # which shouldn't be used to store highly confidential information
7 | # (create the session table with "rails generate session_migration")
8 | # Dummy::Application.config.session_store :active_record_store
9 |
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/renderers/action_link_renderer.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers::Renderers
2 | class ActionLinkRenderer < AbstractLinkRenderer
3 | def initialize (template, *args, &block)
4 | super template, :link, *args, &block
5 | end
6 |
7 | def render
8 | append_class "act"
9 |
10 | if style = has_option?("style")
11 | unless style.to_s == "default"
12 | append_class "act-" + style.to_s
13 | end
14 | end
15 |
16 | super
17 | end
18 | end
19 | end
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require "rubygems"
2 | require "spork"
3 |
4 | Spork.prefork do
5 | ENV["RAILS_ENV"] ||= 'test'
6 | require File.expand_path("../dummy/config/environment", __FILE__)
7 |
8 | require "rspec/rails"
9 | require "rspec/autorun"
10 | require "pry"
11 |
12 | Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
13 |
14 | RSpec.configure do |config|
15 | config.order = "random"
16 | config.include Html
17 | end
18 | end
19 |
20 | Spork.each_run do
21 | require "rails-bootstrap-helpers"
22 | end
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 | # Make sure the secret is at least 30 characters and all random,
6 | # no regular words or you'll be exposed to dictionary attacks.
7 | Dummy::Application.config.secret_token = '4d1f9a7946f979c24d8bd58214f498094ca9eea099ac67c75c99f0d2caf1d87c36b03ae78e1b7e9ea534703e9bb099fd3f51afcb2c68971cbc6cc3351557a3c4'
8 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | #
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # Disable root element in JSON by default.
12 | ActiveSupport.on_load(:active_record) do
13 | self.include_root_in_json = false
14 | end
15 |
--------------------------------------------------------------------------------
/spec/helpers/tag_helper_spec.rb:
--------------------------------------------------------------------------------
1 | require "spec_helper"
2 |
3 | describe RailsBootstrapHelpers::Helpers::TagHelper do
4 | describe "bs_content_tag" do
5 | it "should render an HTML tag" do
6 | expected_html = <<-eos
7 |
8 |
9 | foo
10 |
11 | bar
12 |
13 | eos
14 |
15 | html = bs_content_tag :div, id: "foo" do
16 | bs_content_tag :div do
17 | append "foo"
18 | end
19 |
20 | append "bar"
21 | end
22 |
23 | html.should == expected_html
24 | end
25 | end
26 | end
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format
4 | # (all these examples are active by default):
5 | # ActiveSupport::Inflector.inflections do |inflect|
6 | # inflect.plural /^(ox)$/i, '\1en'
7 | # inflect.singular /^(ox)en/i, '\1'
8 | # inflect.irregular 'person', 'people'
9 | # inflect.uncountable %w( fish sheep )
10 | # end
11 | #
12 | # These inflection rules are supported but not enabled by default:
13 | # ActiveSupport::Inflector.inflections do |inflect|
14 | # inflect.acronym 'RESTful'
15 | # end
16 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the top of the
9 | * compiled file, but it's generally better to create a new file per style scope.
10 | *
11 | *= require_self
12 | *= require_tree .
13 | */
14 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "http://rubygems.org"
2 |
3 | # Declare your gem's dependencies in rails-bootstrap-helpers.gemspec.
4 | # Bundler will treat runtime dependencies like base dependencies, and
5 | # development dependencies will be added by default to the :development group.
6 | gemspec
7 |
8 | # jquery-rails is used by the dummy application
9 | gem "jquery-rails"
10 |
11 | # Declare any dependencies that are still in development here instead of in
12 | # your gemspec. These might include edge Rails or gems from your path or
13 | # Git. Remember to move these dependencies to your gemspec before releasing
14 | # your gem to rubygems.org.
15 |
16 | # To use debugger
17 | # gem 'debugger'
18 |
--------------------------------------------------------------------------------
/Guardfile:
--------------------------------------------------------------------------------
1 | # A sample Guardfile
2 | # More info at https://github.com/guard/guard#readme
3 |
4 | guard "spork", :rspec_env => { "RAILS_ENV" => "test" } do
5 | watch("config/application.rb")
6 | watch("config/environment.rb")
7 | watch("config/environments/test.rb")
8 | watch(%r{^config/initializers/.+\.rb$})
9 | watch("Gemfile")
10 | watch("Gemfile.lock")
11 | watch("spec/spec_helper.rb") { :rspec }
12 | end
13 |
14 | guard "rspec", :cli => "--color --drb", :version => 2 do
15 | watch(%r{^spec/.+_spec\.rb$})
16 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
17 | watch("spec/spec_helper.rb") { "spec" }
18 | watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
19 | end
--------------------------------------------------------------------------------
/spec/dummy/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | development:
7 | adapter: sqlite3
8 | database: db/development.sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | # Warning: The database defined as "test" will be erased and
13 | # re-generated from your development database when you run "rake".
14 | # Do not set this db to the same as development or production.
15 | test:
16 | adapter: sqlite3
17 | database: db/test.sqlite3
18 | pool: 5
19 | timeout: 5000
20 |
21 | production:
22 | adapter: sqlite3
23 | database: db/production.sqlite3
24 | pool: 5
25 | timeout: 5000
26 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // the compiled file.
9 | //
10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11 | // GO AFTER THE REQUIRES BELOW.
12 | //
13 | //= require jquery
14 | //= require jquery_ujs
15 | //= require_tree .
16 |
--------------------------------------------------------------------------------
/spec/dummy/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
We're sorry, but something went wrong.
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/helpers/tag_helper.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers::Helpers::TagHelper
2 | # Returns an HTML block tag. Properly adds indentation and newlines for the
3 | # returned HTML.
4 | #
5 | # ==== Example
6 | # bs_content_tag "div", id: "foo" do
7 | # bs_content_tag "div"
8 | # append "foo"
9 | # end
10 | #
11 | # append "bar"
12 | # end
13 | #
14 | #
15 | #
16 | # foo
17 | #
18 | # bar
19 | #
20 | #
21 | # @param [String] the name of the tag to render
22 | # @param [Hash] a hash of HTML attributes
23 | def bs_content_tag (name, options = {}, &block)
24 | RailsBootstrapHelpers::Renderers::ContentTagRenderer.new(self, name, options, &block).render
25 | end
26 | end
--------------------------------------------------------------------------------
/spec/dummy/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The change you wanted was rejected.
23 |
Maybe you tried to change something you didn't have access to.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/dummy/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The page you were looking for doesn't exist.
23 |
You may have mistyped the address or the page may have moved.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/helpers/navigation_helper.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers::Helpers::NavigationHelper
2 | include RailsBootstrapHelpers::Helpers::OptionsHelper
3 |
4 | # Renders a Bootstrap tabbable navigation.
5 | #
6 | # @param args [Array, Hash] an array of the names of the tab items.
7 | # If the last item is a Hash it's considered to be the options.
8 | #
9 | # @option options [Boolean] :bordered (false) if true, will render the tab
10 | # container with a border. This option requires the Jasny Bootstrap extensions.
11 | #
12 | # @option option [Bootstrap] :fade (false) if true, will add the "fade in"
13 | # class to all tab panes. This requires the bootstrap-transition.js file.
14 | def tabbable (*args, &block)
15 | RailsBootstrapHelpers::Renderers::TabbableRenderer.new(self, *args, &block).render
16 | end
17 | end
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rake
2 | begin
3 | require 'bundler/setup'
4 | rescue LoadError
5 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6 | end
7 | begin
8 | require 'rdoc/task'
9 | rescue LoadError
10 | require 'rdoc/rdoc'
11 | require 'rake/rdoctask'
12 | RDoc::Task = Rake::RDocTask
13 | end
14 |
15 | RDoc::Task.new(:rdoc) do |rdoc|
16 | rdoc.rdoc_dir = 'rdoc'
17 | rdoc.title = 'RailsBootstrapHelpers'
18 | rdoc.options << '--line-numbers'
19 | rdoc.rdoc_files.include('README.rdoc')
20 | rdoc.rdoc_files.include('lib/**/*.rb')
21 | end
22 |
23 |
24 |
25 |
26 | Bundler::GemHelper.install_tasks
27 |
28 | require 'rake/testtask'
29 |
30 | Rake::TestTask.new(:test) do |t|
31 | t.libs << 'lib'
32 | t.libs << 'test'
33 | t.pattern = 'test/**/*_test.rb'
34 | t.verbose = false
35 | end
36 |
37 |
38 | task :default => :test
39 |
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/helpers/url_helper.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers::Helpers::UrlHelper
2 | # Renders a Jasny Bootstrap action link. This method behaves just as "link_to"
3 | # but will render a Jasny Bootstrap action link instead of a regular link.
4 | # In addition to the options "link_to" handles, this method also handles the
5 | # following options:
6 | #
7 | # @option options [String, Symbol] :style the style of the link
8 | def action_link_to (*args, &block)
9 | RailsBootstrapHelpers::Renderers::ActionLinkRenderer.new(self, *args, &block).render
10 | end
11 |
12 | # Renders a Jasny Bootstrap row link. This method behaves just as "link_to"
13 | # but will render a Jasny Bootstrap row link instead of a regular link.
14 | def row_link_to (*args, &block)
15 | RailsBootstrapHelpers::Renderers::RowLinkRenderer.new(self, *args, &block).render
16 | end
17 | end
--------------------------------------------------------------------------------
/changelog.md:
--------------------------------------------------------------------------------
1 | # Rails Bootstrap Helpers
2 |
3 | ## Version 0.1.0
4 |
5 | ### New/Changed Features
6 | * Renamed option "placement" to "position" for `bs_popover_button`
7 | * Add new form tag helper `bs_submit_tag`
8 | * Add new button `bs_collapsible_button`
9 | * Add new tag helper `bs_content_tag`
10 | * Add new helper `accordion`
11 | * Add new options helper `append_class!`
12 | * Add new button helper `button_group`
13 | * Add support for tooltips to button helpers
14 | * Add new helper `action_link_to`
15 | * Add new helper `iconic_icon`
16 | * Add new helper `row_link_to`
17 | * Add new tabbable navigation helper `tabbable`
18 | * Add "inline" HTML class to inline buttons
19 | * Add new dropdown button helper `bs_dropdown_button_to`
20 |
21 | ### Bugs Fixed
22 | * "class" option not being passed through button helpers
23 | * "class" option not being passed through icon helper
24 |
25 | ## Version 0.0.1
26 | ### New/Changed Features
27 | * Initial releases
--------------------------------------------------------------------------------
/lib/rails-bootstrap-helpers/rails/engine.rb:
--------------------------------------------------------------------------------
1 | module RailsBootstrapHelpers
2 | module Rails
3 | class Engine < ::Rails::Engine
4 | initializer "rails-bootstrap-helpers.helpers" do
5 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::AccordionHelper
6 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::UrlHelper
7 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::AlertHelper
8 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::BaseHelper
9 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::ButtonHelper
10 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::FormTagHelper
11 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::LabelHelper
12 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::TagHelper
13 | ActionView::Base.send :include, RailsBootstrapHelpers::Helpers::NavigationHelper
14 | end
15 | end
16 | end
17 | end
--------------------------------------------------------------------------------
/spec/helpers/accordion_helper_spec.rb:
--------------------------------------------------------------------------------
1 | require "spec_helper"
2 |
3 | describe RailsBootstrapHelpers::Helpers::AccordionHelper do
4 | describe "accordion" do
5 | it "should render an accordion" do
6 | expected_html = <<-eos
7 |
91 | eos
92 |
93 | strip_expected(html)
94 | end
95 |
96 | it "should render a tabbable navigation with fade" do
97 | html = tabbable(foo_tab_text, fade: true, &block)
98 | strip(html).should == expected_html
99 | end
100 | end
101 |
102 | context "with active" do
103 | it "should render the specified tabs and tab panes as active" do
104 | expected_html = <<-eos
105 |
121 | eos
122 |
123 | expected_html = strip_expected(expected_html)
124 |
125 | html = tabbable do |bar|
126 | bar.tab foo_tab_text
127 | bar.tab bar_tab_text, active: true
128 |
129 | bar.tab_pane do
130 | "foo content"
131 | end
132 |
133 | bar.tab_pane active: true do
134 | "bar content"
135 | end
136 | end
137 |
138 | strip(html).should == expected_html
139 | end
140 |
141 | it "should render none of the tabs or tab panes as active if ':active' is set to 'false'" do
142 | expected_html = <<-eos
143 |
159 | eos
160 |
161 | expected_html = strip_expected(expected_html)
162 |
163 | html = tabbable do |bar|
164 | bar.tab foo_tab_text
165 | bar.tab bar_tab_text, active: false
166 |
167 | bar.tab_pane do
168 | "foo content"
169 | end
170 |
171 | bar.tab_pane active: false do
172 | "bar content"
173 | end
174 | end
175 |
176 | strip(html).should == expected_html
177 | end
178 | end
179 |
180 | context "with direction" do
181 | context "unspecified" do
182 | let(:html_class) { "tabbable" }
183 |
184 | it "should render a tabbable navigation with the tabs on top" do
185 | html = tabbable(foo_tab_text, &block)
186 | strip(html).should == expected_html
187 | end
188 | end
189 |
190 | context "top" do
191 | let(:html_class) { "tabbable" }
192 |
193 | it "should render a tabbable navigation with the tabs on top" do
194 | html = tabbable(foo_tab_text, direction: "top", &block)
195 | strip(html).should == expected_html
196 | end
197 | end
198 |
199 | context "bottom" do
200 | let(:html_class) { "tabbable tabs-below" }
201 |
202 | it "should render a tabbable navigation with the tabs on the bottom" do
203 | html = tabbable(foo_tab_text, direction: "below", &block)
204 | strip(html).should == expected_html
205 | end
206 | end
207 |
208 | context "left" do
209 | let(:html_class) { "tabbable tabs-left" }
210 |
211 | it "should render a tabbable navigation with the tabs on the left" do
212 | html = tabbable(foo_tab_text, direction: "left", &block)
213 | strip(html).should == expected_html
214 | end
215 | end
216 |
217 | context "right" do
218 | let(:html_class) { "tabbable tabs-right" }
219 |
220 | it "should render a tabbable navigation with the tabs on the right" do
221 | html = tabbable(foo_tab_text, direction: "right", &block)
222 | strip(html).should == expected_html
223 | end
224 | end
225 | end
226 | end
227 | end
228 | end
--------------------------------------------------------------------------------
/spec/dummy/README.rdoc:
--------------------------------------------------------------------------------
1 | == Welcome to Rails
2 |
3 | Rails is a web-application framework that includes everything needed to create
4 | database-backed web applications according to the Model-View-Control pattern.
5 |
6 | This pattern splits the view (also called the presentation) into "dumb"
7 | templates that are primarily responsible for inserting pre-built data in between
8 | HTML tags. The model contains the "smart" domain objects (such as Account,
9 | Product, Person, Post) that holds all the business logic and knows how to
10 | persist themselves to a database. The controller handles the incoming requests
11 | (such as Save New Account, Update Product, Show Post) by manipulating the model
12 | and directing data to the view.
13 |
14 | In Rails, the model is handled by what's called an object-relational mapping
15 | layer entitled Active Record. This layer allows you to present the data from
16 | database rows as objects and embellish these data objects with business logic
17 | methods. You can read more about Active Record in
18 | link:files/vendor/rails/activerecord/README.html.
19 |
20 | The controller and view are handled by the Action Pack, which handles both
21 | layers by its two parts: Action View and Action Controller. These two layers
22 | are bundled in a single package due to their heavy interdependence. This is
23 | unlike the relationship between the Active Record and Action Pack that is much
24 | more separate. Each of these packages can be used independently outside of
25 | Rails. You can read more about Action Pack in
26 | link:files/vendor/rails/actionpack/README.html.
27 |
28 |
29 | == Getting Started
30 |
31 | 1. At the command prompt, create a new Rails application:
32 | rails new myapp (where myapp is the application name)
33 |
34 | 2. Change directory to myapp and start the web server:
35 | cd myapp; rails server (run with --help for options)
36 |
37 | 3. Go to http://localhost:3000/ and you'll see:
38 | "Welcome aboard: You're riding Ruby on Rails!"
39 |
40 | 4. Follow the guidelines to start developing your application. You can find
41 | the following resources handy:
42 |
43 | * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44 | * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45 |
46 |
47 | == Debugging Rails
48 |
49 | Sometimes your application goes wrong. Fortunately there are a lot of tools that
50 | will help you debug it and get it back on the rails.
51 |
52 | First area to check is the application log files. Have "tail -f" commands
53 | running on the server.log and development.log. Rails will automatically display
54 | debugging and runtime information to these files. Debugging info will also be
55 | shown in the browser on requests from 127.0.0.1.
56 |
57 | You can also log your own messages directly into the log file from your code
58 | using the Ruby logger class from inside your controllers. Example:
59 |
60 | class WeblogController < ActionController::Base
61 | def destroy
62 | @weblog = Weblog.find(params[:id])
63 | @weblog.destroy
64 | logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65 | end
66 | end
67 |
68 | The result will be a message in your log file along the lines of:
69 |
70 | Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71 |
72 | More information on how to use the logger is at http://www.ruby-doc.org/core/
73 |
74 | Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75 | several books available online as well:
76 |
77 | * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78 | * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79 |
80 | These two books will bring you up to speed on the Ruby language and also on
81 | programming in general.
82 |
83 |
84 | == Debugger
85 |
86 | Debugger support is available through the debugger command when you start your
87 | Mongrel or WEBrick server with --debugger. This means that you can break out of
88 | execution at any point in the code, investigate and change the model, and then,
89 | resume execution! You need to install ruby-debug to run the server in debugging
90 | mode. With gems, use sudo gem install ruby-debug. Example:
91 |
92 | class WeblogController < ActionController::Base
93 | def index
94 | @posts = Post.all
95 | debugger
96 | end
97 | end
98 |
99 | So the controller will accept the action, run the first line, then present you
100 | with a IRB prompt in the server window. Here you can do things like:
101 |
102 | >> @posts.inspect
103 | => "[#nil, "body"=>nil, "id"=>"1"}>,
105 | #"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107 | >> @posts.first.title = "hello from a debugger"
108 | => "hello from a debugger"
109 |
110 | ...and even better, you can examine how your runtime objects actually work:
111 |
112 | >> f = @posts.first
113 | => #nil, "body"=>nil, "id"=>"1"}>
114 | >> f.
115 | Display all 152 possibilities? (y or n)
116 |
117 | Finally, when you're ready to resume execution, you can enter "cont".
118 |
119 |
120 | == Console
121 |
122 | The console is a Ruby shell, which allows you to interact with your
123 | application's domain model. Here you'll have all parts of the application
124 | configured, just like it is when the application is running. You can inspect
125 | domain models, change values, and save to the database. Starting the script
126 | without arguments will launch it in the development environment.
127 |
128 | To start the console, run rails console from the application
129 | directory.
130 |
131 | Options:
132 |
133 | * Passing the -s, --sandbox argument will rollback any modifications
134 | made to the database.
135 | * Passing an environment name as an argument will load the corresponding
136 | environment. Example: rails console production.
137 |
138 | To reload your controllers and models after launching the console run
139 | reload!
140 |
141 | More information about irb can be found at:
142 | link:http://www.rubycentral.org/pickaxe/irb.html
143 |
144 |
145 | == dbconsole
146 |
147 | You can go to the command line of your database directly through rails
148 | dbconsole. You would be connected to the database with the credentials
149 | defined in database.yml. Starting the script without arguments will connect you
150 | to the development database. Passing an argument will connect you to a different
151 | database, like rails dbconsole production. Currently works for MySQL,
152 | PostgreSQL and SQLite 3.
153 |
154 | == Description of Contents
155 |
156 | The default directory structure of a generated Ruby on Rails application:
157 |
158 | |-- app
159 | | |-- assets
160 | | | |-- images
161 | | | |-- javascripts
162 | | | `-- stylesheets
163 | | |-- controllers
164 | | |-- helpers
165 | | |-- mailers
166 | | |-- models
167 | | `-- views
168 | | `-- layouts
169 | |-- config
170 | | |-- environments
171 | | |-- initializers
172 | | `-- locales
173 | |-- db
174 | |-- doc
175 | |-- lib
176 | | |-- assets
177 | | `-- tasks
178 | |-- log
179 | |-- public
180 | |-- script
181 | |-- test
182 | | |-- fixtures
183 | | |-- functional
184 | | |-- integration
185 | | |-- performance
186 | | `-- unit
187 | |-- tmp
188 | | `-- cache
189 | | `-- assets
190 | `-- vendor
191 | |-- assets
192 | | |-- javascripts
193 | | `-- stylesheets
194 | `-- plugins
195 |
196 | app
197 | Holds all the code that's specific to this particular application.
198 |
199 | app/assets
200 | Contains subdirectories for images, stylesheets, and JavaScript files.
201 |
202 | app/controllers
203 | Holds controllers that should be named like weblogs_controller.rb for
204 | automated URL mapping. All controllers should descend from
205 | ApplicationController which itself descends from ActionController::Base.
206 |
207 | app/models
208 | Holds models that should be named like post.rb. Models descend from
209 | ActiveRecord::Base by default.
210 |
211 | app/views
212 | Holds the template files for the view that should be named like
213 | weblogs/index.html.erb for the WeblogsController#index action. All views use
214 | eRuby syntax by default.
215 |
216 | app/views/layouts
217 | Holds the template files for layouts to be used with views. This models the
218 | common header/footer method of wrapping views. In your views, define a layout
219 | using the layout :default and create a file named default.html.erb.
220 | Inside default.html.erb, call <% yield %> to render the view using this
221 | layout.
222 |
223 | app/helpers
224 | Holds view helpers that should be named like weblogs_helper.rb. These are
225 | generated for you automatically when using generators for controllers.
226 | Helpers can be used to wrap functionality for your views into methods.
227 |
228 | config
229 | Configuration files for the Rails environment, the routing map, the database,
230 | and other dependencies.
231 |
232 | db
233 | Contains the database schema in schema.rb. db/migrate contains all the
234 | sequence of Migrations for your schema.
235 |
236 | doc
237 | This directory is where your application documentation will be stored when
238 | generated using rake doc:app
239 |
240 | lib
241 | Application specific libraries. Basically, any kind of custom code that
242 | doesn't belong under controllers, models, or helpers. This directory is in
243 | the load path.
244 |
245 | public
246 | The directory available for the web server. Also contains the dispatchers and the
247 | default HTML files. This should be set as the DOCUMENT_ROOT of your web
248 | server.
249 |
250 | script
251 | Helper scripts for automation and generation.
252 |
253 | test
254 | Unit and functional tests along with fixtures. When using the rails generate
255 | command, template test files will be generated for you and placed in this
256 | directory.
257 |
258 | vendor
259 | External libraries that the application depends on. Also includes the plugins
260 | subdirectory. If the app has frozen rails, those gems also go here, under
261 | vendor/rails/. This directory is in the load path.
262 |
--------------------------------------------------------------------------------
/spec/helpers/button_helper_spec.rb:
--------------------------------------------------------------------------------
1 | require "spec_helper"
2 |
3 | describe RailsBootstrapHelpers::Helpers::ButtonHelper do
4 | let(:html_attributes) do
5 | attributes.map{ |k, v| "#{k}=\"#{v}\"" }.join(" ")
6 | end
7 |
8 | let(:html) { "foo" }
9 |
10 | describe "bs_button_to" do
11 | context "with url" do
12 | it { should render_bs_button_to("foo").to("bar") }
13 | end
14 |
15 | context "with style" do
16 | it { should render_bs_button_to("foo") }
17 | it { should render_bs_button_to("foo").with_style(:default) }
18 | it { should render_bs_button_to("foo").with_style(:primary) }
19 | it { should render_bs_button_to("foo").with_style(:info) }
20 | it { should render_bs_button_to("foo").with_style(:success) }
21 | it { should render_bs_button_to("foo").with_style(:warning) }
22 | it { should render_bs_button_to("foo").with_style(:danger) }
23 | it { should render_bs_button_to("foo").with_style(:inverse) }
24 | it { should render_bs_button_to("foo").with_style(:link) }
25 | end
26 |
27 | context "with size" do
28 | it { should render_bs_button_to("foo").with_size(:default) }
29 | it { should render_bs_button_to("foo").with_size(:large) }
30 | it { should render_bs_button_to("foo").with_size(:small) }
31 | it { should render_bs_button_to("foo").with_size(:mini) }
32 | end
33 |
34 | context "with icon" do
35 | it { should render_bs_button_to("foo").with_icon(:ok) }
36 | it { should render_bs_button_to("foo").with_icon(:edit) }
37 | it { should render_bs_button_to("foo").with_icon(:none) }
38 | end
39 |
40 | context "with inverted icon" do
41 | it { should render_bs_button_to("foo").with_icon(:ok).with_icon_inverted(true) }
42 | it { should render_bs_button_to("foo").with_icon(:edit).with_icon_inverted(true) }
43 | end
44 |
45 | context "with icon position" do
46 | it { should render_bs_button_to("foo").with_icon_position(:default) }
47 | it { should render_bs_button_to("foo").with_icon_position(:left) }
48 | it { should render_bs_button_to("foo").with_icon_position(:right) }
49 | end
50 |
51 | context "with custom class attribute" do
52 | it { should render_bs_button_to("foo").with_class("bar") }
53 | end
54 |
55 | context "with tooltip" do
56 | it { should render_bs_button_to("foo").with_tooltip("asd") }
57 | it { should render_bs_button_to("foo").with_tooltip("asd").with_tooltip_position(:left) }
58 | end
59 | end
60 |
61 | describe "bs_inline_button_to" do
62 | it { should render_inline_button_to("foo", "edit") }
63 |
64 | context "with size" do
65 | it { should render_inline_button_to("foo", "edit").with_size(:large) }
66 | it { should render_inline_button_to("foo", "edit").with_size(:small) }
67 | it { should render_inline_button_to("foo", "edit").with_size(:mini) }
68 | end
69 | end
70 |
71 | describe "bs_popover_button" do
72 | let(:attributes) do
73 | {
74 | href: '#',
75 | class: "btn",
76 | :"data-content" => "bar",
77 | :"data-placement" => "bottom",
78 | :"data-toggle" => "popover"
79 | }
80 | end
81 |
82 | it "should render a button with a popover" do
83 | helper.bs_popover_button("foo", "bar").should == html
84 | end
85 |
86 | context "render popover using block" do
87 | it "should render a button with a popover" do
88 | helper.bs_popover_button("foo") { "bar" }.should == html
89 | end
90 | end
91 |
92 | context "with custom placement" do
93 | it "should render a button with a popover" do
94 | attributes[:"data-placement"] = "top"
95 | helper.bs_popover_button("foo", "bar", position: "top").should == html
96 | end
97 | end
98 |
99 | context "with deprecated options" do
100 | it "should render a button with a popover" do
101 | attributes[:"data-placement"] = "top"
102 | helper.bs_popover_button("foo", "bar", placement: "top").should == html
103 | end
104 | end
105 | end
106 |
107 | describe "bs_collapsible_button" do
108 | let(:attributes) do
109 | {
110 | class: "btn",
111 | :"data-target" => "bar",
112 | :"data-toggle" => "collapse",
113 | name: "button",
114 | type: "button"
115 | }
116 | end
117 |
118 | let(:html) { "" }
119 |
120 | it "should render a button with a collapsible" do
121 | helper.bs_collapsible_button("foo", "bar").should == html
122 | end
123 |
124 | context "with style" do
125 | it "should render a collapsible button with the proper style" do
126 | attributes[:class] = "btn btn-primary"
127 | helper.bs_collapsible_button("foo", "bar", style: "primary").should == html
128 | end
129 | end
130 | end
131 |
132 | describe "button_group" do
133 | it "should render a button group" do
134 | content = helper.button_group do
135 | "asd"
136 | end
137 |
138 | content.should == '
asd
'
139 | end
140 |
141 | context "vertical button group" do
142 | it "should render a vertical button group" do
143 | content = helper.button_group vertical: true do
144 | "asd"
145 | end
146 |
147 | content.should == '
asd
'
148 | end
149 | end
150 |
151 | context "toolbar button group" do
152 | it "should render a toolbar button group" do
153 | content = helper.button_group toolbar: true do
154 | "asd"
155 | end
156 |
157 | content.should == '
asd
'
158 | end
159 | end
160 | end
161 |
162 | describe "bs_dropdown_button_to" do
163 | let(:expected_html) do
164 | html = <<-eos
165 |
228 | eos
229 |
230 | strip_expected(html)
231 | end
232 |
233 | it "should render a dropdown button with an icon" do
234 | html = bs_dropdown_button_to "foo", icon: "search" do
235 | content_tag(:li, link_to("bar", "http://www.google.com")) +
236 | content_tag(:li, link_to("baz", "http://www.wikipedia.org"))
237 | end
238 |
239 | strip(html).should == expected_html
240 | end
241 | end
242 |
243 | context "with link and icon" do
244 | let(:expected_html) do
245 | html = <<-eos
246 |
256 | eos
257 |
258 | strip_expected(html)
259 | end
260 |
261 | it "should render a split dropdown button with an icon" do
262 | html = bs_dropdown_button_to "foo", "https://github.com", icon: "search" do
263 | content_tag(:li, link_to("bar", "http://www.google.com")) +
264 | content_tag(:li, link_to("baz", "http://www.wikipedia.org"))
265 | end
266 |
267 | strip(html).should == expected_html
268 | end
269 | end
270 |
271 | context "with link and style" do
272 | let(:expected_html) do
273 | html = <<-eos
274 |
284 | eos
285 |
286 | strip_expected(html)
287 | end
288 |
289 | it "should render a split dropdown button with the success style" do
290 | html = bs_dropdown_button_to "foo", "https://github.com", style: "success" do
291 | content_tag(:li, link_to("bar", "http://www.google.com")) +
292 | content_tag(:li, link_to("baz", "http://www.wikipedia.org"))
293 | end
294 |
295 | strip(html).should == expected_html
296 | end
297 | end
298 | end
299 | end
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rails Bootstrap Helpers
2 |
3 | Rails Bootstrap Helpers is a plugin for Ruby on Rails that adds view helpers for
4 | [Bootstrap](http://getbootstrap.com/2.3.2/). It also contains some helpers
5 | for [Jasny's Bootstrap extensions](http://jasny.github.io/bootstrap/index.html).
6 |
7 | This documentation is for the upcoming release, that is git HEAD.
8 | For documentation for the latest release see: https://github.com/Tretti/rails-bootstrap-helpers/blob/v0.1.0/README.md
9 |
10 | ## Installation
11 |
12 | Add it to your Gemfile:
13 |
14 | ```ruby
15 | gem "rails-bootstrap-helpers"
16 | ```
17 |
18 | Manually include the necessary stylesheets and JavaScript files from Bootstrap.
19 |
20 | Although it has no direct dependencies on other gems than Rails, it is necessary
21 | to include Bootstrap in some way or another to make this gem useful.
22 | For standard Bootstrap, [bootstrap-sass](https://github.com/thomas-mcdonald/bootstrap-sass) is
23 | recommended. For Jasny Bootstrap, [jasny-bootstrap-extension-rails](https://github.com/mdedetrich/jasny-bootstrap-extension-rails) is recommended.
24 |
25 | ### JavaScript
26 |
27 | Some of the helpers uses features of Bootstrap that requires JavaScript to be
28 | initialized. You need to manually do this initialization. The following helpers
29 | uses JavaScript that needs manually initialization:
30 |
31 | * Any helper with the `:tooltip` option
32 | * [bs\_popover\_button](#bs_popover_button)
33 |
34 | For which JavaScript file to include, follow the
35 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/javascript.html).
36 |
37 | ## Usage
38 |
39 | ### Common
40 |
41 | #### icon
42 |
43 | ```erb
44 | <%= icon :edit %> # renders an icon with the icon-edit icon
45 | <%= icon :edit, invert: true %> # inverts the color of the icon, making it white
46 | ```
47 |
48 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/base-css.html#icons)
49 |
50 | #### iconic\_icon
51 |
52 | ```erb
53 | <%= iconic_icon :check %> # renders an icon with the iconic-check icon
54 |
55 | <%= iconic_icon :edit, color: :blue %> # render an icon with an CSS color
56 | <%= iconic_icon :edit, color: "#fff" %> # render an icon with an CSS color
57 |
58 | <%= iconic_icon :edit, size: 10 %> # render an icon with an CSS font size
59 | <%= iconic_icon :edit, size: "10" %> # render an icon with an CSS font size
60 | <%= iconic_icon :edit, size: "10em" %> # render an icon with an CSS font size
61 |
62 | <%= iconic_icon :edit, bs_style: "muted" %> # render an Bootstrap style
63 | <%= iconic_icon :edit, bs_style: "success" %> # render an Bootstrap style
64 |
65 | <%= iconic_icon :edit, action_style: "default" %> # render an Jasny Bootstrap action link style
66 | <%= iconic_icon :edit, action_style: "success" %> # render an Jasny Bootstrap action link style
67 | ```
68 |
69 | Renders an icon using the Jasny Bootstrap Iconic icon set.
70 |
71 | [Jasny Bootstrap documentation](http://jasny.github.io/bootstrap/base-css.html#iconic)
72 |
73 | ### Alerts
74 |
75 | #### bs\_alert
76 | ```erb
77 | <%= bs_alert "foo" %> # standard alert box
78 | <%= bs_alert "foo", block: true %> # alert box with block style
79 | <%= bs_alert "foo", dismiss_button: true %> # alert box with a dismiss button
80 | ```
81 |
82 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#alerts)
83 |
84 | ### Buttons
85 |
86 | #### bs\_button\_to
87 |
88 | ```erb
89 | <%= bs_button_to "google", "http://www.google.se" %>
90 | <%= bs_button_to "google", "http://www.google.se", style: "success" %>
91 | <%= bs_button_to "google", "http://www.google.se", disabled: true %>
92 | <%= bs_button_to "google", "http://www.google.se", icon: "edit" %>
93 | <%= bs_button_to "google", "http://www.google.se", icon_position: "left" %>
94 | <%= bs_button_to "google", "http://www.google.se", icon_invert: "left" %>
95 | ```
96 |
97 | The `bs_button_to` helper renders an `a` tag, styled as a Bootstrap button. It's
98 | basically a wrapper around the `link_to` helper. In addition all the standard
99 | arguments and options that `link_to` accepts it also accepts the above options.
100 |
101 | #### bs\_inline\_button\_to
102 |
103 | ```erb
104 | <%= bs_inline_button_to "http://www.google.se", :edit %>
105 | ```
106 |
107 | The `bs_inline_button_to` helper renders an `a` tag, styled as a inline
108 | Bootstrap button. That is, a button with the an icon (no text) and the size
109 | "mini". Except from that it accepts all options as the [bs\_button\_to](#bs_button_to) does.
110 |
111 | #### bs\_popover\_button
112 |
113 | ```erb
114 | <%= bs_popover_button "foo", "bar" %>
115 | <%= bs_popover_button "foo", "bar", position: "right" %>
116 | <%= bs_popover_button "foo" do %>
117 | <%= link_to "Google", "http://www.google.se" %>
118 | <% end %>
119 | ```
120 |
121 | Renders a Bootstrap button that when clicked opens a popover. The content of the
122 | popover can either be supplied as the second argument or as a block.
123 |
124 | **Note:** this helper requires JavaScript to be manually initialized. Add the
125 | following code to your JavaScript file:
126 |
127 | ```javascript
128 | $("[data-toggle=popover]").popover(html: true)
129 | // The "html" option tells the plugin to not escape HTML. Useful when rendering
130 | // the popover content using a block.
131 | ```
132 |
133 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/base-css.html#buttons)
134 |
135 | #### bs\_collapsible\_button
136 |
137 | ```erb
138 | <%= bs_collapsible_button "foo", "#bar" %>
139 | <%= bs_collapsible_button "foo", "#bar", style: "primary" %>
140 |
141 |
foobar
142 | ```
143 |
144 | Renders a Bootstrap button that when clicked will open a collapsible section.
145 | The second argument is a selector matching the section to open.
146 |
147 | #### button\_group
148 |
149 | ```erb
150 | <%= button_group do %>
151 | <%= bs_button_to "google", "http://www.google.se" %>
152 | <%= bs_button_to "google", "http://www.google.se", style: "success" %>
153 | <% end %>
154 |
155 | <%= button_group vertical: true do %>
156 | <%= bs_button_to "google", "http://www.google.se" %>
157 | <%= bs_button_to "google", "http://www.google.se", style: "success" %>
158 | <% end %>
159 |
160 | <%= button_group toolbar: true do %>
161 | <%= button_group do %>
162 | <%= bs_button_to "google", "http://www.google.se" %>
163 | <%= bs_button_to "google", "http://www.google.se", style: "success" %>
164 | <% end %>
165 |
166 | <%= button_group do %>
167 | <%= bs_button_to "google", "http://www.google.se", disabled: true %>
168 | <%= bs_button_to "google", "http://www.google.se", icon: "edit" %>
169 | <% end %>
170 | <%= end %>
171 | ```
172 |
173 | Renders a Bootstrap button group. That is, a div tag with the `btn-group` class.
174 |
175 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#buttonGroups)
176 |
177 | #### bs\_dropdown\_button\_to
178 |
179 | Renders a Bootstrap button with a dropdown menu. The menu items are rendered in
180 | the block by rendering list items (`
211 | <% end %>
212 | ```
213 |
214 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#buttonDropdowns)
215 |
216 | ### Forms
217 |
218 | #### bs\_button\_tag
219 |
220 | ```erb
221 | <%= bs_button_to "google", :submit %>
222 | ```
223 |
224 | Renders an `button` tag styled as a Bootstrap button. First argument is the text
225 | to be rendered on the button, the other is what type of button (that is, the HTML
226 | attribute `type`). Accepts all the options as [bs\_button\_to](#bs_button_to) does.
227 |
228 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/base-css.html#buttons)
229 |
230 | #### bs\_submit\_tag
231 |
232 | ```erb
233 | <%= bs_submit_tag "save" %>
234 | <%= bs_submit_tag "save", style: "primary" %>
235 | <%= bs_submit_tag "save", size: "small" %>
236 | ```
237 |
238 | ### Labels
239 |
240 | #### bs\_label
241 |
242 | ```erb
243 | <%= bs_label "foo" # standard label%>
244 | <%= bs_label "foo", :success # styled label %>
245 | ```
246 |
247 | ### Tooltips
248 |
249 | ```erb
250 | <%= bs_label "foo", tooltip: "bar" %>
251 | ```
252 |
253 | Basically any helper accepts the `:tooltip` option. This will add a Bootstrap
254 | tooltip to the rendered component.
255 |
256 | **Note:** this option requires JavaScript to be manually initialized. Add the
257 | following code to your JavaScript file:
258 |
259 | ```javascript
260 | $("[data-toggle=tooltip]").tooltip()
261 | ```
262 |
263 | [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#labels-badges)
264 |
265 | ### Tags
266 |
267 | #### bs\_content\_tag
268 |
269 | ```ruby
270 | bs_content_tag :div do
271 | append "foo"
272 | end
273 |
274 | bs_content_tag :div, id: "foo" do
275 | bs_content_tag :div, class: "asd" do
276 | append "bar"
277 | end
278 |
279 | append "foobar"
280 | end
281 | ```
282 |
283 | The above code will return the following HTML code:
284 |
285 | ```html
286 |
287 | foo
288 |
289 |
290 |
291 |
292 | bar
293 |
294 | foobar
295 |
296 | ```
297 |
298 | Returns an HTML block. This method behaves basically just like `content_tag` but
299 | properly indents and add newlines to the HTML. This is useful in helpers.
300 |
301 | ### Accordion
302 |
303 | #### accordion
304 |
305 | ```erb
306 | <%= accordion "unique_id" do |a| %>
307 | <% a.group "heading" do %>
308 | content
309 | <% end %>
310 | <% end %>
311 | ```
312 |
313 | The above code will render the following HTML code:
314 |
315 | ```html
316 |