base16-builder 0.0.1

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: 30ab8163bdb80ec8cbceafa173a5a8a79a7313e95399cadd0a96cc80c7ed42e5
4
+ data.tar.gz: 8de95c35ae157aa78fa248177fe56c353721b84bb4863047654db2d9562bbde8
5
+ SHA512:
6
+ metadata.gz: 89d6a516664a8c8ba92a3fa14f44c0249efa13002069c0b1ed5b4b60cb9cbdd9ede1a47e80421fd08eb7db702443d78bb01ba7c4a2a95a6a6afa8e8844422282
7
+ data.tar.gz: '038d75cbf5c3c74e25021db81f0d01c1d37003fc0cb479ece813b9124e1e352782efc2e6a966c7ebc4a2035419755247aeb63bb5ef53bd039411623cf659eb1c'
data/.standard.yml ADDED
@@ -0,0 +1,7 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
4
+
5
+ ignore:
6
+ - 'schemes/**/*'
7
+ - 'templates/**/*'
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in base16-builder.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "standard", "~> 1.3"
11
+
12
+ gem "git"
13
+ gem "mustache", "~> 1.0"
14
+ gem "slugify"
15
+ gem "chroma"
16
+ gem "thor"
17
+ gem "parallel"
18
+ gem "safe_yaml"
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ base16-builder (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.5)
10
+ public_suffix (>= 2.0.2, < 6.0)
11
+ ast (2.4.2)
12
+ chroma (0.2.0)
13
+ git (1.18.0)
14
+ addressable (~> 2.8)
15
+ rchardet (~> 1.8)
16
+ json (2.6.3)
17
+ language_server-protocol (3.17.0.3)
18
+ lint_roller (1.1.0)
19
+ mustache (1.1.1)
20
+ parallel (1.23.0)
21
+ parser (3.2.2.4)
22
+ ast (~> 2.4.1)
23
+ racc
24
+ public_suffix (5.0.4)
25
+ racc (1.7.3)
26
+ rainbow (3.1.1)
27
+ rake (13.1.0)
28
+ rchardet (1.8.0)
29
+ regexp_parser (2.8.2)
30
+ rexml (3.2.6)
31
+ rubocop (1.57.2)
32
+ json (~> 2.3)
33
+ language_server-protocol (>= 3.17.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.2.2.4)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.28.1, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 2.4.0, < 3.0)
42
+ rubocop-ast (1.30.0)
43
+ parser (>= 3.2.1.0)
44
+ rubocop-performance (1.19.1)
45
+ rubocop (>= 1.7.0, < 2.0)
46
+ rubocop-ast (>= 0.4.0)
47
+ ruby-progressbar (1.13.0)
48
+ safe_yaml (1.0.5)
49
+ slugify (1.0.7)
50
+ standard (1.32.0)
51
+ language_server-protocol (~> 3.17.0.2)
52
+ lint_roller (~> 1.0)
53
+ rubocop (~> 1.57.2)
54
+ standard-custom (~> 1.0.0)
55
+ standard-performance (~> 1.2)
56
+ standard-custom (1.0.2)
57
+ lint_roller (~> 1.0)
58
+ rubocop (~> 1.50)
59
+ standard-performance (1.2.1)
60
+ lint_roller (~> 1.1)
61
+ rubocop-performance (~> 1.19.1)
62
+ thor (1.3.0)
63
+ unicode-display_width (2.5.0)
64
+
65
+ PLATFORMS
66
+ x86_64-linux
67
+
68
+ DEPENDENCIES
69
+ base16-builder!
70
+ chroma
71
+ git
72
+ mustache (~> 1.0)
73
+ parallel
74
+ rake (~> 13.0)
75
+ safe_yaml
76
+ slugify
77
+ standard (~> 1.3)
78
+ thor
79
+
80
+ BUNDLED WITH
81
+ 2.3.26
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Omar
4
+ Copyright (c) 2022 [Tinted Theming](https://github.com/tinted-theming)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # base16-builder-ruby
2
+
3
+ This is a base16 builder written in Ruby as defined by the [base16 builder
4
+ guidelines](https://github.com/tinted-theming/home/blob/cc34890294402b9052b528e107f5b6b5ae15fdff/builder.md)
5
+ version 0.9.0
6
+
7
+ ## Requirements
8
+
9
+ * Ruby 2.3.0+ (You can use [rbenv](https://github.com/rbenv/rbenv) or
10
+ [rvm](https://rvm.io/) to acquire a specific Ruby version)
11
+ * [Bundler](http://bundler.io/)
12
+
13
+ ## Installation
14
+
15
+ If you have all the requirements listed above, `cd` to the directory where you
16
+ cloned this repository to then run `bundle install`. If everything succeeds you
17
+ should be able to use it as described below.
18
+
19
+ ## Usage
20
+
21
+ ```sh
22
+ ./builder update
23
+ ```
24
+ Clones or pulls all sources, schemes, and templates repositories.
25
+
26
+ ```sh
27
+ ./builder
28
+ ```
29
+
30
+ Builds all templates and saves them in `/out/<dir>` where `<dir>` is defined by
31
+ the template's configuration. If the necessary directories don't exist, it will
32
+ call `./builder update`
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "standard/rake"
5
+
6
+ task default: :standard
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/base16/builder/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "base16-builder"
7
+ spec.version = Base16::Builder::VERSION
8
+ spec.authors = ["Omar", "Tinted Theming"]
9
+ spec.email = ["omar@omar.engineer"]
10
+
11
+ spec.summary = "A ruby implementation of a Base16 Builder"
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = "https://github.com/tinted-theming/base16-builder-ruby"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+ end
data/builder ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ require "thor"
3
+ require "parallel"
4
+
5
+ Dir["src/*.rb"].sort.each { |file| require_relative file }
6
+
7
+ PROCESS_COUNT = 6
8
+
9
+ class Builder < Thor
10
+ package_name "base16-builder-ruby"
11
+
12
+ no_commands do
13
+ def required_dirs_exist?
14
+ Dir.exist?("sources") && Dir.exist?("schemes") &&
15
+ Dir.exist?("templates")
16
+ end
17
+ end
18
+ desc "update", "Re-acquires all sources, schemes, and templates"
19
+
20
+ def update
21
+ schemes_repo = Base16Repository.schemes_repo
22
+ templates_repo = Base16Repository.templates_repo
23
+
24
+ schemes_repo.update
25
+ templates_repo.update
26
+
27
+ schemes_list = YAML.load_file("sources/schemes/list.yaml")
28
+ templates_list = YAML.load_file("sources/templates/list.yaml")
29
+
30
+ Parallel.each(schemes_list, in_processes: PROCESS_COUNT) do |k, v|
31
+ # These repos now 404 on GitHub, maybe they were taken private?
32
+ next if v.include? "aramisgithub"
33
+ repo = Base16Repository.new(path: "schemes", name: k, url: v)
34
+ repo.update
35
+ end
36
+
37
+ Parallel.each(templates_list, in_processes: PROCESS_COUNT) do |k, v|
38
+ # textadept has moved their config file for some reason
39
+ next if v.include? "textadept"
40
+ repo = Base16Repository.new(path: "templates", name: k, url: v)
41
+ repo.update
42
+ end
43
+ end
44
+
45
+ desc "build", "Builds all templates for all schemes into ./outputs/"
46
+
47
+ def build
48
+ invoke :update unless required_dirs_exist?
49
+
50
+ schemes = Scheme.load_schemes
51
+ templates = Template.load_templates
52
+
53
+ Parallel.each(schemes, in_processes: PROCESS_COUNT) do |s|
54
+ templates.each do |t|
55
+ t.render(scheme: s)
56
+ end
57
+ end
58
+ end
59
+
60
+ default_task :build
61
+ end
62
+
63
+ Builder.start(ARGV)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Base16
4
+ module Builder
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "builder/version"
4
+
5
+ module Base16
6
+ module Builder
7
+ end
8
+ end
data/sources.yaml ADDED
@@ -0,0 +1,2 @@
1
+ schemes: https://github.com/chriskempson/base16-schemes-source.git
2
+ templates: https://github.com/chriskempson/base16-templates-source.git
@@ -0,0 +1,75 @@
1
+ require "git"
2
+ require "safe_yaml/load"
3
+
4
+ class Base16Repository
5
+ @@sources_filename = "sources.yaml"
6
+ @@sources_dir = "sources"
7
+
8
+ attr_accessor :repo_path
9
+
10
+ def self.repo_from_sources_yaml(key:)
11
+ yaml = SafeYAML.load(File.read(@@sources_filename))
12
+ url = yaml[key]
13
+
14
+ return nil unless url
15
+
16
+ Base16Repository.new(
17
+ path: @@sources_dir,
18
+ name: key,
19
+ url: url
20
+ )
21
+ end
22
+
23
+ def self.schemes_repo
24
+ repo_from_sources_yaml(key: "schemes")
25
+ end
26
+
27
+ def self.templates_repo
28
+ repo_from_sources_yaml(key: "templates")
29
+ end
30
+
31
+ def initialize(path:, name:, url:)
32
+ @path = path
33
+ @name = name
34
+ @url = url
35
+
36
+ @repo_path = "#{@path}/#{@name}"
37
+ end
38
+
39
+ def update
40
+ if exist?
41
+ puts "Pulling #{@repo_path}..."
42
+ repo = Git.open(@repo_path)
43
+ repo.pull
44
+ else
45
+ clone
46
+ end
47
+ end
48
+
49
+ def clone
50
+ puts "Cloning #{@repo_path}..."
51
+ Git.clone(@url, @name, path: @path, depth: 1)
52
+ end
53
+
54
+ def exist?
55
+ Dir.exist?(@repo_path)
56
+ end
57
+
58
+ def is_scheme_list_repo?
59
+ @repo_path == "sources/schemes"
60
+ end
61
+
62
+ def is_template_list_repo?
63
+ @repo_path == "sources/templates"
64
+ end
65
+
66
+ def scheme_repo_urls
67
+ return nil unless exist? && is_scheme_list_repo?
68
+ SafeYAML.load(File.read("#{@repo_path}/list.yaml"))
69
+ end
70
+
71
+ def template_repo_urls
72
+ return nil unless exist? && is_template_list_repo?
73
+ SafeYAML.load(File.read("#{@repo_path}/list.yaml"))
74
+ end
75
+ end
data/src/scheme.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "slugify"
2
+ require "safe_yaml/load"
3
+
4
+ class Scheme
5
+ attr_reader :name
6
+ attr_reader :slug
7
+ attr_reader :author
8
+ attr_reader :bases
9
+
10
+ def self.load_schemes
11
+ schemes = []
12
+ Dir["schemes/*/*.yaml"].each do |scheme_file|
13
+ schemes << Scheme.new(file_path: scheme_file)
14
+ end
15
+
16
+ schemes
17
+ end
18
+
19
+ def initialize(file_path:)
20
+ yaml = SafeYAML.load(File.read(file_path))
21
+ filename = File.basename(file_path, ".yaml")
22
+
23
+ @author = yaml["author"]
24
+ @name = yaml["scheme"]
25
+ @slug = filename.slugify
26
+ @bases = {}
27
+
28
+ bases = %w[00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F]
29
+
30
+ bases.each do |b|
31
+ key = "base#{b}"
32
+ @bases[key] = yaml[key]
33
+ end
34
+ end
35
+ end
data/src/template.rb ADDED
@@ -0,0 +1,69 @@
1
+ require "mustache"
2
+ require "chroma"
3
+ require "safe_yaml/load"
4
+
5
+ class Template
6
+ def self.load_templates
7
+ templates = []
8
+
9
+ Dir["templates/**/templates"].each do |template_dir|
10
+ config_file = File.join(template_dir, "config.yaml")
11
+ templates << Template.new(template_dir: template_dir, config_file: config_file)
12
+ end
13
+
14
+ templates
15
+ end
16
+
17
+ def initialize(template_dir:, config_file:)
18
+ @template_dir = template_dir
19
+ @config = SafeYAML.load(File.read(config_file))
20
+ end
21
+
22
+ def render(scheme:)
23
+ @config.each do |key, template_file_config|
24
+ template_data = build_template_data(scheme: scheme)
25
+
26
+ template_file = "#{@template_dir}/#{key}.mustache"
27
+ rendered_filename = "base16-#{scheme.slug}#{template_file_config["extension"]}"
28
+ rendered_dir = "out/#{template_file_config["output"]}"
29
+
30
+ rendered_template = Mustache.render(File.read(template_file), template_data)
31
+
32
+ FileUtils.mkdir_p(rendered_dir) unless Dir.exist?(rendered_dir)
33
+
34
+ puts "building #{rendered_dir}/#{rendered_filename}"
35
+ File.write("#{rendered_dir}/#{rendered_filename}", rendered_template)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def build_template_data(scheme:)
42
+ data = {
43
+ "scheme-name" => scheme.name,
44
+ "scheme-author" => scheme.author,
45
+ "scheme-slug" => scheme.slug
46
+ }
47
+
48
+ scheme.bases.each do |base_key, base_color|
49
+ data["#{base_key}-hex"] = base_color
50
+
51
+ data["#{base_key}-hex-r"] = base_color[0, 2]
52
+ data["#{base_key}-hex-g"] = base_color[2, 2]
53
+ data["#{base_key}-hex-b"] = base_color[4, 2]
54
+
55
+ # Turn hex color into an array of [r, g, b]
56
+ rgb = base_color.paint.to_rgb.scan(/\d+/)
57
+
58
+ data["#{base_key}-rgb-r"] = rgb[0]
59
+ data["#{base_key}-rgb-g"] = rgb[1]
60
+ data["#{base_key}-rgb-b"] = rgb[2]
61
+
62
+ data["#{base_key}-dec-r"] = rgb[0].to_i / 255.0
63
+ data["#{base_key}-dec-g"] = rgb[1].to_i / 255.0
64
+ data["#{base_key}-dec-b"] = rgb[2].to_i / 255.0
65
+ end
66
+
67
+ data
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: base16-builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Omar
8
+ - Tinted Theming
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-11-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - omar@omar.engineer
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".standard.yml"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - base16-builder.gemspec
28
+ - builder
29
+ - lib/base16/builder.rb
30
+ - lib/base16/builder/version.rb
31
+ - sources.yaml
32
+ - src/base16_repository.rb
33
+ - src/scheme.rb
34
+ - src/template.rb
35
+ homepage: https://github.com/tinted-theming/base16-builder-ruby
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/tinted-theming/base16-builder-ruby
40
+ source_code_uri: https://github.com/tinted-theming/base16-builder-ruby
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.6.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.4.21
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: A ruby implementation of a Base16 Builder
60
+ test_files: []