livingstyleguide 2.0.0.alpha.4 → 2.0.0.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/livingstyleguide/document.rb +55 -34
- data/lib/livingstyleguide/filters.rb +2 -0
- data/lib/livingstyleguide/filters/add_wrapper_class.rb +2 -2
- data/lib/livingstyleguide/filters/coffee_script.rb +1 -1
- data/lib/livingstyleguide/filters/colors.rb +2 -2
- data/lib/livingstyleguide/filters/css.rb +6 -5
- data/lib/livingstyleguide/filters/data.rb +1 -1
- data/lib/livingstyleguide/filters/font_example.rb +2 -2
- data/lib/livingstyleguide/filters/full_width.rb +1 -1
- data/lib/livingstyleguide/filters/haml.rb +1 -1
- data/lib/livingstyleguide/filters/html_head.rb +2 -2
- data/lib/livingstyleguide/filters/import.rb +2 -1
- data/lib/livingstyleguide/filters/javascript.rb +1 -1
- data/lib/livingstyleguide/filters/markdown.rb +1 -1
- data/lib/livingstyleguide/filters/options.rb +3 -6
- data/lib/livingstyleguide/filters/require.rb +2 -2
- data/lib/livingstyleguide/filters/style.rb +7 -0
- data/lib/livingstyleguide/filters/type.rb +4 -0
- data/lib/livingstyleguide/templates/code.html.erb +3 -0
- data/lib/livingstyleguide/version.rb +1 -1
- data/stylesheets/livingstyleguide/_code.scss +2 -0
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f48cd7f49da48fb013eb94ef814c352b0b36d8
|
4
|
+
data.tar.gz: 708b10793c5522b1ce06c4b44b9b88130b410d09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4db4eee6c6208f7887ebc193b8e878dbd73f0a464206e0ebd3e31fdab7a176073217f06f293035534442c9b9039fe8c19cde309cf30c801ad8a75d46cdc245a3
|
7
|
+
data.tar.gz: 168434570778b35daa37373c6827e2d1a86166c2da1123d72d0608586a6eeb0d2b52b27f26541d5663a0f142a1638255241a285f086904adf34c5f2fc25fa41b
|
@@ -29,7 +29,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def prepare
|
32
|
-
@type = :
|
32
|
+
@type = :lsg
|
33
33
|
@filters = LivingStyleGuide::Filters.new(self)
|
34
34
|
@template = options.has_key?(:livingstyleguide) ? :default : :layout
|
35
35
|
@classes = []
|
@@ -63,28 +63,15 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def erb
|
66
|
-
@erb ||= parse_filters do |name, arguments|
|
67
|
-
arguments
|
68
|
-
%Q("#{argument.gsub('"', '\\"').gsub("\n", '\\n')}")
|
69
|
-
end
|
70
|
-
"<%= #{name}(#{arguments.join(', ')}) %>"
|
66
|
+
@erb ||= parse_filters do |name, arguments, options, block|
|
67
|
+
"<%= #{name}(#{arguments.inspect}, #{options.inspect}, #{block.inspect}) %>\n"
|
71
68
|
end
|
72
69
|
end
|
73
70
|
|
74
71
|
def evaluate(scope, locals, &block)
|
75
72
|
@scope = scope
|
76
73
|
result = ERB.new(erb).result(@filters.get_binding)
|
77
|
-
@html =
|
78
|
-
when :plain, :example, :html, :javascript
|
79
|
-
remove_highlights(result)
|
80
|
-
when :markdown
|
81
|
-
renderer = LivingStyleGuide::RedcarpetHTML.new(LivingStyleGuide.default_options, self)
|
82
|
-
redcarpet = ::Redcarpet::Markdown.new(renderer, LivingStyleGuide::REDCARPET_RENDER_OPTIONS)
|
83
|
-
remove_highlights(redcarpet.render(result))
|
84
|
-
else
|
85
|
-
require "tilt/#{@type}"
|
86
|
-
template_class.new{ remove_highlights(result) }.render(@scope, @locals.merge(locals))
|
87
|
-
end
|
74
|
+
@html = render_html(result, locals)
|
88
75
|
@classes.unshift "livingstyleguide--#{@type}-example"
|
89
76
|
@classes.unshift "livingstyleguide--example"
|
90
77
|
ERB.new(template_erb).result(binding).gsub(/\n\n+/, "\n")
|
@@ -94,6 +81,25 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
94
81
|
@scope.depend_on(File.expand_path(file)) if @scope.respond_to?(:depend_on)
|
95
82
|
end
|
96
83
|
|
84
|
+
private
|
85
|
+
def render_html(result, locals)
|
86
|
+
if @type == :lsg
|
87
|
+
renderer = LivingStyleGuide::RedcarpetHTML.new(LivingStyleGuide.default_options, self)
|
88
|
+
redcarpet = ::Redcarpet::Markdown.new(renderer, LivingStyleGuide::REDCARPET_RENDER_OPTIONS)
|
89
|
+
redcarpet.render(result)
|
90
|
+
elsif engine = Tilt[@type]
|
91
|
+
begin
|
92
|
+
require "tilt/#{template_name}"
|
93
|
+
rescue LoadError
|
94
|
+
end
|
95
|
+
engine.new{ remove_highlights(result) }.render(@scope, @locals.merge(locals))
|
96
|
+
elsif @type == :escaped
|
97
|
+
ERB::Util.h(remove_highlights(result))
|
98
|
+
else
|
99
|
+
remove_highlights(result)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
97
103
|
private
|
98
104
|
def set_highlights(code, &block)
|
99
105
|
code, positions = remove_highlight_marker_and_save_positions(code)
|
@@ -164,21 +170,45 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
164
170
|
def parse_filters
|
165
171
|
data.gsub('<%', '<%%').gsub(/\G(.*?)((```.+?```)|\Z)/m) do
|
166
172
|
content, code_block = $1, $2
|
167
|
-
content.gsub(/^@([\w\d_-]+)(?: ([^\{\n]
|
168
|
-
name,
|
173
|
+
content.gsub(/^@([\w\d_-]+)(?: ([^\n]*[^\{\n:]))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*(?:\n|\Z))+)| *:\n((?:.|\n)*?)(?:\n\n|\Z))?/) do
|
174
|
+
name, arguments_string, block = $1, $2 || '', $3 || $4 || $5
|
175
|
+
options = {
|
176
|
+
block_type: $3 ? :braces : $4 ? :indented : $5 ? :block : :none
|
177
|
+
}
|
169
178
|
name = name.gsub('-', '_').to_sym
|
170
|
-
arguments =
|
171
|
-
if
|
172
|
-
|
179
|
+
arguments = parse_arguments(arguments_string, options)
|
180
|
+
if options[:block_type] == :indented
|
181
|
+
block.gsub!(/\A(\s*)((?:.|\n)+)\Z/){ $2.gsub(/^#{$1}/, '') }
|
173
182
|
end
|
174
|
-
yield name, arguments
|
183
|
+
yield name, arguments, options, block
|
175
184
|
end + code_block
|
176
185
|
end
|
177
186
|
end
|
178
187
|
|
188
|
+
private
|
189
|
+
def parse_arguments(arguments_string, options)
|
190
|
+
arguments = arguments_string.split(/(?<!\\);/)
|
191
|
+
arguments.map! do |argument|
|
192
|
+
argument.strip!
|
193
|
+
argument.gsub! "\\;", ";"
|
194
|
+
if /^(?<key>[a-zA-Z0-9_\-]+):(?<value>.+)$/ =~ argument
|
195
|
+
options[key.downcase.gsub('-', '_').to_sym] = remove_quots(value.strip)
|
196
|
+
nil
|
197
|
+
else
|
198
|
+
remove_quots(argument)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
arguments.compact
|
202
|
+
end
|
203
|
+
|
204
|
+
private
|
205
|
+
def remove_quots(string)
|
206
|
+
string.sub(/^"(.*)"$|^'(.*)'$|^(.*)$/, '\\1\\2\\3').gsub(/\\("|')/, "\\1")
|
207
|
+
end
|
208
|
+
|
179
209
|
private
|
180
210
|
def gsub_content(regexp, &block)
|
181
|
-
if @type == :
|
211
|
+
if @type == :lsg
|
182
212
|
data.gsub(/\G(.+?)((```.+?```)|\Z)/m) do
|
183
213
|
content, code_block = $1, $2
|
184
214
|
content.to_s.gsub(regexp, &block) + code_block
|
@@ -190,16 +220,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
190
220
|
|
191
221
|
private
|
192
222
|
def template_name
|
193
|
-
@type == :markdown ? :redcarpet : @type
|
194
|
-
end
|
195
|
-
|
196
|
-
private
|
197
|
-
def template_class
|
198
|
-
case @type
|
199
|
-
when :coffee then Tilt::CoffeeScriptTemplate
|
200
|
-
when :erb then Tilt::ERBTemplate
|
201
|
-
else Tilt.const_get(@type.to_s.capitalize + 'Template')
|
202
|
-
end
|
223
|
+
(@type == :lsg or @type == :markdown) ? :redcarpet : @type
|
203
224
|
end
|
204
225
|
|
205
226
|
private
|
@@ -21,6 +21,7 @@ require 'livingstyleguide/filters/import'
|
|
21
21
|
require 'livingstyleguide/filters/require'
|
22
22
|
require 'livingstyleguide/filters/full_width'
|
23
23
|
require 'livingstyleguide/filters/haml'
|
24
|
+
require 'livingstyleguide/filters/type'
|
24
25
|
require 'livingstyleguide/filters/markdown'
|
25
26
|
require 'livingstyleguide/filters/javascript'
|
26
27
|
require 'livingstyleguide/filters/coffee_script'
|
@@ -28,5 +29,6 @@ require 'livingstyleguide/filters/add_wrapper_class'
|
|
28
29
|
require 'livingstyleguide/filters/font_example'
|
29
30
|
require 'livingstyleguide/filters/colors'
|
30
31
|
require 'livingstyleguide/filters/css'
|
32
|
+
require 'livingstyleguide/filters/style'
|
31
33
|
require 'livingstyleguide/filters/data'
|
32
34
|
require 'livingstyleguide/filters/html_head'
|
@@ -1,5 +1,5 @@
|
|
1
|
-
LivingStyleGuide.add_filter :colors do |content|
|
2
|
-
colors = content.split(/\n+/).map{ |l| l.split(/\s+/) }
|
1
|
+
LivingStyleGuide.add_filter :colors do |arguments, options, content|
|
2
|
+
colors = content.split(/\n+/).map{ |l| l.strip.split(/\s+/) }
|
3
3
|
columns = colors.map{ |l| l.size }.max
|
4
4
|
colors = colors.flatten
|
5
5
|
document.scss << <<-SCSS
|
@@ -1,10 +1,11 @@
|
|
1
|
-
LivingStyleGuide.add_filter :css, :scss do |source|
|
2
|
-
|
1
|
+
LivingStyleGuide.add_filter :css, :scss do |arguments, options, source|
|
2
|
+
file = arguments.first
|
3
|
+
if file =~ /\.(css|scss|sass)$/
|
3
4
|
if document.file
|
4
|
-
|
5
|
+
file = File.join(File.dirname(document.file), file)
|
5
6
|
end
|
6
|
-
document.depend_on
|
7
|
-
document.scss << %Q(@import "#{
|
7
|
+
document.depend_on file
|
8
|
+
document.scss << %Q(@import "#{file}";\n)
|
8
9
|
else
|
9
10
|
document.scss << "##{document.id.gsub('/', '\\/')} {\n#{source}\n}\n"
|
10
11
|
end
|
@@ -5,11 +5,11 @@ LivingStyleGuide.default_options[:font_example] = { text: <<-TEXT }
|
|
5
5
|
!&/()$=@;:,.
|
6
6
|
TEXT
|
7
7
|
|
8
|
-
LivingStyleGuide.add_filter :font_example do |
|
8
|
+
LivingStyleGuide.add_filter :font_example do |arguments, options, text|
|
9
9
|
text ||= LivingStyleGuide.default_options[:font_example][:text]
|
10
10
|
text = ERB::Util.html_escape(text)
|
11
11
|
text.strip!
|
12
12
|
text.gsub!(/\n/, "<br>\n")
|
13
|
-
font = ERB::Util.html_escape(
|
13
|
+
font = ERB::Util.html_escape(arguments.first)
|
14
14
|
ERB.new(File.read("#{File.dirname(__FILE__)}/../templates/font-example.html.erb")).result(binding)
|
15
15
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tilt'
|
2
2
|
|
3
|
-
LivingStyleGuide.add_filter :import do |
|
3
|
+
LivingStyleGuide.add_filter :import do |arguments, options, data|
|
4
|
+
glob = arguments.first
|
4
5
|
if glob =~ /\.s[ac]ss$/
|
5
6
|
raise "Error: Please use `@css #{glob}` instead of `@import #{glob}` for importing Sass."
|
6
7
|
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
LivingStyleGuide.add_filter :set do |
|
2
|
-
|
3
|
-
key
|
4
|
-
key = key.downcase.gsub('-', '_').to_sym
|
5
|
-
value = case value
|
1
|
+
LivingStyleGuide.add_filter :set do |arguments, options, block|
|
2
|
+
options.each do |key, value|
|
3
|
+
document.options[key] = case value
|
6
4
|
when 'true'
|
7
5
|
true
|
8
6
|
when 'false'
|
@@ -12,7 +10,6 @@ LivingStyleGuide.add_filter :set do |option|
|
|
12
10
|
else
|
13
11
|
value
|
14
12
|
end
|
15
|
-
document.options[key] = value
|
16
13
|
end
|
17
14
|
nil
|
18
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: livingstyleguide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.alpha.
|
4
|
+
version: 2.0.0.alpha.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nico Hagenburger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minisyntax
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.2.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.2.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sass
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,6 +124,20 @@ dependencies:
|
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: heredoc_unindent
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.2.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.2.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: minitest
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
@@ -137,7 +151,7 @@ dependencies:
|
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
154
|
+
name: coffee-script
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - ">="
|
@@ -151,7 +165,7 @@ dependencies:
|
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
168
|
+
name: i18n
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
156
170
|
requirements:
|
157
171
|
- - ">="
|
@@ -194,12 +208,15 @@ files:
|
|
194
208
|
- lib/livingstyleguide/filters/markdown.rb
|
195
209
|
- lib/livingstyleguide/filters/options.rb
|
196
210
|
- lib/livingstyleguide/filters/require.rb
|
211
|
+
- lib/livingstyleguide/filters/style.rb
|
212
|
+
- lib/livingstyleguide/filters/type.rb
|
197
213
|
- lib/livingstyleguide/integration.rb
|
198
214
|
- lib/livingstyleguide/integration/compass.rb
|
199
215
|
- lib/livingstyleguide/integration/rails.rb
|
200
216
|
- lib/livingstyleguide/integration/sass.rb
|
201
217
|
- lib/livingstyleguide/integration/sprockets.rb
|
202
218
|
- lib/livingstyleguide/markdown_extensions.rb
|
219
|
+
- lib/livingstyleguide/templates/code.html.erb
|
203
220
|
- lib/livingstyleguide/templates/default.html.erb
|
204
221
|
- lib/livingstyleguide/templates/example.html.erb
|
205
222
|
- lib/livingstyleguide/templates/font-example.html.erb
|