view_component-styles 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7047860194ebfc08bea90c9306a4881d7282ed708e20cb5cb45c7cfce0e0fa3
4
+ data.tar.gz: 5995e1a0e94a23889483380d4ae26abbf25ce4632dc5008fd7d7cc1b3287f2de
5
+ SHA512:
6
+ metadata.gz: f546a36658662db1cc7aa20283965da3477be5ee20f01b0cbac6c34cfac2ada1068e389356d7efa602c5a9cca8653438750859e75077766a1edca89e1694b76b
7
+ data.tar.gz: 206c6ab35a36db08b0baef9b4bcae2c5a5ceaa7e9b1bdbe8fe26d55ed4466a10a02360b2b56cfe26d1e0d8897ed29531be99a7cdb500a46c0419740cfabaad95
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: single_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in view_component-styles.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ gem 'rubocop', '~> 1.7'
data/Gemfile.lock ADDED
@@ -0,0 +1,195 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ view_component-styles (0.1.0)
5
+ rails (>= 5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (7.0.3)
11
+ actionpack (= 7.0.3)
12
+ activesupport (= 7.0.3)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (7.0.3)
16
+ actionpack (= 7.0.3)
17
+ activejob (= 7.0.3)
18
+ activerecord (= 7.0.3)
19
+ activestorage (= 7.0.3)
20
+ activesupport (= 7.0.3)
21
+ mail (>= 2.7.1)
22
+ net-imap
23
+ net-pop
24
+ net-smtp
25
+ actionmailer (7.0.3)
26
+ actionpack (= 7.0.3)
27
+ actionview (= 7.0.3)
28
+ activejob (= 7.0.3)
29
+ activesupport (= 7.0.3)
30
+ mail (~> 2.5, >= 2.5.4)
31
+ net-imap
32
+ net-pop
33
+ net-smtp
34
+ rails-dom-testing (~> 2.0)
35
+ actionpack (7.0.3)
36
+ actionview (= 7.0.3)
37
+ activesupport (= 7.0.3)
38
+ rack (~> 2.0, >= 2.2.0)
39
+ rack-test (>= 0.6.3)
40
+ rails-dom-testing (~> 2.0)
41
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
42
+ actiontext (7.0.3)
43
+ actionpack (= 7.0.3)
44
+ activerecord (= 7.0.3)
45
+ activestorage (= 7.0.3)
46
+ activesupport (= 7.0.3)
47
+ globalid (>= 0.6.0)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (7.0.3)
50
+ activesupport (= 7.0.3)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.4)
53
+ rails-dom-testing (~> 2.0)
54
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
55
+ activejob (7.0.3)
56
+ activesupport (= 7.0.3)
57
+ globalid (>= 0.3.6)
58
+ activemodel (7.0.3)
59
+ activesupport (= 7.0.3)
60
+ activerecord (7.0.3)
61
+ activemodel (= 7.0.3)
62
+ activesupport (= 7.0.3)
63
+ activestorage (7.0.3)
64
+ actionpack (= 7.0.3)
65
+ activejob (= 7.0.3)
66
+ activerecord (= 7.0.3)
67
+ activesupport (= 7.0.3)
68
+ marcel (~> 1.0)
69
+ mini_mime (>= 1.1.0)
70
+ activesupport (7.0.3)
71
+ concurrent-ruby (~> 1.0, >= 1.0.2)
72
+ i18n (>= 1.6, < 2)
73
+ minitest (>= 5.1)
74
+ tzinfo (~> 2.0)
75
+ ast (2.4.2)
76
+ builder (3.2.4)
77
+ concurrent-ruby (1.1.10)
78
+ crass (1.0.6)
79
+ diff-lcs (1.5.0)
80
+ digest (3.1.0)
81
+ erubi (1.10.0)
82
+ globalid (1.0.0)
83
+ activesupport (>= 5.0)
84
+ i18n (1.10.0)
85
+ concurrent-ruby (~> 1.0)
86
+ loofah (2.18.0)
87
+ crass (~> 1.0.2)
88
+ nokogiri (>= 1.5.9)
89
+ mail (2.7.1)
90
+ mini_mime (>= 0.1.1)
91
+ marcel (1.0.2)
92
+ method_source (1.0.0)
93
+ mini_mime (1.1.2)
94
+ minitest (5.15.0)
95
+ net-imap (0.2.3)
96
+ digest
97
+ net-protocol
98
+ strscan
99
+ net-pop (0.1.1)
100
+ digest
101
+ net-protocol
102
+ timeout
103
+ net-protocol (0.1.3)
104
+ timeout
105
+ net-smtp (0.3.1)
106
+ digest
107
+ net-protocol
108
+ timeout
109
+ nio4r (2.5.8)
110
+ nokogiri (1.13.6-arm64-darwin)
111
+ racc (~> 1.4)
112
+ parallel (1.22.1)
113
+ parser (3.1.2.0)
114
+ ast (~> 2.4.1)
115
+ racc (1.6.0)
116
+ rack (2.2.3.1)
117
+ rack-test (1.1.0)
118
+ rack (>= 1.0, < 3)
119
+ rails (7.0.3)
120
+ actioncable (= 7.0.3)
121
+ actionmailbox (= 7.0.3)
122
+ actionmailer (= 7.0.3)
123
+ actionpack (= 7.0.3)
124
+ actiontext (= 7.0.3)
125
+ actionview (= 7.0.3)
126
+ activejob (= 7.0.3)
127
+ activemodel (= 7.0.3)
128
+ activerecord (= 7.0.3)
129
+ activestorage (= 7.0.3)
130
+ activesupport (= 7.0.3)
131
+ bundler (>= 1.15.0)
132
+ railties (= 7.0.3)
133
+ rails-dom-testing (2.0.3)
134
+ activesupport (>= 4.2.0)
135
+ nokogiri (>= 1.6)
136
+ rails-html-sanitizer (1.4.2)
137
+ loofah (~> 2.3)
138
+ railties (7.0.3)
139
+ actionpack (= 7.0.3)
140
+ activesupport (= 7.0.3)
141
+ method_source
142
+ rake (>= 12.2)
143
+ thor (~> 1.0)
144
+ zeitwerk (~> 2.5)
145
+ rainbow (3.1.1)
146
+ rake (13.0.6)
147
+ regexp_parser (2.5.0)
148
+ rexml (3.2.5)
149
+ rspec (3.11.0)
150
+ rspec-core (~> 3.11.0)
151
+ rspec-expectations (~> 3.11.0)
152
+ rspec-mocks (~> 3.11.0)
153
+ rspec-core (3.11.0)
154
+ rspec-support (~> 3.11.0)
155
+ rspec-expectations (3.11.0)
156
+ diff-lcs (>= 1.2.0, < 2.0)
157
+ rspec-support (~> 3.11.0)
158
+ rspec-mocks (3.11.1)
159
+ diff-lcs (>= 1.2.0, < 2.0)
160
+ rspec-support (~> 3.11.0)
161
+ rspec-support (3.11.0)
162
+ rubocop (1.30.1)
163
+ parallel (~> 1.10)
164
+ parser (>= 3.1.0.0)
165
+ rainbow (>= 2.2.2, < 4.0)
166
+ regexp_parser (>= 1.8, < 3.0)
167
+ rexml (>= 3.2.5, < 4.0)
168
+ rubocop-ast (>= 1.18.0, < 2.0)
169
+ ruby-progressbar (~> 1.7)
170
+ unicode-display_width (>= 1.4.0, < 3.0)
171
+ rubocop-ast (1.18.0)
172
+ parser (>= 3.1.1.0)
173
+ ruby-progressbar (1.11.0)
174
+ strscan (3.0.3)
175
+ thor (1.2.1)
176
+ timeout (0.3.0)
177
+ tzinfo (2.0.4)
178
+ concurrent-ruby (~> 1.0)
179
+ unicode-display_width (2.1.0)
180
+ websocket-driver (0.7.5)
181
+ websocket-extensions (>= 0.1.0)
182
+ websocket-extensions (0.1.5)
183
+ zeitwerk (2.5.4)
184
+
185
+ PLATFORMS
186
+ arm64-darwin-21
187
+
188
+ DEPENDENCIES
189
+ rake (~> 13.0)
190
+ rspec (~> 3.0)
191
+ rubocop (~> 1.7)
192
+ view_component-styles!
193
+
194
+ BUNDLED WITH
195
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 ryantaylor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # View Component Styles
2
+
3
+ Stylesheet aggregation for view components. Automatically combines component-specific stylesheets into a single sheet
4
+ that can be included in a single location. Great for using components in mailers, aggregating styles, then loading them
5
+ all at once so they can be pulled into premailer.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'view_component-styles'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install view_component-styles
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ class ApplicationComponent < ViewComponent::Base
27
+ include ViewComponent::Styles::Component
28
+ end
29
+ ```
30
+ ```ruby
31
+ class ApplicationMailer < ActionMailer::Base
32
+ include ViewComponent::Styles::Controller
33
+ helper ViewComponent::Styles::Helper
34
+ end
35
+ ```
36
+ Then just create a component and a matching CSS/SCSS file like so:
37
+
38
+ `components/user_component.rb`
39
+ ```ruby
40
+ class UserComponent < ApplicationComponent
41
+ def initialize(user)
42
+ @user = user
43
+ end
44
+ end
45
+ ```
46
+ `components/user_component.scss`
47
+ ```scss
48
+ .name {
49
+ font-style: italic;
50
+ }
51
+ ```
52
+ `components/user_component.html.erb`
53
+ ```html
54
+ <div class="name">
55
+ <%= @user.name %>
56
+ </div>
57
+ ```
58
+ In your layout, all you have to do is include the single stylesheet tag:
59
+
60
+ `views/layouts/layout.html.erb`
61
+ ```html
62
+ <html>
63
+ <head>
64
+ <%= singleton_stylesheet_link_tags %>
65
+ </head>
66
+ <body>
67
+ <%= yield %>
68
+ </body>
69
+ </html>
70
+ ```
71
+ At this point you're all set up! Whenever a component is included in a view that renders inside the configured layout,
72
+ styles will be aggregated into a single stylesheet and then loaded right into the layout. From here, they can be
73
+ rendered regularly or picked up by premailer for inlining.
74
+
75
+ ## Development
76
+
77
+ 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.
78
+
79
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thriver/view_component-styles.
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'view_component/styles'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module Styles
5
+ module Component
6
+ include ViewComponent::Styles::Helper
7
+
8
+ # @param path [String]
9
+ # @return [Boolean]
10
+ def asset_exists?(path)
11
+ if Rails.configuration.assets.compile
12
+ # Dynamic compilation
13
+ Rails.application.assets.find_asset(path).present?
14
+ else
15
+ # Pre-compiled
16
+ Rails.application.assets_manifest.assets[path].present?
17
+ end
18
+ end
19
+
20
+ # @return [void]
21
+ def before_render
22
+ singleton_stylesheet_link_tag(component_stylesheet_name) if asset_exists?(component_stylesheet_name)
23
+ end
24
+
25
+ # @return [String]
26
+ def component_stylesheet_name
27
+ "#{self.class.name.underscore}.css"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module Styles
5
+ module Controller
6
+ def singleton_stylesheets
7
+ @singleton_stylesheets ||= Set.new
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module Styles
5
+ module Helper
6
+ def singleton_stylesheet_link_tag(*args, **options)
7
+ controller.singleton_stylesheets << stylesheet_link_tag(*args, **options) and return
8
+ end
9
+
10
+ def singleton_stylesheet_link_tags
11
+ controller.singleton_stylesheets.select(&:html_safe?).join("\n").html_safe
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module Styles
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'view_component/styles/version'
4
+
5
+ module ViewComponent
6
+ module Styles
7
+ autoload :Helper, 'view_component/styles/helper'
8
+ autoload :Controller, 'view_component/styles/controller'
9
+ autoload :Component, 'view_component/styles/component'
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/view_component/styles/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'view_component-styles'
7
+ spec.version = ViewComponent::Styles::VERSION
8
+ spec.authors = ['Ryan Taylor']
9
+ spec.email = ['2320507+ryantaylor@users.noreply.github.com']
10
+
11
+ spec.summary = 'Stylesheet aggregation for view components'
12
+ spec.description = 'Automatically combine component styles in a view into a single stylesheet'
13
+ spec.homepage = 'https://github.com/thriver/view_component-styles'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'rails', '>= 5'
33
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: view_component-styles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Taylor
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ description: Automatically combine component styles in a view into a single stylesheet
28
+ email:
29
+ - 2320507+ryantaylor@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/view_component/styles.rb
45
+ - lib/view_component/styles/component.rb
46
+ - lib/view_component/styles/controller.rb
47
+ - lib/view_component/styles/helper.rb
48
+ - lib/view_component/styles/version.rb
49
+ - view_component-styles.gemspec
50
+ homepage: https://github.com/thriver/view_component-styles
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ allowed_push_host: https://rubygems.org
55
+ homepage_uri: https://github.com/thriver/view_component-styles
56
+ source_code_uri: https://github.com/thriver/view_component-styles
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.7.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.2.22
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Stylesheet aggregation for view components
76
+ test_files: []