typi_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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2bb92bfa935d034c9593a1897ffde4ef2b108d7
4
+ data.tar.gz: 59792b8353472831010756f3783eedbc8c88fd25
5
+ SHA512:
6
+ metadata.gz: 71241af6eac7067436c56b9c10a277448ad0789ab7a0cebbf3f84525a643b96512c8ec2a6094cdad2de74dad2fab5d4a4cc03b18d436929cd87fbf6b5e7602bb
7
+ data.tar.gz: 1196f96dcd39903409e21a62b4e717b55015427481bb8751bb3955af0325e056b3512d47a567660216ccf476e3ab91568279ea0f900268a854ba33ffde93cfdc
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Pete Cass
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.
@@ -0,0 +1,40 @@
1
+ # TypiRails
2
+
3
+ ![Codeship](https://codeship.com/projects/000e2420-c497-0134-7204-7e1cf7b64920/status?branch=master)
4
+
5
+ Typi Rails is a Gemified wrapper for [Typi](https://github.com/zellwk/typi) (A Sass Mixin) for use in you Rails project
6
+
7
+ ## Usage
8
+ For detailed usage please refer to [https://github.com/zellwk/typi](https://github.com/zellwk/typi)
9
+
10
+ ## Installation
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ # ./Gemfile
15
+ # ...
16
+ gem 'typi_rails'
17
+ ```
18
+
19
+ And then execute:
20
+ ```bash
21
+ $ bundle
22
+ ```
23
+
24
+ You can then incorporate Typi into the asset pipeline.
25
+
26
+ Import Typi styles in `app/assets/stylesheets/application.scss`
27
+
28
+ Make sure the file has the `.scss` extension (or `.sass` for the indentation based Sass syntax). If you have just generated a new Rails app it will most likely have a `.css` extension. If this file exists, it will be served instead of Sass, so rename it and delete all the require statements and use the `@import` directive native to sass.
29
+
30
+ ```bash
31
+ $ mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss
32
+ ```
33
+
34
+ ```scss
35
+ // app/assets/stylesheets/application.scss
36
+ @import 'typi';
37
+ ```
38
+
39
+ ## License
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,11 @@
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
+ desc 'Updates and copies files from bower'
8
+ task :update do
9
+ require './tasks/update'
10
+ Update.new.extract
11
+ end
@@ -0,0 +1,8 @@
1
+ $breakpoints: () !default;
2
+ $typi: (null: (16px, 1.5)) !default;
3
+ $typi-ms: false !default;
4
+ $typi-breakpoint: null !default;
5
+
6
+ @import 'ty/mixins';
7
+ @import 'ty/functions';
8
+ @import 'typi/typi';
@@ -0,0 +1,234 @@
1
+ // _ty-font-size
2
+ // =============
3
+ // Calls _ty-calc-font-size or _ty-base-size
4
+ @function _ty-font-size(
5
+ $font-size,
6
+ $breakpoint,
7
+ $typi,
8
+ $rem,
9
+ $base: false,
10
+ $typi-map: false
11
+ ) {
12
+ @if $base == true {
13
+ @return _ty-base-size($font-size);
14
+ } @else {
15
+ @return _ty-calc-font-size($font-size, $breakpoint, $typi, $rem, $typi-map);
16
+ }
17
+ }
18
+
19
+ // _ty-calc-font-size
20
+ // =======
21
+ // returns correct rem value depending on
22
+ // breakpoint
23
+ @function _ty-calc-font-size(
24
+ $font-size,
25
+ $breakpoint,
26
+ $typi,
27
+ $rem,
28
+ $typi-map: false
29
+ ) {
30
+ @if unitless($font-size) {
31
+ @if function-exists(ms) {
32
+ $typi-ms: map-get($typi-map, ms);
33
+ @if $rem {
34
+ @return _ty-strip-unit(_ty-ms($font-size, $breakpoint, $typi-ms, $typi-map)) * 1rem;
35
+ } @else {
36
+ @return _ty-ms($font-size, $breakpoint, $typi-ms, $typi-map);
37
+ }
38
+ } @else {
39
+ @error "Modular Scale Library required";
40
+ }
41
+ }
42
+
43
+ // Convert px and em into rem
44
+ @else if $rem {
45
+ @if unit($font-size) == 'em' {
46
+ @return _ty-strip-unit($font-size) * 1rem;
47
+ }
48
+
49
+ @else if unit($font-size) == 'px' {
50
+ $basemap: map-get($typi, $breakpoint);
51
+ $basefont: if(type-of($basemap) == 'list', nth($basemap, 1), $basemap);
52
+
53
+ @if $basefont == null {
54
+ $basefont: nth(map-get($typi, null), 1);
55
+ }
56
+
57
+ @return $font-size / $basefont * 1rem;
58
+ }
59
+
60
+ @else {
61
+ @return $font-size;
62
+ }
63
+ }
64
+
65
+ // Converts rem and px into em
66
+ @else {
67
+ @if unit($font-size) == 'rem' {
68
+ @return _ty-strip-unit($font-size) * 1em;
69
+ }
70
+
71
+ @else if unit($font-size) == 'px' {
72
+ $basemap: map-get($typi, $breakpoint);
73
+ $basefont: if(type-of($basemap) == 'list', nth($basemap, 1), $basemap);
74
+
75
+ @if $basefont == null {
76
+ $basefont: nth(map-get($typi, null), 1);
77
+ }
78
+
79
+ @return _ty-em($font-size, $basefont);
80
+ }
81
+
82
+ @else {
83
+ @return $font-size;
84
+ }
85
+ }
86
+ }
87
+
88
+ // _ty-base-size
89
+ // =============
90
+ // Converts Typi sizes into percentages
91
+ @function _ty-base-size(
92
+ $font-size
93
+ ) {
94
+ @if unit($font-size) == 'px' {
95
+ @return $font-size / 16px * 100%;
96
+ }
97
+
98
+ @else {
99
+ @error 'Typi font sizes must be written in pixels';
100
+ }
101
+ }
102
+
103
+
104
+ // _ty-strip-unit
105
+ // ==============
106
+ @function _ty-strip-unit($num) {
107
+ @return $num / ($num * 0 + 1);
108
+ }
109
+
110
+ // _ty-em
111
+ // ========
112
+ @function _ty-em($font-size, $ref-size: false) {
113
+ @if ($ref-size) {
114
+ @return $font-size / $ref-size * 1em;
115
+ }
116
+ }
117
+
118
+ // _ty-rem
119
+ // =========
120
+ @function _ty-rem($font-size) {
121
+ @if unit($font-size) == 'px' {
122
+ @return strip-unit($font-size) / 16 * 1rem;
123
+ }
124
+ @else if unit($font-size) == 'em' {
125
+ @return strip-unit($font-size) * 1rem;
126
+ }
127
+ }
128
+
129
+ // _ty-ms
130
+ // ======
131
+ @function _ty-ms(
132
+ $multiplier,
133
+ $breakpoint: null,
134
+ $typi-ms: $typi-ms,
135
+ $typi-map: false
136
+ ) {
137
+ $ms-setting: null;
138
+ @if map-has-key($typi-ms, $breakpoint) {
139
+ $ms-setting: map-get($typi-ms, $breakpoint);
140
+ } @else {
141
+ $last-valid-ms: map-get($typi-map, last-valid-ms);
142
+ $ms-setting: map-get($typi-ms, $last-valid-ms);
143
+ }
144
+
145
+ $ty-ms-base: null;
146
+ $ty-ms-ratio: null;
147
+
148
+ @for $i from 1 to length($ms-setting) + 1 {
149
+ $val: nth($ms-setting, $i);
150
+
151
+
152
+ // For combinations of multiple bases + multiple ratios
153
+ @if type-of($val) == 'list' {
154
+ @if not unitless(nth($val, 1)) {
155
+ $ty-ms-base: $val;
156
+ } @else {
157
+ $ty-ms-ratio: $val;
158
+ }
159
+ }
160
+ // For combinations of 1 base + multiple ratios
161
+ @else {
162
+ @if unitless($val) {
163
+ @if $ty-ms-ratio == null {
164
+ $ty-ms-ratio: $val;
165
+ } @else if type-of($ty-ms-ratio) == "number" {
166
+ $ty-ms-ratio: $ty-ms-ratio $val;
167
+ } @else if type-of($ty-ms-ratio) == "list" {
168
+ $ty-ms-ratio: append($ty-ms-ratio, $val);
169
+ }
170
+ }
171
+
172
+ @else {
173
+ @if $ty-ms-base == null {
174
+ $ty-ms-base: $val;
175
+ } @else if type-of($ty-ms-base) == 'number' {
176
+ $ty-ms-base: ($ty-ms-base $val)
177
+ } @else if type-of($ty-ms-base) == 'list' {
178
+ $ty-ms-base: append($ty-ms-base, $val);
179
+ }
180
+ }
181
+ }
182
+ }
183
+
184
+ @if $ty-ms-base == null {
185
+ $ty-ms-base: 1em;
186
+ }
187
+
188
+ @return ms($multiplier, $ty-ms-base, $ty-ms-ratio);
189
+ }
190
+
191
+ // _ty-get-breakpoints
192
+ // ===================
193
+ @function _ty-get-breakpoints($breakpoints, $typi-ms, $target) {
194
+ $_return: null;
195
+
196
+ @each $breakpoint, $val in $breakpoints {
197
+ @if type-of($typi-ms) == 'map' and map-has-key($typi-ms, $breakpoint) {
198
+ @if not index($_return, $breakpoint) {
199
+ $_return: append($_return, $breakpoint);
200
+ }
201
+ }
202
+
203
+ @if map-has-key($target, $breakpoint) {
204
+ @if not index($_return, $breakpoint) {
205
+ $_return: append($_return, $breakpoint);
206
+ }
207
+ }
208
+ }
209
+ @return $_return;
210
+ }
211
+
212
+ // _ty-get-base-font
213
+ @function _ty-get-base-font($typi) {
214
+ $base-map: map-get($typi, null);
215
+ @return nth($base-map, 1);
216
+ }
217
+
218
+ // _ty-get-base-line-height
219
+ @function _ty-get-base-line-height($typi) {
220
+ $base-map: map-get($typi, null);
221
+ $base-line-height: null;
222
+
223
+ @if length($base-map) > 1 {
224
+ $base-line-height: nth($base-map, 2);
225
+ } @else {
226
+ @error "$typi map should contain a second argument (line-height) in the `null` key";
227
+ }
228
+
229
+ @if not unit($base-line-height) == "" {
230
+ @error "line-height multiple on the `null` key should be unitless";
231
+ }
232
+
233
+ @return $base-line-height;
234
+ }
@@ -0,0 +1,72 @@
1
+
2
+ // _ty-breakpoint
3
+ // ==============
4
+ // Allows use of breakpoint-sass and mappy-bp.
5
+ // Falls back to default method otherwise.
6
+ @mixin _ty-breakpoint(
7
+ $typi-map
8
+ ) {
9
+ $breakpoint: map-get($typi-map, breakpoint);
10
+ $breakpoints: map-get($typi-map, breakpoints);
11
+ $bp-val: map-get($breakpoints, $breakpoint);
12
+
13
+ @if $typi-breakpoint == breakpoint {
14
+ @if mixin-exists(breakpoint) {
15
+ @include breakpoint-set('to ems', true);
16
+ @include breakpoint(map-get($breakpoints, $breakpoint)) {
17
+ @include _ty-write-props($typi-map);
18
+ }
19
+ } @else {
20
+ @error 'Breakpoint-sass Library not found'
21
+ }
22
+ }
23
+
24
+ @else if $typi-breakpoint == mappy-breakpoint or $typi-breakpoint == mappy-breakpoints {
25
+ @if mixin-exists(mappy-bp) {
26
+ @include mappy-bp(map-get($breakpoints, $breakpoint)) {
27
+ @include _ty-write-props($typi-map);
28
+ }
29
+ } @else {
30
+ @error 'Mappy Breakpoints Library not found'
31
+ }
32
+ }
33
+
34
+ @else {
35
+ @media all and (min-width: #{map-get($breakpoints, $breakpoint)}) {
36
+ @include _ty-write-props($typi-map);
37
+ }
38
+ }
39
+ }
40
+
41
+ // _ty-write-props
42
+ // ===============
43
+ // Writes font-size (and line height) properties
44
+ @mixin _ty-write-props (
45
+ $typi-map
46
+ ) {
47
+ $target: map-get($typi-map, target);
48
+ $breakpoint: map-get($typi-map, breakpoint);
49
+ $typi: map-get($typi-map, typi);
50
+ $base: map-get($typi-map, base);
51
+ $rem: map-get($typi-map, rem);
52
+
53
+ $bp-val: map-get($target, $breakpoint);
54
+ $font-size: null;
55
+ $line-height: null;
56
+
57
+ @if type-of($bp-val) == 'null' {
58
+ $last-valid-breakpoint: map-get($typi-map, last-valid-breakpoint);
59
+ $bp-val: map-get($target, $last-valid-breakpoint);
60
+ }
61
+
62
+ @if type-of($bp-val) == "list" and length($bp-val) > 1 {
63
+ $font-size: nth($bp-val, 1);
64
+ $line-height: nth($bp-val, 2);
65
+ font-size: _ty-font-size($font-size, $breakpoint, $typi, $rem, $base, $typi-map);
66
+ line-height: $line-height;
67
+ }
68
+ @else {
69
+ $font-size: $bp-val;
70
+ font-size: _ty-font-size($font-size, $breakpoint, $typi, $rem, $base, $typi-map);
71
+ }
72
+ }
@@ -0,0 +1,111 @@
1
+ @mixin typi(
2
+ $target-map,
3
+ $breakpoints: $breakpoints,
4
+ $typi: $typi,
5
+ $typi-ms: $typi-ms,
6
+ $base: false,
7
+ $rem: true
8
+ ) {
9
+ $typi-map: (
10
+ target: $target-map,
11
+ breakpoints: $breakpoints,
12
+ typi: $typi,
13
+ base: $base,
14
+ rem: $rem,
15
+ ms: $typi-ms
16
+ );
17
+
18
+ $breakpoints-to-output: _ty-get-breakpoints($breakpoints, $typi-ms, $target-map);
19
+ @each $breakpoint in $breakpoints-to-output {
20
+ $target: $target-map;
21
+ $typi-map: map-merge($typi-map, (breakpoint: $breakpoint));
22
+
23
+ @if $breakpoint == null {
24
+ @include _ty-write-props($typi-map);
25
+ }
26
+
27
+ @else {
28
+ @if map-has-key($breakpoints, $breakpoint) {
29
+ @include _ty-breakpoint($typi-map);
30
+ } @else {
31
+ @warn "Missing #{$breakpoint} in $breakpoints map";
32
+ }
33
+ }
34
+
35
+ // Add previous valid breakpoint
36
+ @if map-has-key($target, $breakpoint) {
37
+ $typi-map: map-merge($typi-map, (last-valid-breakpoint: $breakpoint))
38
+ }
39
+
40
+ // Add previous valid ms
41
+ @if type-of($typi-ms) == 'map' and map-has-key($typi-ms, $breakpoint) {
42
+ $typi-map: map-merge($typi-map, (last-valid-ms: $breakpoint))
43
+ }
44
+ }
45
+ }
46
+
47
+ @mixin typi-base(
48
+ $typi: $typi,
49
+ $breakpoints: $breakpoints,
50
+ $typi-ms: $typi-ms,
51
+ $base: true,
52
+ $rem: true
53
+ ) {
54
+ @include typi(
55
+ $typi,
56
+ $breakpoints,
57
+ $typi: $typi,
58
+ $typi-ms: $typi-ms,
59
+ $base: $base,
60
+ $rem: $rem
61
+ );
62
+ }
63
+
64
+ // Vertical rhythm function. Possible to output both EM and REM.
65
+ // Requires line height to be set on $typi map for 'null' breakpoint
66
+ @function vr($vr, $current-font: null, $typi: $typi) {
67
+ $base-font: _ty-get-base-font($typi);
68
+ $base-line-height: _ty-get-base-line-height($typi);
69
+ $rhythm-context: $vr * $base-line-height;
70
+
71
+ // Converts into EM if $current-font is provided
72
+ @if $current-font {
73
+ @if unit($current-font) == "px" {
74
+ $rhythm-context: $rhythm-context * $base-font;
75
+
76
+ @return $rhythm-context / $current-font * 1em;
77
+ }
78
+
79
+ @if unit($current-font) == "em" {
80
+ @return $rhythm-context / _ty-strip-unit($current-font) * 1em;
81
+ }
82
+
83
+ @else {
84
+ @error "Font sizes should either be px or em if $current-font is provided";
85
+ }
86
+ }
87
+
88
+ @else {
89
+ @if unit($base-line-height) == 'px' {
90
+ @return $vr * $base-line-height / $base-font-size * 1rem;
91
+ } @else {
92
+ @return $vr * $base-line-height * 1rem;
93
+ }
94
+ }
95
+ }
96
+
97
+ // Responsive Vertical Rhythm
98
+ @mixin rvr($props, $vr, $typi: $typi) {
99
+ $base-font: _ty-get-base-font($typi);
100
+ $base-line-height: _ty-get-base-line-height($typi);
101
+ $unit: unit($base-line-height);
102
+
103
+ @each $prop in $props {
104
+ @if $unit == 'px' {
105
+ #{$prop}: $base-line-height / $base-font * 1rem * $vr;
106
+ } @else {
107
+ #{$prop}: $base-line-height * 1rem * $vr;
108
+ }
109
+ #{$prop}: calc(var(--baseline) * #{1rem * $vr});
110
+ }
111
+ }
@@ -0,0 +1,5 @@
1
+ require "typi_rails/engine"
2
+
3
+ module TypiRails
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,5 @@
1
+ module TypiRails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace TypiRails
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module TypiRails
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typi_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pete Cass
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-24 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.0.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sass
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '3.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '3.2'
61
+ - !ruby/object:Gem::Dependency
62
+ name: sass-rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '3.2'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '3.2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Gemified version of Typi (https://github.com/zellwk/typi)
90
+ email:
91
+ - pete@petecss.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - MIT-LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - app/assets/stylesheets/_typi.scss
100
+ - app/assets/stylesheets/ty/_functions.scss
101
+ - app/assets/stylesheets/ty/_mixins.scss
102
+ - app/assets/stylesheets/typi/_typi.scss
103
+ - lib/typi_rails.rb
104
+ - lib/typi_rails/engine.rb
105
+ - lib/typi_rails/version.rb
106
+ homepage: https://github.com/Petecass/typi_rails
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Gemified version of Typi
130
+ test_files: []