rails_html_helpers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44f9d0e76ba33b7b5163f52bf11107524cb9c31b
4
+ data.tar.gz: aefb292dd2f21a3590ccb6e832e498f186837c50
5
+ SHA512:
6
+ metadata.gz: 994065157493231ac0550f2fa69ae6a7225c12c2cf7f265cc4c4531fcc5d67b689dd46d2690cefef7db7df7cbd0067fbfa2857372ff5a6acd4e53a73feb5356c
7
+ data.tar.gz: 36651a644b345dc778f611b830cb1cd3ac97ee86eac40338e78f8d678af69ec55b3411e8a877207a11c012ea702539ba2e55428019e0e8c302d2f4cc885ea968
@@ -0,0 +1,11 @@
1
+ module RailsHTMLHelpers
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+
5
+ initializer 'rails_html_helpers.helper' do |app|
6
+ ActionController::Base.helper(RailsHTMLHelpers::Rails::Helpers)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,69 @@
1
+ module RailsHTMLHelpers
2
+ module Rails
3
+ module Helpers
4
+
5
+ # Sets and formats document title
6
+ #
7
+ # @param [Mixed]
8
+ # @param [String] Separator
9
+ # @return [String] Title
10
+ def title(t = nil, separator = " | ")
11
+ @title ||= []
12
+ @title << t
13
+ @title.flatten.compact.join(separator)
14
+ end
15
+
16
+
17
+ # Sets body classes
18
+ #
19
+ # @param [Mixed]
20
+ # @return [String] CSS classes
21
+ def body_class(c = nil)
22
+ @body_class ||= [controller.controller_name]
23
+ @body_class << c
24
+ @body_class.flatten.compact.uniq.join(" ")
25
+ end
26
+
27
+
28
+ # Helper to display conditional html tags for IE
29
+ #
30
+ # http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither
31
+ # has been originally lifted from the HTML5-rails gem:
32
+ # https://raw.github.com/sporkd/html5-rails/master/lib/html5/rails/helpers.rb
33
+ #
34
+ # @param [Hash] Attributes hash for HTML tag
35
+ # @return [String] HTML
36
+ def html_tag(attrs = {}, &block)
37
+ attrs.symbolize_keys!
38
+ html = "<!--[if lt IE 7]> #{ tag(:html, add_class('no-js lt-ie9 lt-ie8 lt-ie7', attrs), true) } <![endif]-->\n"
39
+ html << "<!--[if IE 7]> #{ tag(:html, add_class('no-js lt-ie9 lt-ie8', attrs), true) } <![endif]-->\n"
40
+ html << "<!--[if IE 8]> #{ tag(:html, add_class('no-js lt-ie9', attrs), true) } <![endif]-->\n"
41
+ html << "<!--[if gt IE 8]><!--> "
42
+
43
+ if block_given? && defined? Haml
44
+ haml_concat(html.html_safe)
45
+ haml_tag :html, add_class('no-js', attrs) do
46
+ haml_concat("<!--<![endif]-->".html_safe)
47
+ yield
48
+ end
49
+ else
50
+ html = html.html_safe
51
+ html << tag(:html, add_class('no-js', attrs), true)
52
+ html << " <!--<![endif]-->\n".html_safe
53
+ html
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def add_class(name, attrs)
60
+ classes = attrs[:class] || ''
61
+ classes.strip!
62
+ classes = ' ' + classes if !classes.empty?
63
+ classes = name + classes
64
+ attrs.merge(:class => classes)
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ require "rails_html_helpers/rails/engine"
2
+
3
+ module RailsHTMLHelpers
4
+ module Rails
5
+ autoload :Helpers, 'rails_html_helpers/rails/helpers'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Html
3
+ module Helpers
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require "rails_html_helpers/rails" if defined?(Rails)
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ class DummyContext < ActionView::Base; end
4
+
5
+ describe "RailsHTMLHelpers::Rails::Helpers" do
6
+
7
+ let(:helpers) { DummyContext.new.extend(RailsHTMLHelpers::Rails::Helpers) }
8
+
9
+ describe '#title' do
10
+ it 'should return a passed title partial' do
11
+ helpers.title('foo').should == 'foo'
12
+ end
13
+
14
+ it 'should join multiple definitions' do
15
+ helpers.title('foo')
16
+ helpers.title('bar').should == 'foo | bar'
17
+ end
18
+
19
+ it 'should return the title when no arguments passed' do
20
+ helpers.title('foo')
21
+ helpers.title.should == 'foo'
22
+ end
23
+
24
+ it 'should support a custom separator' do
25
+ helpers.title('foo')
26
+ helpers.title('bar', '+').should == 'foo+bar'
27
+ end
28
+
29
+ it 'should allow the passing of multiple partials as array' do
30
+ helpers.title(['foo', 'bar']).should == 'foo | bar'
31
+ end
32
+ end
33
+
34
+ describe '#body_class' do
35
+
36
+ before do
37
+ controller = double
38
+ helpers.stub(:controller) { controller }
39
+ controller.should_receive(:controller_name).and_return('foo')
40
+ end
41
+
42
+ it 'should return the controller name' do
43
+ helpers.body_class.should == 'foo'
44
+ end
45
+
46
+ it 'should include a passed class' do
47
+ helpers.body_class('bar').should == 'foo bar'
48
+ end
49
+
50
+ it 'should join multiple definitions' do
51
+ helpers.body_class('bar')
52
+ helpers.body_class('bat').should == 'foo bar bat'
53
+ end
54
+
55
+ it 'should return the class when no arguments passed' do
56
+ helpers.body_class('bar')
57
+ helpers.body_class.should == 'foo bar'
58
+ end
59
+
60
+ it 'should allow the passing of multiple classes as array' do
61
+ helpers.body_class(['bar', 'bat']).should == 'foo bar bat'
62
+ end
63
+ end
64
+
65
+ describe '#html_tag' do
66
+ it 'should produce a set of conditional tags' do
67
+ helpers.html_tag.should == <<-EOS
68
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
69
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
70
+ <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
71
+ <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
72
+ EOS
73
+ end
74
+
75
+ it 'should assign attributes' do
76
+ helpers.html_tag(:foo => 'bar').should == <<-EOS
77
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" foo="bar"> <![endif]-->
78
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" foo="bar"> <![endif]-->
79
+ <!--[if IE 8]> <html class="no-js lt-ie9" foo="bar"> <![endif]-->
80
+ <!--[if gt IE 8]><!--> <html class="no-js" foo="bar"> <!--<![endif]-->
81
+ EOS
82
+ end
83
+
84
+ it 'should merge classes' do
85
+ helpers.html_tag(:class => 'foo').should == <<-EOS
86
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7 foo"> <![endif]-->
87
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8 foo"> <![endif]-->
88
+ <!--[if IE 8]> <html class="no-js lt-ie9 foo"> <![endif]-->
89
+ <!--[if gt IE 8]><!--> <html class="no-js foo"> <!--<![endif]-->
90
+ EOS
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails/engine'
2
+ require 'action_view'
3
+
4
+ require 'rspec'
5
+
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'rails_html_helpers')
7
+
8
+ RSpec.configure do |config|
9
+ config.order = 'random'
10
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_html_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Plank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: A bunch of frequently used HTML helpers for Rails apps.
56
+ email:
57
+ - florian@polarblau.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/rails_html_helpers.rb
63
+ - lib/rails_html_helpers/rails.rb
64
+ - lib/rails_html_helpers/rails/engine.rb
65
+ - lib/rails_html_helpers/rails/helpers.rb
66
+ - lib/rails_html_helpers/version.rb
67
+ - spec/lib/rails_html_helpers/rails/helpers_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: https://github.com/polarblau/rails-html-helpers
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project: '[none]'
89
+ rubygems_version: 2.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Collection of HTML helpers
93
+ test_files:
94
+ - spec/lib/rails_html_helpers/rails/helpers_spec.rb
95
+ - spec/spec_helper.rb