bootstrap_helpers 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ module BootstrapHelpers
2
+
3
+ module FlashMessageProccessor
4
+
5
+ private
6
+
7
+ def equal_bootstrap_class(flash_type)
8
+ case flash_type.to_s.downcase
9
+ when 'alert'
10
+ 'error'
11
+ when 'notice'
12
+ 'success'
13
+ when 'info'
14
+ 'info'
15
+ else 'warning'
16
+ end
17
+ end
18
+
19
+ def flash_message_template(message,type)
20
+ content_tag :div, :class=>"alert-message #{equal_bootstrap_class(type)} fade in", 'data-alert'=>'alert' do
21
+ content_tag(:a, :href=>'#', :class=>'close'){"×"} + content_tag(:p) {message}
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -1,3 +1,3 @@
1
1
  module BootstrapHelpers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,20 +1,47 @@
1
+ require 'bootstrap_helpers/flash_message_proccessor'
1
2
  module BootstrapHelpers
2
3
 
3
4
  module ViewHelpers
4
5
 
6
+ include FlashMessageProccessor
7
+
5
8
  def bootstrap_form_tag(path,legend='',params={})
6
9
  form_tag path, params do
7
- concat content_tag :legend, legend
8
- yield
10
+ concat(content_tag(:fieldset) do
11
+ concat content_tag(:legend, legend)
12
+ yield
13
+ end)
9
14
  end
10
15
  end
11
16
 
12
- def bootstrap_form_input(title)
13
- content_tag :div, :class=>'clearfix' do
17
+ def bootstrap_form_input(title, params={})
18
+ params[:class]="clearfix #{params[:class]}"
19
+ content_tag :div, params do
14
20
  content_tag(:label, title) + content_tag(:div, :class=>'input') { yield }
15
21
  end
16
22
  end
17
23
 
24
+ def bootstrap_form_actions(params={})
25
+ params[:class]="actions #{params[:class]}"
26
+ content_tag :div, params do
27
+ yield
28
+ end
29
+ end
30
+
31
+ def bootstrap_flash_messages(params={})
32
+ params[:class]="bootstrap_flash_messages #{params[:class]}"
33
+ content_tag :div, params do
34
+ flash.each do |type, content|
35
+ case content
36
+ when Array
37
+ content.each {|message| concat flash_message_template(message, type)}
38
+ when String
39
+ concat flash_message_template(content, type)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
18
45
  end
19
46
 
20
47
  end
data/test_app/Gemfile CHANGED
@@ -7,7 +7,7 @@ gem 'rails', '3.0.10'
7
7
 
8
8
  gem 'sqlite3'
9
9
  gem 'jquery-rails'
10
- gem 'bootstrap_helpers', '0.0.1'
10
+ gem 'bootstrap_helpers', '0.0.2'
11
11
 
12
12
  group :test do
13
13
  gem 'rspec-rails', ">=2.5.0"
@@ -4,4 +4,11 @@ class SamplesController < ApplicationController
4
4
 
5
5
  def bootstrap_form_input;end
6
6
 
7
+ def bootstrap_flash_messages
8
+ flash[:notice]='Example of notice'
9
+ flash[:alert]='Example of error'
10
+ flash[:info] = "Example of info"
11
+ flash[:just_another_type]=['Example of warning(default flash message)', 'Another warning info']
12
+ end
13
+
7
14
  end
@@ -0,0 +1 @@
1
+ <%= bootstrap_flash_messages :class=>'customer_bootstrap_class' %>
@@ -1,3 +1,10 @@
1
1
  <%= bootstrap_form_tag "#", "Sample form", :class=>'sample_form' do%>
2
2
  <%= bootstrap_form_input ("Sample input"){ text_field "sample", "input", :class=>'xlarge'}%>
3
+ <%= bootstrap_form_input ("Custom class", :class=>'custom_class') do%>
4
+ <h2>nvsdnsksdn</h2>
5
+ <%end%>
6
+ <%= bootstrap_form_actions(:class=>'another_action') do%>
7
+ <%= link_to 'Foo', '#', :class=>'btn'%>
8
+ <%= link_to 'Boo', '#', :class=>'btn info'%>
9
+ <%end%>
3
10
  <%end%>
