This repository has been archived by the owner on Dec 20, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
324 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
.bundle | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rvm: | ||
- 1.8.7 | ||
- ree | ||
- 1.9.2 | ||
- 1.9.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in bootstrap-rails.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
guard 'rspec', :version => 2 do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/.*(helpers|components)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
watch(%r{^spec/support/(.+)\.rb$}) { "spec" } | ||
watch(%r{^lib/(.+)\.rb$}) { "spec" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" | ||
require 'rspec/core/rake_task' | ||
require 'rake/testtask' | ||
|
||
task :default => :spec | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs << "test" | ||
t.test_files = FileList['test/*_test.rb'] | ||
t.verbose = true | ||
end | ||
|
||
desc 'Test the plugin.' | ||
RSpec::Core::RakeTask.new('spec') do |t| | ||
t.pattern = FileList['spec/**/*_spec.rb'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Twitter | ||
module Bootstrap | ||
module Markup | ||
module Rails | ||
require_relative "twitter-bootstrap-markup-rails/version" | ||
|
||
autoload :Helpers, "twitter-bootstrap-markup-rails/helpers" | ||
autoload :Components, "twitter-bootstrap-markup-rails/components" | ||
|
||
require_relative "twitter-bootstrap-markup-rails/engine" if defined?(::Rails) | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Twitter::Bootstrap::Markup::Rails | ||
module Components | ||
autoload :Base, 'twitter-bootstrap-markup-rails/components/base' | ||
autoload :Alert, 'twitter-bootstrap-markup-rails/components/alert' | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Twitter::Bootstrap::Markup::Rails::Components | ||
class Alert < Base | ||
attr_reader :message | ||
|
||
def initialize(message, options = {}) | ||
super | ||
@message = message | ||
end | ||
|
||
def to_s | ||
output_buffer << content_tag(:div, :class => build_class) do | ||
html = "" | ||
html << build_close_tag.html_safe if options[:close] | ||
html << build_heading_tag.html_safe if options[:heading] | ||
html << message | ||
html.html_safe | ||
end.html_safe | ||
super | ||
end | ||
|
||
private | ||
def default_options | ||
{ | ||
:class => "alert", | ||
:block => false, | ||
:close => true, | ||
:heading => nil, | ||
:dismiss => true, | ||
:type => nil, | ||
} | ||
end | ||
|
||
def build_close_tag | ||
content_tag(:a, "×".html_safe, close_tag_options) | ||
end | ||
|
||
def build_heading_tag | ||
options[:block] ? build_block_heading : build_inline_heading | ||
end | ||
|
||
def build_block_heading | ||
content_tag(:h4, options[:heading], :class => 'alert-heading') | ||
end | ||
|
||
def build_inline_heading | ||
content_tag(:strong, options[:heading]) | ||
end | ||
|
||
def close_tag_options | ||
opts = { :class => "close" } | ||
opts["data-dismiss"] = "alert" if options[:dismiss] | ||
opts | ||
end | ||
|
||
def build_class | ||
classes = %w(alert) | ||
classes << "alert-block" if options[:block] | ||
classes << "alert-#{options[:type]}" if options[:type] | ||
classes.join(" ") | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- encoding: utf-8 -*- | ||
module Twitter::Bootstrap::Markup::Rails::Components | ||
class Base | ||
include ActionView::Helpers::TagHelper | ||
|
||
attr_accessor :output_buffer, :options, :default_options | ||
|
||
def initialize(*args) | ||
@output_buffer = "" | ||
@options = args.extract_options!.reverse_merge(default_options) | ||
end | ||
|
||
def to_s | ||
@output_buffer.to_s.html_safe | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Twitter::Bootstrap::Markup::Rails | ||
class Engine < ::Rails::Engine | ||
initializer 'twitter.bootstrap.markup.rails.initialize' do | ||
ActiveSupport.on_load(:action_view) do | ||
include Twitter::Bootstrap::Markup::Rails::Helpers::AlertHelpers | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Twitter::Bootstrap::Markup::Rails | ||
module Helpers | ||
autoload :AlertHelpers, 'twitter-bootstrap-markup-rails/helpers/alert_helpers' | ||
end | ||
end | ||
|
17 changes: 17 additions & 0 deletions
17
lib/twitter-bootstrap-markup-rails/helpers/alert_helpers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# encoding: utf-8 | ||
|
||
module Twitter::Bootstrap::Markup::Rails::Helpers | ||
module AlertHelpers | ||
def twitter_alert_info_block(message, opts = {}) | ||
twitter_alert(message, opts.merge({ :type => "info", :block => true })) | ||
end | ||
|
||
def twitter_alert(message, options = {}) | ||
Twitter::Bootstrap::Markup::Rails::Components::Alert.new( | ||
message, | ||
options | ||
).to_s | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Twitter | ||
module Bootstrap | ||
module Markup | ||
module Rails | ||
VERSION = "0.0.1" | ||
end | ||
end | ||
end | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Twitter::Bootstrap::Markup::Rails::Helpers::AlertHelpers do | ||
include BootstrapSpecHelper | ||
|
||
before do | ||
@output_buffer = '' | ||
end | ||
|
||
describe "#twitter_alert_info_block" do | ||
it "has correct classes" do | ||
concat twitter_alert_info_block("Message") | ||
output_buffer.should have_tag('div.alert.alert-block.alert-info') | ||
end | ||
|
||
it "has correct message" do | ||
concat twitter_alert_info_block("Message") | ||
output_buffer.should have_tag('div', /Message/) | ||
end | ||
|
||
it "has close button" do | ||
concat twitter_alert_info_block("Message") | ||
output_buffer.should have_tag('div a.close', /×/) | ||
end | ||
|
||
it "has dismiss tag" do | ||
concat twitter_alert_info_block("Message") | ||
output_buffer.should have_tag('div a[data-dismiss="alert"]') | ||
end | ||
|
||
it "has a heading" do | ||
concat twitter_alert_info_block("Message", :heading => "Heading1") | ||
output_buffer.should have_tag('div h4.alert-heading', /Heading1/) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# encoding: utf-8 | ||
require 'bundler/setup' | ||
require 'active_support' | ||
require 'action_pack' | ||
require 'action_view' | ||
require 'action_controller' | ||
require 'action_dispatch' | ||
|
||
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/twitter-bootstrap-markup-rails')) | ||
|
||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f} | ||
|
||
module FakeHelpersModule | ||
end | ||
|
||
module BootstrapSpecHelper | ||
include ActionPack | ||
include ActionView::Context if defined?(ActionView::Context) | ||
include ActionController::RecordIdentifier | ||
include ActionView::Helpers::FormHelper | ||
include ActionView::Helpers::FormTagHelper | ||
include ActionView::Helpers::FormOptionsHelper | ||
include ActionView::Helpers::UrlHelper | ||
include ActionView::Helpers::TagHelper | ||
include ActionView::Helpers::TextHelper | ||
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper) | ||
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper) | ||
include ActionView::Helpers::DateHelper | ||
include ActionView::Helpers::CaptureHelper | ||
include ActionView::Helpers::AssetTagHelper | ||
include ActiveSupport | ||
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes) | ||
|
||
def _routes | ||
url_helpers = mock('url_helpers') | ||
url_helpers.stub!(:hash_for_posts_path).and_return({}) | ||
url_helpers.stub!(:hash_for_post_path).and_return({}) | ||
url_helpers.stub!(:hash_for_post_models_path).and_return({}) | ||
url_helpers.stub!(:hash_for_authors_path).and_return({}) | ||
|
||
mock('_routes', | ||
:url_helpers => url_helpers, | ||
:url_for => "/mock/path" | ||
) | ||
end | ||
|
||
def controller | ||
env = mock('env', :[] => nil) | ||
request = mock('request', :env => env) | ||
mock('controller', :controller_path= => '', :params => {}, :request => request) | ||
end | ||
|
||
def default_url_options | ||
{} | ||
end | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
|
||
attr_accessor :output_buffer | ||
|
||
def protect_against_forgery? | ||
false | ||
end | ||
|
||
def _helpers | ||
FakeHelpersModule | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# encoding: utf-8 | ||
|
||
require 'rspec' | ||
require 'rspec_tag_matchers' | ||
|
||
RSpec.configure do |config| | ||
config.include RspecTagMatchers | ||
config.mock_with :rspec | ||
end | ||
|
||
require "action_controller/railtie" | ||
|
||
# Create a simple rails application for use in testing the viewhelper | ||
module BootstrapTest | ||
class Application < Rails::Application | ||
# Configure the default encoding used in templates for Ruby 1.9. | ||
config.encoding = "utf-8" | ||
config.active_support.deprecation = :stderr | ||
end | ||
end | ||
BootstrapTest::Application.initialize! | ||
|
||
require 'rspec/rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters