class_name 1.0.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
+ SHA256:
3
+ metadata.gz: 1448df3204bd9c543972ed141a9e7091d4faee5954b8c325f712b55a0541f7c3
4
+ data.tar.gz: da239b43e8f807444e59b42c4224cdbb487b2ae66d0ff57eb03cc9011876f989
5
+ SHA512:
6
+ metadata.gz: e7e3ab29185c71986bba9429a7afb6959b61de50576c377b5aa805ca225a15420870b0de7a20acbb270f0139e1ee604923b8f76f90432e49230bd4e3eaedae50
7
+ data.tar.gz: 2e2bb1579df100b9c0c5b0b51a5cacac11e0c9132754f06e1c849d555053eb57c3801806028fbdb583fec21ededdd1759e8834817aefe85df3650e6e6dd9f773
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # class_name
2
+
3
+ [![Build Status](https://travis-ci.com/invisiblehats/class_name.svg?branch=master)](https://travis-ci.com/invisiblehats/class_name)
4
+ [![Code Climate](https://codeclimate.com/github/invisiblehats/class_name.svg)](https://codeclimate.com/github/invisiblehats/class_name)
5
+ [![Inline docs](http://inch-ci.org/github/invisiblehats/class_name.svg)](http://inch-ci.org/github/invisiblehats/class_name)
6
+ [![Security](https://hakiri.io/github/invisiblehats/class_name/master.svg)](https://hakiri.io/github/invisiblehats/class_name/master)
7
+
8
+ A ruby implementation of Node's [classnames](https://www.npmjs.com/package/classnames) package.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'class_name', github: 'invisiblehats/class_name'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install class_name
25
+
26
+ ## Usage
27
+
28
+ Add this line to `ApplicationHelper`:
29
+ ```ruby
30
+ module ApplicationHelper
31
+ include ClassName
32
+ end
33
+ ```
34
+
35
+ Then use it in your view templates:
36
+ ```html
37
+ <div class="<%= class_name('ui card', fluid: false, { blue: true }) %>"></div>
38
+ ```
39
+
40
+ Would generate:
41
+ ```html
42
+ <div class="ui card blue"></div>
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/invisiblehats/class_name. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
58
+
59
+ ## Code of Conduct
60
+
61
+ Everyone interacting in the ClassName project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/class_name/blob/master/CODE_OF_CONDUCT.md).
62
+
63
+ ## Development team
64
+ ### People
65
+ - [Myk Klemme - @mklemme](https://github.com/mklemme) Lead developer and maintainer for this project.
66
+ ### Partners
67
+ - [Invisible Hat Ventures - @invisiblehats](https://github.com/invisiblehats) A private startup development agency
68
+ - [Love.irish - @love-irish](https://github.com/love-irish) A lifestyle-as-a-service for the Irish language
69
+ - [League of Celts - @league-of-celts](https://github.com/league-of-celts) A non-profit focused on promoting Celtic languages
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ClassName'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,25 @@
1
+ module ClassName
2
+ class << self
3
+ attr_writer :configuration
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.reset
11
+ @configuration = Configuration.new
12
+ end
13
+
14
+ def self.configure
15
+ yield(configuration)
16
+ end
17
+
18
+ class Configuration
19
+ attr_accessor :foo
20
+
21
+ def initialize
22
+ @foo = 'bar'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ module ClassName
2
+ module Helper
3
+ #
4
+ # Conditionally joins a set of CSS class names into a single string
5
+ #
6
+ # @param css_map [Hash] a mapping of CSS class names to boolean values
7
+ # @return [String] a combined string of CSS classes where the value was true
8
+ # @example Create a css string from a complex object
9
+ # class_name(
10
+ # "base",
11
+ # "carl-the-fog",
12
+ # hidden: article.has_chart?,
13
+ # [:foo, :bar] => false,
14
+ # [:foobar] => true
15
+ # )
16
+ # => "base carl-the-fog foobar"
17
+ #
18
+ # read more about this [module](http://www.carlosramireziii.com/a-cleaner-way-to-set-multiple-conditional-css-classes-for-link-to.html)
19
+ #
20
+ def class_name(*css_map)
21
+ classes = []
22
+ css_map.flatten.reject(&:blank?).each do |css, bool|
23
+ case css.class.to_s
24
+ when "Integer", "Fixnum"
25
+ classes << ClassName::NumberConverter.to_word(css)
26
+ when "String"
27
+ classes << css
28
+ when "Array"
29
+ classes << css.join(" ")
30
+ when "Hash"
31
+ css.each do |hash_css, bool|
32
+ classes << hash_css if bool
33
+ end
34
+ end
35
+ end
36
+
37
+ classes.join(" ")
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ module ClassName
2
+ module NumberConverter
3
+ class << self
4
+ # @return [String] Converts the integer to the human word (up to 16 for our grids. Feel free to extend support)
5
+ def to_word integer
6
+ case integer
7
+ when 0
8
+ "zero"
9
+ when 1
10
+ "one"
11
+ when 2
12
+ "two"
13
+ when 3
14
+ "three"
15
+ when 4
16
+ "four"
17
+ when 5
18
+ "five"
19
+ when 6
20
+ "six"
21
+ when 7
22
+ "seven"
23
+ when 8
24
+ "eight"
25
+ when 9
26
+ "nine"
27
+ when 10
28
+ "ten"
29
+ when 11
30
+ "eleven"
31
+ when 12
32
+ "twelve"
33
+ when 13
34
+ "thirteen"
35
+ when 14
36
+ "fourteen"
37
+ when 15
38
+ "fifteen"
39
+ when 16
40
+ "sixteen"
41
+ else
42
+ integer
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,4 @@
1
+ # module ClassName
2
+ # class Railtie < ::Rails::Railtie
3
+ # end
4
+ # end
@@ -0,0 +1,3 @@
1
+ module ClassName
2
+ VERSION = '1.0.0'
3
+ end
data/lib/class_name.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "active_support"
2
+ require "active_support/core_ext"
3
+ require "class_name/railtie"
4
+ require "class_name/configuration"
5
+ require "class_name/helper"
6
+ require "class_name/number_converter"
7
+
8
+ module ClassName
9
+ include ClassName::Helper
10
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: class_name
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Myk Klemme
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Generate dynamic class strings easily
84
+ email:
85
+ - mykklemme@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - Rakefile
92
+ - lib/class_name.rb
93
+ - lib/class_name/configuration.rb
94
+ - lib/class_name/helper.rb
95
+ - lib/class_name/number_converter.rb
96
+ - lib/class_name/railtie.rb
97
+ - lib/class_name/version.rb
98
+ homepage: https://github.cominvisiblehats/class_name
99
+ licenses:
100
+ - GNU General Public License v3.0
101
+ metadata:
102
+ allowed_push_host: https://rubygems.org/
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.0.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Generate dynamic class strings easily
122
+ test_files: []