tailwind_theme-rails 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: af4a596650d11be93a96ed08a70b8155b5865c1ff40c3053b3b4a39ee6585fc3
4
+ data.tar.gz: 787ff82ef8f220ec9bdd71c880bf50ead8775e2e41727c0237d88244aea6a3be
5
+ SHA512:
6
+ metadata.gz: bdfa4e58b4079e6204b90a6476cb6e5b87e8b636781ef3efbaca6947eb742fb998be868d08bed4b76f9019d84bcb9f8d869cbf7ed4691bc34619d18759603602
7
+ data.tar.gz: cfc8b8ea25b3a6997b16e2423ff7ddf9eb88f223712dbd36543424098b6af585524251935e1560d21a19a0520dfd02018c736b8354dc8cbb93276baa6c725231
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright James Fawks
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # TailwindTheme::Rails
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "tailwind_theme-rails"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install tailwind_theme-rails
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ bin/rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ module TailwindTheme
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ source_root File.expand_path("../templates", __dir__)
9
+
10
+ desc "Creates a default TailwindTheme file."
11
+
12
+ class_option :erb
13
+
14
+ def copy_default_theme
15
+ @theme_name = "default"
16
+ template "theme.yml", "config/theme.yml#{".erb" if !!options[:erb]}"
17
+ end
18
+
19
+ def copy_alternative_theme
20
+ @theme_name = "alternative"
21
+ template "theme.yml", "config/themes/alternative.yml#{".erb" if !!options[:erb]}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ _theme: "<%= @theme_name %>"
2
+ component:
3
+ disabled?: "opacity-50"
4
+ variant:
5
+ solid: "bg-blue-500"
6
+ outline: "border border-blue-500"
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module TailwindTheme
6
+ # Adds the methods and helpers to the controller for setting and getting the TailwindTheme
7
+ module ControllerConcern
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ class_attribute :_theme # :nodoc:
12
+
13
+ # Add the helper method for the views
14
+ helper_method :theme
15
+ end
16
+
17
+ class_methods do
18
+ # Set the TailwindTheme for the controller
19
+ #e
20
+ # @param [String, Symbol, NilClass] name the name of the theme to use. Defaults to nil.
21
+ #
22
+ # When `name` is nil, :default, or "default", the default theme will be used.
23
+ #
24
+ # See the [Factory](#Factory) class for more details
25
+ def theme(name)
26
+ self._theme = name
27
+ end
28
+ end
29
+
30
+ # The specified TailwindTheme for the controller
31
+ def theme
32
+ theme_factory.theme self.class._theme
33
+ end
34
+
35
+ private
36
+
37
+ def theme_factory
38
+ Factory.new
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TailwindTheme
4
+ class Engine < ::Rails::Engine # :nodoc:
5
+
6
+
7
+ initializer "tailwind_theme.setup_controller_theme" do |app|
8
+ ActiveSupport.on_load(:action_controller) do
9
+ ActionController::Base.include TailwindTheme::ControllerConcern
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TailwindTheme
4
+ # Theme factory to load and cache a theme.
5
+ #
6
+ # @example
7
+ #
8
+ # TailwindTheme::Factory.new.theme
9
+ #
10
+ # @example
11
+ #
12
+ # TailwindTheme::Factory.new.theme :admin
13
+ #
14
+ class Factory
15
+ def initialize(config_dir = nil)
16
+ @config_dir = config_dir || ::Rails.root.join("config").to_s
17
+ @themes = {}
18
+ end
19
+
20
+ # Load and cache the theme.
21
+ #
22
+ # @param [String, Symbol] name the name of the theme to load. Nil will load the default theme.
23
+ #
24
+ # The default theme load order:
25
+ # 1) themes/default.yml(.erb)
26
+ # 2) theme.yml(.erb)
27
+ #
28
+ # @return [TailwindTheme::Theme, NilClass] returns the theme or nil if the theme cannot be found.
29
+ def theme(name = nil)
30
+ if name.nil? || name.to_s == "default"
31
+ default_theme
32
+ else
33
+ theme_by_name name
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def default_theme
40
+ return @themes[:default] if @themes[:default]
41
+
42
+ files = Dir[
43
+ File.expand_path("themes/default.{yml,yml.erb}"),
44
+ File.expand_path("theme.{yml,yml.erb}", @config_dir)
45
+ ]
46
+
47
+ load_theme :default, files
48
+ end
49
+
50
+ def theme_by_name(name)
51
+ return @themes[name.to_sym] if @themes[name.to_sym]
52
+
53
+ files = Dir[File.expand_path("themes/#{name}.{yml,yml.erb}", @config_dir)]
54
+ load_theme name, files
55
+ end
56
+
57
+ def load_theme(name, files)
58
+ return if files.empty?
59
+
60
+ theme = TailwindTheme.load_file files.first.to_s
61
+ theme.instance_eval <<-RUBY
62
+ def name
63
+ "#{name}"
64
+ end
65
+ RUBY
66
+
67
+ @themes[name.to_sym] = theme
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module TailwindTheme
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "tailwind_theme"
5
+ require "tailwind_theme/rails/version"
6
+ require "tailwind_theme/factory"
7
+ require "tailwind_theme/controller_concern"
8
+ require "tailwind_theme/engine"
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tailwind_theme-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Fawks
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tailwind_theme
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 6.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 6.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 6.0.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '8.0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 6.0.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '8.0'
61
+ description:
62
+ email:
63
+ - hello@jfawks.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - lib/generators/tailwind_theme/install/USAGE
71
+ - lib/generators/tailwind_theme/install/install_generator.rb
72
+ - lib/generators/tailwind_theme/templates/theme.yml
73
+ - lib/tailwind_theme-rails.rb
74
+ - lib/tailwind_theme/controller_concern.rb
75
+ - lib/tailwind_theme/engine.rb
76
+ - lib/tailwind_theme/factory.rb
77
+ - lib/tailwind_theme/rails/version.rb
78
+ homepage: https://github.com/jefawks3/tailwind_theme-rails
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ homepage_uri: https://github.com/jefawks3/tailwind_theme-rails
83
+ source_code_uri: https://github.com/jefawks3/tailwind_theme-rails
84
+ changelog_uri: https://github.com/jefawks3/tailwind_theme-rails/releases
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 2.7.0
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.5.3
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Rails helpers for TailwindTheme
104
+ test_files: []