classes 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
+ SHA256:
3
+ metadata.gz: c7d8b60537ea194c8a560b6ed425f8624e6a11da30c5e2f0d187cede216f3d7f
4
+ data.tar.gz: 3254c277e5ccf9f9d84069064d385ee41fdfe5329b717bdb00a80160546c33c7
5
+ SHA512:
6
+ metadata.gz: e2ee05e00318a1f17cd9da0174ea46b182259bba4111fe929a3937cee3f0044c3071de18993cdb93e3353feb6e4c374f72ac70e0a2ab6d4047ac50649314b6ac
7
+ data.tar.gz: 4b4bf26477a0cba3fec6cc4156c47b4ee2d7ade6f1dd776ccbd0a2bf9bd6443bab4459ea3bc59ea6bbfa8978605021f45a193d0b500a6a266d5a09b65b02f10b
@@ -0,0 +1,31 @@
1
+ name: Tests
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ name: Run Tests
8
+
9
+ strategy:
10
+ matrix:
11
+ ruby-version: [2.5, 2.6, 2.7]
12
+
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+
23
+ - name: Install gems
24
+ run: |
25
+ gem install bundler
26
+ bundle install --jobs 4 --retry 3
27
+
28
+ - name: Run tests
29
+ run: |
30
+ bundle exec rubocop
31
+ bundle exec rake
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,83 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ Layout/EmptyLinesAroundAccessModifier:
5
+ EnforcedStyle: only_before
6
+
7
+ Layout/ExtraSpacing:
8
+ AllowForAlignment: false
9
+
10
+ Layout/IndentationConsistency:
11
+ EnforcedStyle: indented_internal_methods
12
+
13
+ Layout/LineLength:
14
+ Enabled: false
15
+
16
+ Layout/SpaceAroundMethodCallOperator:
17
+ Enabled: true
18
+
19
+ Lint/RaiseException:
20
+ Enabled: true
21
+
22
+ Lint/StructNewOverride:
23
+ Enabled: true
24
+
25
+ Metrics:
26
+ Enabled: false
27
+
28
+ Style/AndOr:
29
+ Enabled: false
30
+
31
+ Style/ClassAndModuleChildren:
32
+ Enabled: false
33
+
34
+ Style/ConditionalAssignment:
35
+ Enabled: false
36
+
37
+ Style/Documentation:
38
+ Enabled: false
39
+
40
+ Style/EmptyMethod:
41
+ Enabled: false
42
+
43
+ Style/ExponentialNotation:
44
+ Enabled: false
45
+
46
+ Style/FormatStringToken:
47
+ Enabled: false
48
+
49
+ Style/GuardClause:
50
+ Enabled: false
51
+
52
+ Style/HashEachMethods:
53
+ Enabled: true
54
+
55
+ Style/HashTransformKeys:
56
+ Enabled: true
57
+
58
+ Style/HashTransformValues:
59
+ Enabled: true
60
+
61
+ Style/IfInsideElse:
62
+ Enabled: false
63
+
64
+ Style/IfUnlessModifier:
65
+ Enabled: false
66
+
67
+ Style/NumericLiterals:
68
+ Enabled: false
69
+
70
+ Style/SafeNavigation:
71
+ Enabled: false
72
+
73
+ Style/StringLiterals:
74
+ EnforcedStyle: double_quotes
75
+
76
+ Style/StringLiteralsInInterpolation:
77
+ EnforcedStyle: double_quotes
78
+
79
+ Style/SymbolArray:
80
+ Enabled: false
81
+
82
+ Style/WordArray:
83
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in classes.gemspec
6
+ gemspec
7
+
8
+ gem "minitest", "~> 5.0"
9
+ gem "rake", "~> 12.0"
10
+ gem "rubocop", "~> 0.82.0", require: false
11
+ gem "rubocop-performance", "~> 1.5", require: false
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ classes (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ jaro_winkler (1.5.4)
11
+ minitest (5.14.0)
12
+ parallel (1.19.1)
13
+ parser (2.7.1.2)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (12.3.3)
17
+ rexml (3.2.4)
18
+ rubocop (0.82.0)
19
+ jaro_winkler (~> 1.5.1)
20
+ parallel (~> 1.10)
21
+ parser (>= 2.7.0.1)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ rexml
24
+ ruby-progressbar (~> 1.7)
25
+ unicode-display_width (>= 1.4.0, < 2.0)
26
+ rubocop-performance (1.5.2)
27
+ rubocop (>= 0.71.0)
28
+ ruby-progressbar (1.10.1)
29
+ unicode-display_width (1.7.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ classes!
36
+ minitest (~> 5.0)
37
+ rake (~> 12.0)
38
+ rubocop (~> 0.82.0)
39
+ rubocop-performance (~> 1.5)
40
+
41
+ BUNDLED WITH
42
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright 2020 Todd Yandell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # classes
2
+
3
+ classes is a Ruby gem that lets you do:
4
+
5
+ ```erb
6
+ <div class="<%= classes("notification", "is-danger": alert, "is-info": notice) %>">
7
+ <%= alert || notice %>
8
+ </div>
9
+ ```
10
+
11
+ It was inspired by the [Classnames](https://github.com/JedWatson/classnames) npm package.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ bundle add classes
17
+ ```
18
+
19
+ ### Rails
20
+
21
+ Just start using `classes` in your views!
22
+
23
+ ### Sinatra
24
+
25
+ First, `require` classes:
26
+
27
+ ```ruby
28
+ require "classes"
29
+ ```
30
+
31
+ For classic Sinatra apps, you're done.
32
+
33
+ For modular Sinatra apps, you'll also need to include the helpers:
34
+
35
+ ```ruby
36
+ class App < Sinatra::Base
37
+ helpers Classes::Helpers
38
+ end
39
+ ```
40
+
41
+ Now you can start using `classes` in your views!
42
+
43
+ ## Use
44
+
45
+ The simplest use for classes is to join some strings together:
46
+
47
+ ```ruby
48
+ classes("button", "is-link").to_s # => "button is-link"
49
+ ```
50
+
51
+ A hash makes it easy to conditionally enable classes:
52
+
53
+ ```ruby
54
+ classes("button", "is-link": true, "is-danger": false).to_s # => "button is-link"
55
+ ```
56
+
57
+ classes flattens and de-dupes your classes:
58
+
59
+ ```ruby
60
+ classes(["button", ["button is-link", ["is-link"]]]).to_s # => "button is-link"
61
+ ```
62
+
63
+ You can combine these features as much as you like:
64
+
65
+ ```ruby
66
+ classes(
67
+ :button, # Symbols are converted to strings.
68
+ "is-link is-light",
69
+ { "is-link": true, "is-danger": false },
70
+ [true && "is-link", false && "is-danger"],
71
+ "is-light",
72
+ classes("is-fullwidth": true), # You can nest Classes::ClassList instances.
73
+ " " # Empty or invalid classes are ignored.
74
+ ).to_s # => "button is-link is-light is-fullwidth"
75
+ ```
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "classes"
6
+
7
+ require "irb"
8
+ IRB.start __FILE__
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/classes/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "classes"
7
+ spec.version = Classes::VERSION
8
+ spec.authors = ["Todd Yandell"]
9
+ spec.email = ["tyandell@gmail.com"]
10
+
11
+ spec.summary = "A helper for building CSS class names"
12
+ spec.description = "classes is a helper for building CSS class names in your Rails or Sinatra views. It's great for toggling individual classes or combining class names across your views and partials."
13
+ spec.homepage = "https://github.com/tyandell/classes"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "classes/version"
4
+ require "classes/class_list"
5
+ require "classes/helpers"
6
+
7
+ if defined? Rails::Railtie
8
+ require "classes/railtie"
9
+ end
10
+
11
+ if defined? Sinatra
12
+ require "classes/sinatra"
13
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Classes
4
+ class ClassList < Set
5
+ def self.parse(str)
6
+ new(str.scan(/[^\s]+/))
7
+ end
8
+
9
+ def add(arg)
10
+ return self unless arg
11
+
12
+ if arg.is_a?(Hash)
13
+ arg = arg.map { |k, v| v && k }
14
+ end
15
+
16
+ unless arg.is_a?(Enumerable)
17
+ arg = arg.to_s
18
+ return self if arg.empty?
19
+
20
+ if arg.match?(/\s/)
21
+ arg = self.class.parse(arg)
22
+ else
23
+ return super(arg)
24
+ end
25
+ end
26
+
27
+ merge(arg)
28
+ end
29
+
30
+ alias << add
31
+
32
+ def to_s
33
+ to_a.join(" ")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Classes
4
+ module Helpers
5
+ def classes(*args)
6
+ ClassList.new.merge(args)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Classes
4
+ class Railtie < Rails::Railtie
5
+ initializer "classes" do
6
+ ActiveSupport.on_load :action_view do
7
+ include Classes::Helpers
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Sinatra.helpers Classes::Helpers
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Classes
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: classes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Todd Yandell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: classes is a helper for building CSS class names in your Rails or Sinatra
14
+ views. It's great for toggling individual classes or combining class names across
15
+ your views and partials.
16
+ email:
17
+ - tyandell@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".github/workflows/tests.yml"
23
+ - ".gitignore"
24
+ - ".rubocop.yml"
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - classes.gemspec
33
+ - lib/classes.rb
34
+ - lib/classes/class_list.rb
35
+ - lib/classes/helpers.rb
36
+ - lib/classes/railtie.rb
37
+ - lib/classes/sinatra.rb
38
+ - lib/classes/version.rb
39
+ homepage: https://github.com/tyandell/classes
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ allowed_push_host: https://rubygems.org
44
+ source_code_uri: https://github.com/tyandell/classes
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.5.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.0.3
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A helper for building CSS class names
64
+ test_files: []