erector-conditional_classes 0.0.1

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: ff1e7da1404034ddee16072b97d4844aca3ad2a1
4
+ data.tar.gz: 4f0b7d7a9cefae60487729036e86a09cf6cf28ea
5
+ SHA512:
6
+ metadata.gz: 76cc4b7c70827da6ad5f48de7f8da8fb6766f97a6900fd979fae8b584302a688c4c6d84ee2304750b6319dd76524e85d34a9e50364a9bb9994ffd5cf3248e27f
7
+ data.tar.gz: 6d3d92124085546ff9db7219c4627bfb1220e0f682bdddfe4f059a924a62d8cbbe1e463da3293b6d8c7a5fab2a3b33e0bd5cb38e4f0a8a45819c3cccf62ee5e1
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in erector-conditional_classes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Scott Fleckenstein
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Erector::ConditionalClasses
2
+
3
+ erector-conditional_classes is a rubygem that makes using the conditional
4
+ application of html classes in your views nicer.
5
+
6
+ Erector provides a wonderful chain-based api for applying classes to an element:
7
+
8
+ ```ruby
9
+ span.foo.bar.baz "hello" # => '<span class="foo bar baz">hello</span>'
10
+ ```
11
+
12
+ The pain comes when you need to conditionally apply classes to an element:
13
+
14
+ ```ruby
15
+ classes = [:foo]
16
+ classes << :bar if some_condition?
17
+
18
+ span("hello", :class => classes) # => '<span class="foo">hello</span>'
19
+ ```
20
+
21
+ This gem provides support in the chaining API for conditionals:
22
+
23
+ ```ruby
24
+ #block based
25
+ span.foo.bar(:if => some_condition?){ text "hello" } # => '<span class="foo">hello</span>'
26
+
27
+ # non-block content
28
+ span("hello").foo.bar(:if => some_condition?) # => '<span class="foo">hello</span>'
29
+ ```
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ gem 'erector-conditional_classes'
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install erector-conditional_classes
44
+
45
+ ## Usage
46
+
47
+ just:
48
+
49
+ ```ruby
50
+ require 'erector/conditional_classes'
51
+ ```
52
+
53
+ and your good to go.
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'erector/conditional_classes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "erector-conditional_classes"
8
+ spec.version = Erector::ConditionalClasses::VERSION
9
+ spec.authors = ["Scott Fleckenstein"]
10
+ spec.email = ["nullstyle@gmail.com"]
11
+ spec.description = %q{Erector extension for conditional classes}
12
+ spec.summary = %q{Adds helpers to make conditional classes on an element more friendly}
13
+ spec.homepage = "https://github.com/nullstyle/erector-conditional_classes"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+
25
+ spec.add_dependency "erector", "~> 0.9.0"
26
+ spec.add_dependency "activesupport", ">= 3.0.0"
27
+ end
@@ -0,0 +1,35 @@
1
+ require "erector/conditional_classes/version"
2
+ require 'active_support/concern'
3
+ require 'active_support/core_ext/module/aliasing'
4
+ require 'erector'
5
+
6
+ module Erector
7
+ module ConditionalClasses
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ alias_method_chain :method_missing, :conditionals
12
+ end
13
+
14
+ def method_missing_with_conditionals(method_name, *args, &block)
15
+ if args.last.is_a?(Hash) && args.last.has_key?(:if)
16
+ should_render = args.last.delete(:if)
17
+ should_render = should_render.call if should_render.respond_to?(:call)
18
+
19
+ unless should_render
20
+ # hacky: we set the block at this level
21
+ # so even if bail out because we shouldn't render the class
22
+ # we still get expected behavior on the final member of a chain
23
+ @inside_renderer = block if block_given?
24
+ _render
25
+ return self
26
+ end
27
+ end
28
+
29
+ method_missing_without_conditionals(method_name, *args, &block)
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ Erector::Promise.send(:include, Erector::ConditionalClasses)
@@ -0,0 +1,5 @@
1
+ module Erector
2
+ module ConditionalClasses
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erector-conditional_classes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Fleckenstein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: erector
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ description: Erector extension for conditional classes
84
+ email:
85
+ - nullstyle@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - erector-conditional_classes.gemspec
96
+ - lib/erector/conditional_classes.rb
97
+ - lib/erector/conditional_classes/version.rb
98
+ homepage: https://github.com/nullstyle/erector-conditional_classes
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.0.0
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Adds helpers to make conditional classes on an element more friendly
122
+ test_files: []
123
+ has_rdoc: