rails-helper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bdac9e9da8066627164f83b5494fce5ce2a02257
4
+ data.tar.gz: 21bb90dfe179d5ec2761f93191b42ed282558e7d
5
+ SHA512:
6
+ metadata.gz: 6d865a6a48ee72945044b08ab832732e9a82b1b1d7c4170a9d9ce898a16e9a5997a4173d8ff20455d806d7a0316bc3138ac8e92081715c972ab3e2b785adb995
7
+ data.tar.gz: b9a7df99696c2e016318df93770d87fae6adbfc4de92e62180b8bea463fffd8e845639fb064d9da5c08a97f348f11e9b5040b8366660b06d1ef3b86964990cb5
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ # v0.1.0 / 2015-05-25
2
+
3
+ Create project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-helper.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Chen Yi-Cyuan
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.
@@ -0,0 +1,51 @@
1
+ # rails-helper
2
+
3
+ Provides more helper methods for rails.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails-helper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rails-helper
18
+
19
+ ## Usage
20
+
21
+ ### classes(*arg)
22
+ Generate css class names string.
23
+
24
+ #### *arg: `Hash`, `Array` or `String`
25
+ Hash keys will output class name if value is true. Array or string will output class names.
26
+
27
+ ```Ruby
28
+ classes("class1", :class2 => true, :class3 => false)
29
+ ```
30
+ Output
31
+
32
+ "class1 class2"
33
+
34
+ It's useful for that conditional class names. Following is an example of haml:
35
+ ```Haml
36
+ %li{:class => classes(:active => active?)
37
+ ```
38
+ If true
39
+ ```Html
40
+ <li class="active">
41
+ ```
42
+ Or
43
+ ```Html
44
+ <li class>
45
+ ```
46
+ ## License
47
+ The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
48
+
49
+ ## Contact
50
+ The project's website is located at https://github.com/emn178/rails-helper
51
+ Author: emn178@gmail.com
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ require "rails-helper/version"
2
+ require "rails-helper/attribute"
3
+
4
+ module RailsHelper
5
+ if defined?(::Rails::Engine)
6
+ class Engine < ::Rails::Engine
7
+ initializer "rails-helper" do
8
+ ActiveSupport.on_load(:action_view) do
9
+ include RailsHelper::Attribute
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module RailsHelper
2
+ module Attribute
3
+ def classes(*args)
4
+ classes = []
5
+ args.each do |arg|
6
+ if arg.is_a?(Hash)
7
+ classes << arg.select { |key, value| value }.keys
8
+ else
9
+ classes << arg unless arg.nil?
10
+ end
11
+ end
12
+ classes.join(" ")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module RailsHelper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails-helper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-helper"
8
+ spec.version = RailsHelper::VERSION
9
+ spec.authors = ["Chen Yi-Cyuan"]
10
+ spec.email = ["emn178@gmail.com"]
11
+ spec.description = %q{Provides more helper methods for rails. Generate css class names...}
12
+ spec.summary = %q{Provides more helper methods for rails.}
13
+ spec.homepage = "https://github.com/emn178/rails-helper"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "rspec", "~> 3.2"
21
+ end
@@ -0,0 +1,25 @@
1
+ RSpec.describe RailsHelper::Attribute do
2
+ include RailsHelper::Attribute
3
+
4
+ describe "#classes" do
5
+ context "when hash" do
6
+ subject { classes(:class1 => true, :class2 => false, :class3 => true) }
7
+ it { should eq "class1 class3" }
8
+ end
9
+
10
+ context "when hash and string" do
11
+ subject { classes({:class1 => true, :class2 => false, :class3 => true}, "class4 class5") }
12
+ it { should eq "class1 class3 class4 class5" }
13
+ end
14
+
15
+ context "when hash and array" do
16
+ subject { classes({:class1 => true, :class2 => false, :class3 => true}, ["class4", "class5"]) }
17
+ it { should eq "class1 class3 class4 class5" }
18
+ end
19
+
20
+ context "when string and hash" do
21
+ subject { classes( "class4 class5", :class1 => true, :class2 => false, :class3 => true) }
22
+ it { should eq "class4 class5 class1 class3" }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,93 @@
1
+ require 'rails-helper'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is
56
+ # recommended. For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chen Yi-Cyuan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: Provides more helper methods for rails. Generate css class names...
28
+ email:
29
+ - emn178@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - CHANGELOG.md
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - lib/rails-helper.rb
42
+ - lib/rails-helper/attribute.rb
43
+ - lib/rails-helper/version.rb
44
+ - rails-helper.gemspec
45
+ - spec/attribute_spec.rb
46
+ - spec/spec_helper.rb
47
+ homepage: https://github.com/emn178/rails-helper
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.2.2
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Provides more helper methods for rails.
71
+ test_files:
72
+ - spec/attribute_spec.rb
73
+ - spec/spec_helper.rb