sass-tumblr 0.1.0 → 0.2.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -4
  3. data/lib/sass_tumblr.rb +34 -16
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb54b0d8dd6e225ba0e605c85c31d57cdc95f14f
4
- data.tar.gz: 4542170588022e142cbff36676ea304bcc4533c8
3
+ metadata.gz: 948359a7892f1e7936ae432c5e5b63ee02f96b97
4
+ data.tar.gz: 77fbfac1adb8b075d71b014ddfdb236d4a8eeed1
5
5
  SHA512:
6
- metadata.gz: 3c90e15ae3a63bd4d41d9441f48f81ce33e08e65b9362c71dea7a69daac8425bd4f40b68ad5f599d4fcd9839c9019692653cd9d1c4a44deac0b4374228dd00ce
7
- data.tar.gz: 2d6d3e23e9c3725969e2255ab94c5e6c23bd3e328c603b421e1b627d31667728a70e1f489ea15adbf6877ad7fc6f1d77778499f820b9dfc69a51d85a09e04ded
6
+ metadata.gz: 5de741d2b137ac36729cdbbd1e03b69e537aaf11e2821082a38817729659b2dbfb7a348013328f5431acee671ec6d470e9c243dd0a1befb83d2a3c1461828dea
7
+ data.tar.gz: aff359448f023512c241e2d159f8f65f32d8c0b8ad5b7cb27fb56e6f035d8fdc659f37abea0b025a464e2023b2133143bbad270a1429b3258cd79a24ab36184c
data/README.md CHANGED
@@ -1,15 +1,43 @@
1
1
  sass-tumblr
2
2
  ===========
3
3
 