File without changes
@@ -2,5 +2,6 @@ TestApp::Application.routes.draw do
2
2
  root :to=>'Samples#index'
3
3
  controller :samples do
4
4
  get '/bootstrap_form_input'=>:bootstrap_form_input, :as=>:bootstrap_form_input
5
+ get '/bootstrap_flash_messages'=>:bootstrap_flash_messages, :as=>:bootstrap_flash_messages
5
6
  end
6
7
  end
@@ -6,13 +6,23 @@ describe SamplesController do
6
6
  visit root_path
7
7
  page.should have_selector("form.sample_form")
8
8
  page.should have_selector(".sample_form legend", :text=>'Sample form')
9
- page.should have_selector('.sample_form .clearfix')
9
+ page.should have_selector('.sample_form .clearfix.custom_class')
10
10
  page.should have_selector('.sample_form .clearfix label', :text=>'Sample input')
11
+ page.should have_selector(".sample_form .actions")
12
+ page.should have_selector('.sample_form .actions a', :count=>2)
11
13
  end
12
14
 
13
- it 'should proper generate bootstrap form input' do
14
- visit bootstrap_form_input_path
15
- page.should have_selector("div.clearfix")
15
+ it 'should have several kind of flash' do
16
+ visit bootstrap_flash_messages_path
17
+ page.should have_selector("div.customer_bootstrap_class")
18
+ page.should have_selector("div.alert-message", :count=>5)
19
+ page.should have_selector("div.alert-message.error", :text=>'Example of error')
20
+ page.should have_selector("div.alert-message.success", :text=>'Example of notice')
21
+ page.should have_selector("div.alert-message.info", :text=>'Example of info')
22
+ page.should have_selector("div.alert-message.warning", :text=>'Example of warning(default flash message)')
23
+ page.should have_selector("div.alert-message.warning", :text=>'Another warning info')
24
+ find("div.info a").click
25
+ page.should_not have_selector("div.alert-message.info")
16
26
  end
17
27
 
18
28
  end
@@ -5,6 +5,10 @@ require 'rspec/rails'
5
5
  require 'rspec/autorun'
6
6
  require 'capybara/rspec'
7
7
 
8
+ Capybara.register_driver :selenium_chrome do |app|
9
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
10
+ end
11
+
8
12
  # Requires supporting ruby files with custom matchers and macros, etc,
9
13
  # in spec/support/ and its subdirectories.
10
14
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
@@ -31,4 +35,5 @@ RSpec.configure do |config|
31
35
  # automatically. This will be the default behavior in future versions of
32
36
  # rspec-rails.
33
37
  config.infer_base_class_for_anonymous_controllers = false
38
+ Capybara.default_driver = :selenium_chrome
34
39
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_helpers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergey Pchelincev
@@ -34,6 +34,7 @@ files:
34
34
  - Rakefile
35
35
  - bootstrap_helpers.gemspec
36
36
  - lib/bootstrap_helpers.rb
37
+ - lib/bootstrap_helpers/flash_message_proccessor.rb
37
38
  - lib/bootstrap_helpers/railtie.rb
38
39
  - lib/bootstrap_helpers/version.rb
39
40
  - lib/bootstrap_helpers/view_helpers.rb
@@ -47,8 +48,10 @@ files:
47
48
  - test_app/app/controllers/samples_controller.rb
48
49
  - test_app/app/helpers/application_helper.rb
49
50
  - test_app/app/views/layouts/application.html.erb
51
+ - test_app/app/views/samples/bootstrap_flash_messages.html.erb
50
52
  - test_app/app/views/samples/bootstrap_form_input.html.erb
51
53
  - test_app/app/views/samples/index.html.erb
54
+ - test_app/chromedriver.log
52
55
  - test_app/config.ru
53
56
  - test_app/config/application.rb
54
57
  - test_app/config/boot.rb