css3buttons 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1 @@
1
+ require 'autotest/growl'
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "lib/css3buttons/generators/css3buttons/templates/public"]
2
+ path = lib/generators/css3buttons/templates/public
3
+ url = git://github.com/michenriksen/css3buttons.git
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in css3buttons.gemspec
4
+ gemspec
5
+
6
+ gem 'actionpack', '>= 3.0.5'
7
+
8
+ group :test do
9
+ #gem 'rails'
10
+ gem 'rspec'
11
+ #gem 'rspec-rails'
12
+ gem 'autotest'
13
+ gem 'autotest-growl'
14
+ gem 'capybara', :git => 'https://github.com/jnicklas/capybara.git'
15
+ gem 'webrat'
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ GIT
2
+ remote: https://github.com/jnicklas/capybara.git
3
+ revision: 549e67336c712a1ef2119ce5ff64dbbc7542480f
4
+ specs:
5
+ capybara (0.4.1.1)
6
+ mime-types (>= 1.16)
7
+ nokogiri (>= 1.3.3)
8
+ rack (>= 1.0.0)
9
+ rack-test (>= 0.5.4)
10
+ selenium-webdriver (>= 0.0.27)
11
+ xpath (~> 0.1.3)
12
+
13
+ PATH
14
+ remote: .
15
+ specs:
16
+ css3buttons (0.7.0)
17
+ actionpack (>= 3.0.5)
18
+
19
+ GEM
20
+ remote: http://rubygems.org/
21
+ specs:
22
+ ZenTest (4.5.0)
23
+ abstract (1.0.0)
24
+ actionpack (3.0.5)
25
+ activemodel (= 3.0.5)
26
+ activesupport (= 3.0.5)
27
+ builder (~> 2.1.2)
28
+ erubis (~> 2.6.6)
29
+ i18n (~> 0.4)
30
+ rack (~> 1.2.1)
31
+ rack-mount (~> 0.6.13)
32
+ rack-test (~> 0.5.7)
33
+ tzinfo (~> 0.3.23)
34
+ activemodel (3.0.5)
35
+ activesupport (= 3.0.5)
36
+ builder (~> 2.1.2)
37
+ i18n (~> 0.4)
38
+ activesupport (3.0.5)
39
+ autotest (4.4.6)
40
+ ZenTest (>= 4.4.1)
41
+ autotest-growl (0.2.9)
42
+ builder (2.1.2)
43
+ childprocess (0.1.7)
44
+ ffi (~> 0.6.3)
45
+ diff-lcs (1.1.2)
46
+ erubis (2.6.6)
47
+ abstract (>= 1.0.0)
48
+ ffi (0.6.3)
49
+ rake (>= 0.8.7)
50
+ i18n (0.5.0)
51
+ json_pure (1.5.1)
52
+ mime-types (1.16)
53
+ nokogiri (1.4.4)
54
+ rack (1.2.2)
55
+ rack-mount (0.6.13)
56
+ rack (>= 1.0.0)
57
+ rack-test (0.5.7)
58
+ rack (>= 1.0)
59
+ rake (0.8.7)
60
+ rspec (2.5.0)
61
+ rspec-core (~> 2.5.0)
62
+ rspec-expectations (~> 2.5.0)
63
+ rspec-mocks (~> 2.5.0)
64
+ rspec-core (2.5.1)
65
+ rspec-expectations (2.5.0)
66
+ diff-lcs (~> 1.1.2)
67
+ rspec-mocks (2.5.0)
68
+ rubyzip (0.9.4)
69
+ selenium-webdriver (0.1.3)
70
+ childprocess (~> 0.1.5)
71
+ ffi (~> 0.6.3)
72
+ json_pure
73
+ rubyzip
74
+ tzinfo (0.3.25)
75
+ webrat (0.7.2)
76
+ nokogiri (>= 1.2.0)
77
+ rack (>= 1.0)
78
+ rack-test (>= 0.5.3)
79
+ xpath (0.1.3)
80
+ nokogiri (~> 1.3)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ actionpack (>= 3.0.5)
87
+ autotest
88
+ autotest-growl
89
+ capybara!
90
+ css3buttons!
91
+ rspec
92
+ webrat
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "css3buttons/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "css3buttons"
7
+ s.version = Css3buttons::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nicholas Bruning"]
10
+ s.email = ["nicholas@bruning.com.au"]
11
+ s.homepage = "https://github.com/thetron/css3buttons_rails_helpers"
12
+ s.summary = %q{Easy, beautiful buttons, the CSS3 way.}
13
+ s.description = %q{Rails helper methods and generators for the css3buttons by Michael Henriksen.}
14
+
15
+ s.rubyforge_project = "css3buttons"
16
+
17
+ s.add_dependency 'actionpack', '>= 3.0.0'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'action_controller'
2
+ require 'action_view'
3
+
4
+ module Css3buttons
5
+ module Helpers
6
+ autoload :ButtonHelper, 'css3buttons/helpers/button_helper'
7
+ end
8
+ autoload :ButtonGroup, 'css3buttons/button_group'
9
+ ActionController::Base.helper(Css3buttons::Helpers::ButtonHelper)
10
+ end
Binary file
@@ -0,0 +1,38 @@
1
+ module Css3buttons
2
+ class ButtonGroup
3
+ attr_reader :template, :button_count
4
+
5
+ def initialize(template)
6
+ @button_count = 0
7
+ @template = template
8
+ end
9
+
10
+ def render(&block)
11
+ add_group_classes(template.capture(self, &block)) if block_given?
12
+ end
13
+
14
+ def method_missing(method_name, *args)
15
+ name = args[0]
16
+ options = args[1] || {}
17
+ html_options = args[2] || {}
18
+ html_options[:class] ||= ""
19
+ html_options[:class] += " __css3buttons_group_#{@button_count}__"
20
+ @button_count += 1
21
+ @template.send(method_name, name, options, html_options)
22
+ end
23
+
24
+ private
25
+ def add_group_classes(html)
26
+ (0...@button_count).to_a.each do |index|
27
+ if index == 0
28
+ html.gsub! /__css3buttons_group_#{index}__/, "left"
29
+ elsif index == @button_count - 1
30
+ html.gsub! /__css3buttons_group_#{index}__/, "right"
31
+ else
32
+ html.gsub! /__css3buttons_group_#{index}__/, "middle"
33
+ end
34
+ end
35
+ html
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,55 @@
1
+ module Css3buttons
2
+ module Helpers
3
+ module ButtonHelper
4
+
5
+ def css3buttons_stylesheets(options = {})
6
+ options[:include_reset] = true unless options.has_key?(:include_reset)
7
+ if options[:include_reset] == true
8
+ stylesheet_link_tag "css3buttons/reset", "css3buttons/css3buttons"
9
+ else
10
+ stylesheet_link_tag "css3buttons/css3buttons"
11
+ end
12
+ end
13
+
14
+ def button_group(&block)
15
+ group = Css3buttons::ButtonGroup.new(self)
16
+ group.render(&block) if block_given?
17
+ end
18
+
19
+ # add the dynamic methods for all button types
20
+ def self.included(base)
21
+ qualifiers = ["", "positive", "negative", "pill", "positive_pill", "negative_pill"]
22
+ icons = ["link", "book","calendar","chat","check","clock","cog","comment","cross","downarrow","fork","heart","home","key","leftarrow","lock","loop","magnifier","mail","move","pen","pin","plus","reload","rightarrow","rss","tag","trash","unlock","uparrow","user"]
23
+ qualifiers.each do |qualifier|
24
+ icons.each do |icon|
25
+ method_name = (qualifier.split("_") + [icon, "button", "to"]).join("_")
26
+ define_method(:"#{method_name}") do |*args, &block|
27
+ icon_tag = (icon != icons.first) ? content_tag(:span, "", :class => "icon #{icon}") : ""
28
+ if block_given?
29
+ options = args.first || {}
30
+ html_options = args.second
31
+ html_options = add_classes_to_html_options [qualifier.split("_"), 'button'], html_options
32
+ link_to(icon_tag + capture(&block).html_safe, options, html_options)
33
+ else
34
+ name = args[0]
35
+ options = args[1] || {}
36
+ html_options = args[2] || {}
37
+ html_options = add_classes_to_html_options [qualifier.split("_"), 'button'], html_options
38
+ link_to(icon_tag + name.html_safe, options, html_options)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ protected
46
+ def add_classes_to_html_options(classes, html_options = {})
47
+ classes = classes.delete_if{|c| c.blank?}
48
+ html_options ||= {}
49
+ html_options[:class] ||= ""
50
+ html_options[:class] = (html_options[:class].split(" ") + classes).join(" ")
51
+ html_options
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Css3buttons
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ To add the latest css3buttons stylsheets and icon images to your rails app, just do the following:
2
+
3
+ rails generate css3buttons:assets
@@ -0,0 +1,12 @@
1
+ class Css3buttonsGenerator < Rails::Generators::Base
2
+ desc "Copies css3buttons stylesheets and images"
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_stylesheets_and_images
6
+ copy_file "public/images/css3buttons_backgrounds.png", "public/images/css3buttons/css3buttons_backgrounds.png"
7
+ copy_file "public/images/css3buttons_icons.png", "public/images/css3buttons/css3buttons_icons.png"
8
+ copy_file "public/stylesheets/css3buttons.css", "public/stylesheets/css3buttons/css3buttons.css"
9
+ copy_file "public/stylesheets/reset.css", "public/stylesheets/css3buttons/reset.css"
10
+ gsub_file "public/stylesheets/css3buttons/css3buttons.css", /\.\.\/images/, "/images/css3buttons"
11
+ end
12
+ end
data/readme.md ADDED
@@ -0,0 +1,94 @@
1
+ # css3buttons gem - helper methods for css3buttons
2
+
3
+ The css3buttons gem is a small set of helper methods designed to work in
4
+ conjunction with the __awesome__ [css3buttons by Michael Henriksen](http://css3buttons.michaelhenriksen.dk).
5
+
6
+ The helpers allow rails developers to quickly and easily leverage this
7
+ fantastic CSS library - without cluttering up your views and calls to
8
+ `link_to`.
9
+
10
+ # Getting started
11
+
12
+ Include the gem in your gemfile:
13
+
14
+ gem 'css3buttons'
15
+
16
+ Run the generators
17
+
18
+ $ rails g css3buttons
19
+
20
+ Which will copy the stylesheets and icon/button images into your public
21
+ directory.
22
+
23
+ In your layout, add the following:
24
+
25
+ <%= css3buttons_stylesheets %>
26
+
27
+ Which will add both the `reset.css` and the `css3buttons.css` stylesheet
28
+ link tags.
29
+
30
+ _Please note_ since this helper includes the css3buttons
31
+ reset stylesheet, it's advisable to place this helper before all your
32
+ other stylsheet declarations. However, if you'd like to use your own
33
+ reset, you can skip it with:
34
+
35
+ <%= css3buttons_stylesheets :include_reset => false %>
36
+
37
+ # The basics
38
+
39
+ To change your `link_to` calls to buttons, simply use `link_button_to`.
40
+ For example:
41
+
42
+ <%= link_button_to "Search", search_path %>
43
+
44
+ The helper method accept all the same parameters as `link_to` to
45
+ upgrading and downgrading so css3buttons should be a snap.
46
+
47
+
48
+ # Icons and pills and colours, oh my!
49
+
50
+ The gem also creates a huge stack of dynamic helpers, to assist in adding
51
+ icons, colours and styles to your buttons.
52
+
53
+ ## Icons
54
+
55
+ To add an icon from [the current icon list](http://css3buttons.michaelhenriksen.dk/), simply replace `link` in the helper method with the name of the icon you'd like to use. For example:
56
+
57
+ <%= magnifier_button_to "Search", search_path %>
58
+ <%= user_button_to "Account", edit_current_user_path %>
59
+ <%= pin_button_to "Mark on map", edit_map_path %>
60
+
61
+ ## Styles
62
+
63
+ Just like the icons, simply prepend your button calls with `pill_`:
64
+
65
+ <%= pill_link_button_to "Archive", archive_path %>
66
+
67
+ ## Colors
68
+
69
+ Again with colors - simply add `positive_` or `negative_` to the front
70
+ of your method call:
71
+
72
+ <%= negative_trash_button_to "Delete", delete_path %>
73
+ <%= positive_pill_reload_button_to "Reload", reload_path %>
74
+
75
+ ## Button groups
76
+
77
+ There's also a helper to automatically add the `left`, `middle` and
78
+ `right` classes for grouped buttons.
79
+
80
+ <%= button_group do |group| %>
81
+ <%= group.link_button_to "Show", @post %>
82
+ <%= group.link_button_to "Edit", edit_post_path(@post) %>
83
+ <%= group.negative_trash_button_to "Delete", @post %>
84
+ <% end >
85
+
86
+ # What's missing?
87
+
88
+ There's a couple of things I've noticed are still missing from the gem,
89
+ namely the `big` and `primary` options - which I will add very soon, for
90
+ the next release.
91
+
92
+ The `button_group` helper needs some proper tests, if anyone can point me
93
+ as to how to stub out a rails request template in RSpec, that would be much
94
+ appreciated!
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ include ActionView::Helpers::UrlHelper
4
+ include Css3buttons::Helpers::ButtonHelper
5
+
6
+ describe Css3buttons::ButtonGroup do
7
+ before :each do
8
+ stub_template "posts/_actions.html.erb" => "<= button_group do\nlink_button_to 'show', '/post/345'\nlink_button_to 'edit', '/post/345/edit'\nlink_button_to 'delete', '/post/345'"
9
+ end
10
+
11
+ it "should add a class of first to the first link" do
12
+ render
13
+ puts rendered
14
+ end
15
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+ include ActionView::Helpers::UrlHelper
3
+ include Css3buttons::Helpers::ButtonHelper
4
+
5
+ describe Css3buttons::Helpers::ButtonHelper do
6
+ before :each do
7
+ @icons = ["book","calendar","chat","check","clock","cog","comment","cross","downarrow","fork","heart","home","key","leftarrow","lock","loop","magnifier","mail","move","pen","pin","plus","reload","rightarrow","rss","tag","trash","unlock","uparrow","user"]
8
+ @qualifiers = ['pill', 'negative', 'positive']
9
+ @label = "Search this site"
10
+ @path = "/search/site"
11
+ end
12
+
13
+ it "should create basic buttons" do
14
+ link = html(link_button_to(@label, @path))
15
+
16
+ link.should have_selector("a.button[href='#{@path}']")
17
+ @qualifiers.each do |qualifier|
18
+ link.should_not have_selector("a.#{qualifier}")
19
+ end
20
+ end
21
+
22
+ it "should create basic buttons with valid icons" do
23
+ @icons.each do |icon|
24
+ link = html(send(:"#{icon}_button_to", @label, @path))
25
+ link.should have_selector("a.button[href='#{@path}']")
26
+ link.should have_selector("a.button span.icon.#{icon}")
27
+ end
28
+ end
29
+ it "should create positive buttons" do
30
+ link = html(positive_link_button_to(@label, @path))
31
+ link.should have_selector("a.button.positive[href='#{@path}']")
32
+ @qualifiers.each do |qualifier|
33
+ link.should_not have_selector("a.#{qualifier}") unless qualifier == "positive"
34
+ end
35
+ end
36
+
37
+ it "should create negative buttons" do
38
+ link = html(negative_link_button_to(@label, @path))
39
+ link.should have_selector("a.button.negative[href='#{@path}']")
40
+ @qualifiers.each do |qualifier|
41
+ link.should_not have_selector("a.#{qualifier}") unless qualifier == "negative"
42
+ end
43
+ end
44
+
45
+ it "should create positive buttons with valid icons" do
46
+ @icons.each do |icon|
47
+ link = html(send(:"positive_#{icon}_button_to", @label, @path))
48
+ link.should have_selector("a.button.positive[href='#{@path}']")
49
+ link.should have_selector("a.button.positive span.icon.#{icon}")
50
+ @qualifiers.each do |qualifier|
51
+ link.should_not have_selector("a.#{qualifier}") unless qualifier == "positive"
52
+ end
53
+ end
54
+ end
55
+
56
+ it "should create negative buttons with valid icons" do
57
+ @icons.each do |icon|
58
+ link = html(send(:"negative_#{icon}_button_to", @label, @path))
59
+ link.should have_selector("a.button.negative[href='#{@path}']")
60
+ link.should have_selector("a.button.negative span.icon.#{icon}")
61
+ @qualifiers.each do |qualifier|
62
+ link.should_not have_selector("a.#{qualifier}") unless qualifier == "negative"
63
+ end
64
+ end
65
+ end
66
+
67
+ it "should create pill buttons" do
68
+ link = html(pill_link_button_to(@label, @path))
69
+ link.should have_selector("a.button.pill[href='#{@path}']")
70
+ @qualifiers.each do |qualifier|
71
+ link.should_not have_selector("a.#{qualifier}") unless qualifier == "pill"
72
+ end
73
+ end
74
+
75
+ it "should create pill buttons with valid icons" do
76
+ @icons.each do |icon|
77
+ link = html(send(:"pill_#{icon}_button_to", @label, @path))
78
+ link.should have_selector("a.button.pill[href='#{@path}']")
79
+ link.should have_selector("a.button.pill span.icon.#{icon}")
80
+ @qualifiers.each do |qualifier|
81
+ link.should_not have_selector("a.#{qualifier}") unless qualifier == "pill"
82
+ end
83
+ end
84
+ end
85
+
86
+ it "should create positive pill buttons" do
87
+ link = html(positive_pill_link_button_to(@label, @path))
88
+ link.should have_selector("a.button.pill.positive[href='#{@path}']")
89
+ link.should_not have_selector("a.negative")
90
+ end
91
+
92
+ it "should create negative pill buttons" do
93
+ link = html(negative_pill_link_button_to(@label, @path))
94
+ link.should have_selector("a.button.pill.negative[href='#{@path}']")
95
+ link.should_not have_selector("a.positive")
96
+ end
97
+
98
+ it "should create positive pill buttons with valid icons" do
99
+ @icons.each do |icon|
100
+ link = html(send(:"positive_pill_#{icon}_button_to", @label, @path))
101
+ link.should have_selector("a.button.positive.pill[href='#{@path}']")
102
+ link.should have_selector("a.button.positive.pill span.icon.#{icon}")
103
+ link.should_not have_selector("a.negative")
104
+ end
105
+ end
106
+
107
+ it "should create negative pill buttons with valid icons" do
108
+ @icons.each do |icon|
109
+ link = html(send(:"negative_pill_#{icon}_button_to", @label, @path))
110
+ link.should have_selector("a.button.negative.pill[href='#{@path}']")
111
+ link.should have_selector("a.button.negative.pill span.icon.#{icon}")
112
+ link.should_not have_selector("a.positive")
113
+ end
114
+ end
115
+
116
+ def html(text)
117
+ Capybara::string(text)
118
+ end
119
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'webrat'
5
+ require 'capybara'
6
+ require 'css3buttons'
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: css3buttons
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
+ platform: ruby
12
+ authors:
13
+ - Nicholas Bruning
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-21 00:00:00 +11:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: actionpack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Rails helper methods and generators for the css3buttons by Michael Henriksen.
38
+ email:
39
+ - nicholas@bruning.com.au
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .autotest
48
+ - .gitignore
49
+ - .gitmodules
50
+ - .rspec
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - Rakefile
54
+ - css3buttons.gemspec
55
+ - lib/css3buttons.rb
56
+ - lib/css3buttons/.DS_Store
57
+ - lib/css3buttons/button_group.rb
58
+ - lib/css3buttons/helpers/button_helper.rb
59
+ - lib/css3buttons/version.rb
60
+ - lib/generators/css3buttons/USAGE
61
+ - lib/generators/css3buttons/css3buttons_generator.rb
62
+ - readme.md
63
+ - spec/button_group_spec.rb
64
+ - spec/button_helper_spec.rb
65
+ - spec/spec_helper.rb
66
+ has_rdoc: true
67
+ homepage: https://github.com/thetron/css3buttons_rails_helpers
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project: css3buttons
96
+ rubygems_version: 1.3.7
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Easy, beautiful buttons, the CSS3 way.
100
+ test_files:
101
+ - spec/button_group_spec.rb
102
+ - spec/button_helper_spec.rb
103
+ - spec/spec_helper.rb