4
- Ignore [Tumblr template tags](https://www.tumblr.com/docs/en/custom_themes) like ``a { color: {color:Text}; }`` while parsing SCSS.
4
+ Ignore [Tumblr template tags](https://www.tumblr.com/docs/en/custom_themes) like ``a { color: {color:Text}; }`` while parsing SCSS with [Sass](http://sass-lang.com/) gem.
5
+ At this moment, old [indent base sass](http://sass-lang.com/documentation/file.INDENTED_SYNTAX.html) is not supported.
5
6
 
6
7
  Usage
7
8
  -----
8
9
 
9
- Add dependency to your Gemfile.
10
+ Use [Bundler](http://bundler.io/) and add a dependency to your `Gemfile`.
10
11
 
11
- gem "sass-tumblr"
12
+ $ gem "sass-tumblr"
12
13
 
13
14
  Then require ``sass_tumblr`` in appropriate way.
14
15
 
15
- require 'sass_tumblr'
16
+ require "sass_tumblr"
17
+
18
+
19
+ Example
20
+ -------
21
+
22
+ Parse SCSS with Tumblr template tags using `rib`.
23
+
24
+ $ bundle exec irb
25
+ irb> require "sass_tumblr"
26
+ irb> puts Sass::Engine.new("body {color: {color:Text}}", :syntax => :scss).render
27
+ body {
28
+ color: {color:Text}; }
29
+
30
+ Limitations
31
+ -----------
32
+
33
+ At this moment, all Tumblr tags in SCSS must be one of next format.
34
+ Basically it follows [Tumbler template document](https://www.tumblr.com/docs/en/custom_themes), but not all existing templates are following this rule.
35
+
36
+ {CapitalizedTagName}
37
+ {CustomCSS}
38
+ {color:Capitalized Key Name}
39
+ {font:Capitalized Key Name}
40
+ {text:Capitalized Key Name}
41
+ {image:Capitalized Key Name}
42
+
43
+ Also `{block:KeyName}` and `{/block:KeyName}` may not work.
@@ -4,29 +4,33 @@ module Sass
4
4
  module SCSS
5
5
  module RX
6
6
  # Pattern to match Tumblr tag.
7
- TUMBLR_VAR = /({[a-zA-Z0-9_]+(?::[a-zA-Z0-9_]+)?})/
7
+ TUMBLR_TAG = /({(?:[A-Z][a-zA-Z0-9\-]*|(color|font|select|text|image):[A-Z][a-zA-Z0-9\-_ ]*)})/
8
+ # Handle special `{CustomCSS}' tag as a comment,
9
+ # which can appear independently in CSS.
10
+ TUMBLR_CUSTOM_CSS_TAG = /{CustomCSS}/i
11
+ COMMENT = /#{COMMENT.source}|#{TUMBLR_CUSTOM_CSS_TAG}/
8
12
  end
9
13
 
10
14
  # See lib/sass/scss/static_parser.rb
11
15
  class StaticParser
12
- # Handle Tumblr variable tags in CSS selector
16
+ # Handle Tumblr tags in CSS selector
13
17
  # Used from CssParser directly, from StaticParser and Parser via RuleNode#try_to_parse_non_interpolated_rules.
14
18
  alias :qualified_name_without_tumblr :qualified_name
15
19
  def qualified_name(allow_star_name = false)
16
- if var = tok(TUMBLR_VAR)
17
- return nil, var
20
+ if tag = tok(TUMBLR_TAG)
21
+ return nil, tag
18
22
  else
19
23
  qualified_name_without_tumblr(allow_star_name)
20
24
  end
21
25
  end
22
26
 
23
- # Handle Tumblr variable tags in CSS key
27
+ # Handle Tumblr tags in CSS key
24
28
  # Used from CssParser and StaticParser
25
29
  # This is needed even we've patched in Parser class since it's also overridden in StaticParser.
26
30
  alias :interp_ident_without_tumblr :interp_ident
27
31
  def interp_ident(ident = IDENT)
28
- if var = tok(TUMBLR_VAR)
29
- [var]
32
+ if tag = tok(TUMBLR_TAG)
33
+ [tag]
30
34
  else
31
35
  interp_ident_without_tumblr(ident)
32
36
  end
@@ -35,29 +39,43 @@ module Sass
35
39
 
36
40
  # See lib/sass/scss/parser.rb
37
41
  class Parser
38
- # Handle Tumblr variable tags in CSS selector
42
+ # Handle Tumblr tags in CSS selector
39
43
  # Used from StaticParser and Parser.
40
44
  alias :almost_any_value_token_without_tumblr :almost_any_value_token
41
45
  def almost_any_value_token
42
- tok(TUMBLR_VAR) || almost_any_value_token_without_tumblr
46
+ tok(TUMBLR_TAG) || almost_any_value_token_without_tumblr
43
47
  end
44
48
 
45
- # Handle Tumblr variable tags in CSS key
49
+ # Handle Tumblr tags in CSS key
46
50
  # Used from StaticParser and Parser.
47
51
  alias :interp_ident_without_tumblr :interp_ident
48
52
  def interp_ident(ident = IDENT)
49
- if var = tok(TUMBLR_VAR)
50
- [var]
53
+ if tag = tok(TUMBLR_TAG)
54
+ [tag]
51
55
  else
52
56
  interp_ident_without_tumblr(ident)
53
57
  end
54
58
  end
55
59
 
56
- # Avoid to parse first "{" as a block in declaration for Tumblr variable tags in CSS value
60
+ # Handlt Tumblr custom css tag
61
+ # Treat the tag as comment and yet visible in compact style.
62
+ alias :process_comment_without_tumblr :process_comment
63
+ def process_comment(text, node)
64
+ case text
65
+ when TUMBLR_CUSTOM_CSS_TAG
66
+ comment = Sass::Tree::CommentNode.new([text], :loud)
67
+ comment.line = @line
68
+ node << comment
69
+ else
70
+ process_comment_without_tumblr(text, node)
71
+ end
72
+ end
73
+
74
+ # Avoid to parse first "{" as a block in declaration for Tumblr tags in CSS value
57
75
  # Used from all parsers.
58
76
  alias :value_without_tumblr! :value!
59
77
  def value!
60
- if var = tok?(TUMBLR_VAR)
78
+ if tok?(TUMBLR_TAG)
61
79
  sass_script(:parse)
62
80
  else
63
81
  value_without_tumblr!
@@ -69,12 +87,12 @@ module Sass
69
87
  # See lib/sass/script/lexer.rb
70
88
  module Script
71
89
  class Lexer
72
- # Handle Tumblr variable tags in CSS value
90
+ # Handle Tumblr tags in CSS value
73
91
  # Parse as ident token (like `middle', `top') in the parser.
74
92
  # Used from all parsers.
75
93
  alias :ident_without_tumblr_var :ident
76
94
  def ident
77
- if scan(TUMBLR_VAR)
95
+ if scan(TUMBLR_TAG)
78
96
  [:ident, @scanner[1]]
79
97
  else
80
98
  ident_without_tumblr_var
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-tumblr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshimasa Niwa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-17 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass