deadfire 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: 4b22d5497d512927d87bb9f0d4166b055281e8c684188b14b2c03b4052256fe0
4
+ data.tar.gz: c50413354b6e0504777d2111bf83a9f5e39a97f64f2fa14b292fd0277128f7be
5
+ SHA512:
6
+ metadata.gz: 922f9283b553c8c6f92d4e8de65362f1d75b29e028b5a18ab3444e2727cbc09295c176ec5b0359d879dd11a5f942e626ab9256d1cb2f4c0f39c9c13200aca06f
7
+ data.tar.gz: 1bb7bbae48bd1e170c036ad176d3f0dd22b5546b87b2ec874f1fa9d0820b1ba23c7cdd2096caac8673be42d32be4e14063ae44d79d7fc66134d670b41ccc56e7
@@ -0,0 +1,18 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ tests:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ ruby: [head, 3, 2.7]
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true
17
+ - name: Run tests
18
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+ gem "minitest"
7
+ gem "minitest-focus"
8
+ gem "minitest-reporters"
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deadfire (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.4)
11
+ minitest (5.14.3)
12
+ minitest-focus (1.3.1)
13
+ minitest (>= 4, < 6)
14
+ minitest-reporters (1.5.0)
15
+ ansi
16
+ builder
17
+ minitest (>= 5.0)
18
+ ruby-progressbar
19
+ rake (12.3.3)
20
+ ruby-progressbar (1.11.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ deadfire!
27
+ minitest
28
+ minitest-focus
29
+ minitest-reporters
30
+ rake
31
+
32
+ BUNDLED WITH
33
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Haroon Ahmed
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,159 @@
1
+ # Deadfire
2
+
3
+ A lightweight CSS preprocessor.
4
+
5
+ Use plain ol' CSS with a little bit of @import, @apply and nestings.
6
+
7
+ CSS is a staple technology when building web applications. With the introduction of LESS, SASS, SCSS it made CSS easier to maintain. However, most of these tools are no longer supported, maintained or have far too many features (wait... that's a bad thing?).
8
+
9
+ Deadfire sprinkles a few extra features which helps you write CSS, easier.
10
+
11
+ Deadfire can be used with or without a CSS framework.
12
+
13
+ ## Features
14
+
15
+ - [x] @import
16
+ - [x] [@apply](https://tabatkins.github.io/specs/css-apply-rule/)
17
+ - [x] [nesting](https://drafts.csswg.org/css-nesting-1)
18
+
19
+ ### @import
20
+
21
+ Imports allow you to easily include a file from the file system into your current css document.
22
+
23
+ ```CSS
24
+ /* shared/buttons.css */
25
+ .button {
26
+ color: red;
27
+ text-align: center;
28
+ }
29
+
30
+ /* application.css */
31
+ @import "shared/buttons.css";
32
+
33
+ .page-title {
34
+ font-size: 20px;
35
+ }
36
+ ```
37
+
38
+ Output;
39
+
40
+ ```CSS
41
+ /* application.css */
42
+ .button {
43
+ color: red;
44
+ text-align: center;
45
+ }
46
+
47
+ .page-title {
48
+ font-size: 20px;
49
+ }
50
+ ```
51
+
52
+ ### @apply
53
+
54
+ @apply inlines your classes into your custom css.
55
+
56
+ The CSS apply rule was [proposed to be included into CSS](https://tabatkins.github.io/specs/css-apply-rule/) however it was abandoned. Mixins simplify applying existing css to a new class.
57
+
58
+ All mixins must be declared on the `:root` element or preloaded via the `Deadfire.mixins` method. Using a mixin before it's declared will raise an `EarlyApplyException`. Ideally the `:root` element should appear near the top of the document.
59
+
60
+ Let's see an example of how to declare mixins and use the @apply directive.
61
+
62
+ ```CSS
63
+ :root {
64
+ --font-bold: {
65
+ font-weight: bold;
66
+ }
67
+
68
+ --btn: {
69
+ padding-bottom: 10px;
70
+ text-align: center;
71
+ }
72
+ }
73
+ ```
74
+
75
+ How can we use mixins? Using @apply...
76
+
77
+ ```CSS
78
+ .btn-blue {
79
+ @apply --btn --font-bold;
80
+ }
81
+
82
+ .homepage-hero {
83
+ @apply --font-bold;
84
+ }
85
+ ```
86
+
87
+ ### nesting
88
+
89
+ Nesting adds the ability to nest one style rule inside another.
90
+
91
+ NOTE: This feature is still a work in progress.
92
+
93
+ ```CSS
94
+ /* & can be used on its own */
95
+ .btn {
96
+ color: blue;
97
+ & > .homepage { color: red; }
98
+ }
99
+ ```
100
+
101
+ This is expanded to:
102
+
103
+ ```CSS
104
+ .btn { color: blue; }
105
+ .btn > .homepage { color: red; }
106
+ ```
107
+
108
+ ## Installation
109
+
110
+ Add this line to your application's Gemfile:
111
+
112
+ ```ruby
113
+ gem 'deadfire'
114
+ ```
115
+
116
+ And then execute:
117
+
118
+ `> bundle install`
119
+
120
+ Or install it yourself as:
121
+
122
+ `> gem install deadfire`
123
+
124
+ ## Deadfire + Ruby on Rails
125
+
126
+ After adding Deadfire gem to your rails application, open the file `config/initializers/assets.rb` to setup your Sprocket and the asset pipeline to use the new preprocessor.
127
+
128
+ ```ruby
129
+ # config/initializers/assets.rb
130
+ class DeadfireProcessor
131
+ def call(input)
132
+ return { data: Deadfire.parse(input[:data]) }
133
+ end
134
+ end
135
+
136
+ Deadfire.configuration.root_path = Rails.root.join('app', 'assets', 'stylesheets')
137
+ Sprockets.register_preprocessor('text/css', DeadfireProcessor.new)
138
+ ```
139
+
140
+ Your css file should now be run through Deadfire.
141
+ ## Development
142
+
143
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
144
+
145
+ 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).
146
+
147
+ To run the tests, run `bin/test`.
148
+ ## Contributing
149
+
150
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hahmed/deadfire. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hahmed/deadfire/blob/master/CODE_OF_CONDUCT.md).
151
+
152
+
153
+ ## License
154
+
155
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
156
+
157
+ ## Code of Conduct
158
+
159
+ Everyone interacting in the Deadfire project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hahmed/deadfire/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,89 @@
1
+ require "bundler/inline"
2
+
3
+ gemfile(true) do
4
+ source "https://rubygems.org"
5
+
6
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
7
+
8
+ gem "sassc"
9
+ gem "deadfire", github: "hahmed/deadfire", branch: "main"
10
+ gem "syntax_tree-css"
11
+
12
+ gem "benchmark-ips"
13
+ end
14
+
15
+ css = <<~CSS
16
+
17
+ body {
18
+ font-family: helvetica, arial, sans-serif;
19
+ font-size: calc(1.3em + 0.5vw);
20
+ line-height: 1;
21
+ margin: 0;
22
+ padding: 0;
23
+ color: #1d2d35;
24
+ background-color:#ffefef;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 40px;
29
+ }
30
+
31
+ a {
32
+ font-size: 1em;
33
+ vertical-align: baseline;
34
+ background: transparent;
35
+ margin: 0;
36
+ padding: 0;
37
+ color: inherit;
38
+ transition: all 0.2s ease;
39
+ transition-property: text-decoration-color, text-decoration-thickness, text-decoration-width;
40
+ text-decoration-thickness: 0.1em;
41
+ text-decoration-width: 0.1rem
42
+ }
43
+
44
+ .button--block {
45
+ min-width:100% !important
46
+ }
47
+
48
+ code {
49
+ font-family: Roboto Mono;
50
+ font-size: 12px;
51
+ color: gray;
52
+ }
53
+
54
+ .banner {
55
+ border: 1px solid #ccc;
56
+ }
57
+ CSS
58
+
59
+ def dartsass
60
+ system "sass benchmarks/input.scss output.css", exception: true
61
+ end
62
+
63
+ Benchmark.ips do |x|
64
+ x.config(:time => 5, :warmup => 2)
65
+
66
+ x.report("dartsass") { dartsass }
67
+ x.report("deadfire") { Deadfire.parse(css) }
68
+ x.report("sassc") { SassC::Engine.new(css).render }
69
+ x.report("sytanx_tree") { SyntaxTree::CSS.parse(css) }
70
+ x.compare!
71
+ end
72
+
73
+ # FYI
74
+ # Warming up --------------------------------------
75
+ # dartsass 1.000 i/100ms
76
+ # deadfire 1.088k i/100ms
77
+ # sassc 27.000 i/100ms
78
+ # sytanx_tree 19.000 i/100ms
79
+ # Calculating -------------------------------------
80
+ # dartsass 6.605 (± 0.0%) i/s - 33.000 in 5.005992s
81
+ # deadfire 11.507k (± 3.6%) i/s - 57.664k in 5.017772s
82
+ # sassc 308.909 (± 6.2%) i/s - 1.539k in 5.002165s
83
+ # sytanx_tree 210.732 (± 9.0%) i/s - 1.045k in 5.005951s
84
+
85
+ # Comparison:
86
+ # deadfire: 11507.3 i/s
87
+ # sassc: 308.9 i/s - 37.25x (± 0.00) slower
88
+ # sytanx_tree: 210.7 i/s - 54.61x (± 0.00) slower
89
+ # dartsass: 6.6 i/s - 1742.19x (± 0.00) slower
@@ -0,0 +1,40 @@
1
+ body {
2
+ font-family: helvetica, arial, sans-serif;
3
+ font-size: calc(1.3em + 0.5vw);
4
+ line-height: 1;
5
+ margin: 0;
6
+ padding: 0;
7
+ color: #1d2d35;
8
+ background-color:#ffefef;
9
+ }
10
+
11
+ h1 {
12
+ font-size: 40px;
13
+ }
14
+
15
+ a {
16
+ font-size: 1em;
17
+ vertical-align: baseline;
18
+ background: transparent;
19
+ margin: 0;
20
+ padding: 0;
21
+ color: inherit;
22
+ transition: all 0.2s ease;
23
+ transition-property: text-decoration-color, text-decoration-thickness, text-decoration-width;
24
+ text-decoration-thickness: 0.1em;
25
+ text-decoration-width: 0.1rem
26
+ }
27
+
28
+ .button--block {
29
+ min-width:100% !important
30
+ }
31
+
32
+ code {
33
+ font-family: Roboto Mono;
34
+ font-size: 12px;
35
+ color: gray;
36
+ }
37
+
38
+ .banner {
39
+ border: 1px solid #ccc;
40
+ }
@@ -0,0 +1,42 @@
1
+ body {
2
+ font-family: helvetica, arial, sans-serif;
3
+ font-size: calc(1.3em + 0.5vw);
4
+ line-height: 1;
5
+ margin: 0;
6
+ padding: 0;
7
+ color: #1d2d35;
8
+ background-color: #ffefef;
9
+ }
10
+
11
+ h1 {
12
+ font-size: 40px;
13
+ }
14
+
15
+ a {
16
+ font-size: 1em;
17
+ vertical-align: baseline;
18
+ background: transparent;
19
+ margin: 0;
20
+ padding: 0;
21
+ color: inherit;
22
+ transition: all 0.2s ease;
23
+ transition-property: text-decoration-color, text-decoration-thickness, text-decoration-width;
24
+ text-decoration-thickness: 0.1em;
25
+ text-decoration-width: 0.1rem;
26
+ }
27
+
28
+ .button--block {
29
+ min-width: 100% !important;
30
+ }
31
+
32
+ code {
33
+ font-family: Roboto Mono;
34
+ font-size: 12px;
35
+ color: gray;
36
+ }
37
+
38
+ .banner {
39
+ border: 1px solid #ccc;
40
+ }
41
+
42
+ /*# sourceMappingURL=output.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sourceRoot":"","sources":["input.scss"],"names":[],"mappings":"AAAA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;;;AAGF;EACE","file":"output.css"}
@@ -0,0 +1,25 @@
1
+ require "bundler/inline"
2
+
3
+ gemfile(true) do
4
+ source "https://rubygems.org"
5
+
6
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
7
+
8
+ gem "sassc"
9
+ gem "deadfire", github: "hahmed/deadfire", branch: "main"
10
+ gem 'heap-profiler'
11
+ end
12
+
13
+ css = <<~OUTPUT
14
+ h1 {
15
+ font-size: 40px; }
16
+ h1 code {
17
+ font-face: Roboto Mono; }
18
+ OUTPUT
19
+
20
+ require 'heap-profiler'
21
+
22
+ HeapProfiler.report("benchmarks") do
23
+ Deadfire.parse(css)
24
+ # SassC::Engine.new(css).render
25
+ end