livingstyleguide 2.0.0.pre.3 → 2.0.0.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/livingstyleguide +1 -1
- data/lib/livingstyleguide/command_line_interface.rb +14 -11
- data/lib/livingstyleguide/commands/colors.rb +16 -16
- data/lib/livingstyleguide/commands/default.rb +1 -1
- data/lib/livingstyleguide/commands/font_example.rb +2 -1
- data/lib/livingstyleguide/commands/full_width.rb +1 -1
- data/lib/livingstyleguide/commands/import_and_use.rb +16 -4
- data/lib/livingstyleguide/commands/layout.rb +22 -20
- data/lib/livingstyleguide/commands/options.rb +9 -9
- data/lib/livingstyleguide/commands/sass.rb +5 -11
- data/lib/livingstyleguide/commands/search_box.rb +6 -3
- data/lib/livingstyleguide/commands/style.rb +1 -1
- data/lib/livingstyleguide/document.rb +64 -41
- data/lib/livingstyleguide/integration/compass.rb +5 -2
- data/lib/livingstyleguide/integration/rails.rb +5 -3
- data/lib/livingstyleguide/integration/sass.rb +1 -1
- data/lib/livingstyleguide/integration/sprockets.rb +9 -4
- data/lib/livingstyleguide/markdown_extensions.rb +20 -11
- data/lib/livingstyleguide/templates/code.html.erb +1 -1
- data/lib/livingstyleguide/templates/example.html.erb +2 -2
- data/lib/livingstyleguide/templates/font-example.html.erb +3 -3
- data/lib/livingstyleguide/templates/javascript.html.erb +1 -1
- data/lib/livingstyleguide/templates/layout.html.erb +32 -38
- data/lib/livingstyleguide/templates/logo.html.erb +1 -1
- data/lib/livingstyleguide/templates/scripts/copy.js.erb +12 -12
- data/lib/livingstyleguide/templates/scripts/copy_code.js.erb +7 -7
- data/lib/livingstyleguide/templates/scripts/copy_colors.js.erb +14 -14
- data/lib/livingstyleguide/templates/scripts/search.js.erb +30 -30
- data/lib/livingstyleguide/templates/scripts/toggle_code.js.erb +23 -23
- data/lib/livingstyleguide/templates/search-box.html.erb +1 -1
- data/lib/livingstyleguide/templates/toggle-code.html.erb +1 -1
- data/lib/livingstyleguide/tilt_template.rb +17 -19
- data/lib/livingstyleguide/version.rb +1 -1
- data/lib/livingstyleguide.rb +12 -2
- data/stylesheets/_livingstyleguide.scss +76 -65
- data/stylesheets/livingstyleguide/_code.scss +51 -51
- data/stylesheets/livingstyleguide/_color-swatches.scss +38 -38
- data/stylesheets/livingstyleguide/_content.scss +73 -73
- data/stylesheets/livingstyleguide/_functions.scss +1 -1
- data/stylesheets/livingstyleguide/_layout.scss +22 -22
- data/stylesheets/livingstyleguide/_reset.scss +1 -1
- data/stylesheets/livingstyleguide/_search-box.scss +14 -14
- data/stylesheets/livingstyleguide/_toggle-code.scss +10 -11
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25ce8afc33ae405fcf54ef052d1a3faa6e25b20b
|
4
|
+
data.tar.gz: f285f19dcea8ef29dcc9044ad9ecc21b7dc476e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 651a10ac4ce32ced56f0b1a99c01347bd2c96ef5687db65ad2e3e947855ed595257e97edbae6a7225bf6cbd1fe8f77678c2ecfe4acb7cbcd907011969730fec2
|
7
|
+
data.tar.gz: 34d1320a6adf0fe9ea7bad92d885c44873149661ef1827bd1fd07d69b2f24ca8b4d1d00d5062a14cfe3bd0e4cc18f7a2d659c038f72f77f679486295ce232444
|
data/bin/livingstyleguide
CHANGED
@@ -3,8 +3,8 @@ require "tilt"
|
|
3
3
|
|
4
4
|
module LivingStyleGuide
|
5
5
|
class CommandLineInterface < Thor
|
6
|
-
|
7
|
-
|
6
|
+
desc "compile input_file output_file",
|
7
|
+
"Compiles the living style guide to HTML."
|
8
8
|
def compile(input_file = nil, output_file = nil)
|
9
9
|
doc = LivingStyleGuide::Document.new(input_file) do
|
10
10
|
input(input_file)
|
@@ -12,34 +12,37 @@ module LivingStyleGuide
|
|
12
12
|
output doc.render, input_file, output_file
|
13
13
|
end
|
14
14
|
|
15
|
-
desc "version",
|
15
|
+
desc "version",
|
16
|
+
"Shows the current version of the Gem"
|
16
17
|
def version
|
17
18
|
puts "LivingStyleGuide #{LivingStyleGuide::VERSION}"
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
22
|
+
|
21
23
|
def input(input_file = nil)
|
22
24
|
@input ||= if input_file.nil?
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
$stdin.read
|
26
|
+
else
|
27
|
+
File.read(input_file)
|
28
|
+
end
|
27
29
|
end
|
28
30
|
|
29
|
-
private
|
30
31
|
def output(html, input_file = nil, output_file = nil)
|
31
32
|
if input_file.nil?
|
32
33
|
puts html
|
33
34
|
else
|
34
|
-
|
35
|
+
if output_file.nil?
|
36
|
+
output_file = input_file.sub(/(\.html)?\.lsg$/, ".html")
|
37
|
+
end
|
35
38
|
if defined?(Compass)
|
36
39
|
Compass.add_project_configuration
|
37
|
-
output_file = output_file.sub(/^#{Compass.configuration.sass_dir}/,
|
40
|
+
output_file = output_file.sub(/^#{Compass.configuration.sass_dir}/,
|
41
|
+
Compass.configuration.css_dir)
|
38
42
|
end
|
39
43
|
File.write output_file, html
|
40
44
|
puts "Successfully generated a living style guide at #{output_file}."
|
41
45
|
end
|
42
46
|
end
|
43
|
-
|
44
47
|
end
|
45
48
|
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require "digest/sha1"
|
2
2
|
|
3
3
|
LivingStyleGuide.command :colors do |arguments, options, content|
|
4
|
-
colors = content.split(/\n+/).map{ |l| l.strip.split(/(?<![,\(])\s+(?!\))/) }
|
5
|
-
columns = colors.map
|
4
|
+
colors = content.split(/\n+/).map { |l| l.strip.split(/(?<![,\(])\s+(?!\))/) }
|
5
|
+
columns = colors.map(&:size).max
|
6
6
|
colors = colors.flatten
|
7
7
|
|
8
8
|
def color_class(color)
|
9
|
-
"lsg
|
9
|
+
"lsg-color-" + Digest::SHA1.hexdigest(color)[0..7]
|
10
10
|
end
|
11
11
|
|
12
|
+
colors_as_sass_map = colors.reject { |c| c == "-" }.uniq.map do |color|
|
13
|
+
%Q("#{color_class(color)}": #{color})
|
14
|
+
end.join(", ")
|
12
15
|
document.scss << <<-SCSS
|
13
|
-
$lsg
|
14
|
-
$lsg
|
15
|
-
$lsg--colors, (#{
|
16
|
-
colors.reject{ |c| c == '-' }.map do |color|
|
17
|
-
%Q("#{color_class(color)}": #{color})
|
18
|
-
end.join(', ')
|
19
|
-
})
|
20
|
-
);
|
16
|
+
$lsg-colors: () !default;
|
17
|
+
$lsg-colors: join($lsg-colors, (#{colors_as_sass_map}));
|
21
18
|
SCSS
|
22
19
|
|
23
20
|
colors_html = colors.map do |color|
|
24
21
|
if color == "-"
|
25
|
-
%
|
22
|
+
%(<li class="lsg-color-swatch lsg-empty"></li>\n)
|
26
23
|
else
|
27
24
|
unless color =~ /^(#[0-9a-f]{3,6}|[a-z]+)$/
|
28
|
-
source = %
|
25
|
+
source = %(<span class="lsg-color-swatch-source">#{color}</span>)
|
29
26
|
end
|
30
|
-
|
31
|
-
%
|
27
|
+
class_name = "lsg-color-swatch-value #{color_class(color)}"
|
28
|
+
value = %(<span class="#{class_name}"></span>)
|
29
|
+
class_name = "lsg-color-swatch #{color_class(color)}"
|
30
|
+
%(<li class="#{class_name}">#{source}#{value}</li>\n)
|
32
31
|
end
|
33
32
|
end.join("\n")
|
34
|
-
|
33
|
+
class_name = "lsg-color-swatches lsg-#{columns}-columns"
|
34
|
+
%(<ul class="#{class_name}">\n#{colors_html}\n</ul>\n)
|
35
35
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
LivingStyleGuide.command :default do |arguments, options, block|
|
2
|
-
key = arguments.first ? arguments.first.
|
2
|
+
key = arguments.first ? arguments.first.tr("-", "_").to_sym : :global
|
3
3
|
document.defaults[key] ||= {}
|
4
4
|
document.defaults[key].merge!(options)
|
5
5
|
nil
|
@@ -1,11 +1,19 @@
|
|
1
1
|
require "tilt"
|
2
2
|
|
3
|
-
def map_files(glob
|
3
|
+
def map_files(glob)
|
4
4
|
glob << ".lsg" unless glob =~ /\.(\w+|\*)$/
|
5
5
|
glob.gsub!(/[^\/]+$/, "{_,}\\0")
|
6
6
|
glob = File.join(document.path, glob)
|
7
7
|
|
8
|
-
Dir.glob(glob)
|
8
|
+
files = Dir.glob(glob)
|
9
|
+
if glob.index("*")
|
10
|
+
files.uniq!
|
11
|
+
files.reject! { |f| document.files.include?(f) }
|
12
|
+
else
|
13
|
+
raise Errno::ENOENT if files.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
files.map do |file|
|
9
17
|
document.depend_on file
|
10
18
|
yield(file)
|
11
19
|
end.join
|
@@ -14,13 +22,17 @@ end
|
|
14
22
|
LivingStyleGuide.command :import do |arguments, options, data|
|
15
23
|
glob = arguments.first
|
16
24
|
if glob =~ /\.s[ac]ss$/
|
17
|
-
raise
|
25
|
+
raise <<-ERROR.strip.squeeze
|
26
|
+
Error: Please use `@css #{glob}` instead of `@import #{glob}`
|
27
|
+
for importing Sass.
|
28
|
+
ERROR
|
18
29
|
end
|
19
30
|
|
20
31
|
data = LivingStyleGuide.parse_data(data)
|
21
32
|
|
22
33
|
map_files glob do |file|
|
23
|
-
|
34
|
+
template = ::Tilt.new(file, livingstyleguide: document)
|
35
|
+
html = template.render(document.scope, data)
|
24
36
|
html.gsub!("\n", "\n ")
|
25
37
|
"\n<div>\n#{html}\n</div>\n"
|
26
38
|
end
|
@@ -3,30 +3,32 @@ LivingStyleGuide.command :title do |arguments, options, block|
|
|
3
3
|
nil
|
4
4
|
end
|
5
5
|
|
6
|
-
{ :
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
document.#{destination} << %Q(<script>\\n\#{block}\\n</script>)
|
6
|
+
{ before: :head, after: :footer }.each do |name, destination|
|
7
|
+
LivingStyleGuide.command :"javascript_#{name}" do |arguments, options, block|
|
8
|
+
content = document.send(:"#{destination}")
|
9
|
+
if src = arguments.first
|
10
|
+
content << %Q(<script src="#{src}"></script>)
|
11
|
+
else
|
12
|
+
if options[:transpiler] == "coffee-script"
|
13
|
+
block = Tilt["coffee"].new { block }.render
|
16
14
|
end
|
17
|
-
|
15
|
+
content << %Q(<script>\n#{block}\n</script>)
|
18
16
|
end
|
19
|
-
|
17
|
+
document.send(:"#{destination}=", content)
|
18
|
+
nil
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
|
-
%w(head header footer before after).each do |
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
document.#{part} << html.render + "\n"
|
28
|
-
nil
|
22
|
+
%w(head header footer before after).each do |destination|
|
23
|
+
LivingStyleGuide.command :"#{destination}" do |arguments, options, block|
|
24
|
+
content = document.send(:"#{destination}")
|
25
|
+
html = LivingStyleGuide::Document.new(livingstyleguide: document) do
|
26
|
+
block
|
29
27
|
end
|
30
|
-
|
28
|
+
html.type = options[:type]
|
29
|
+
content << html.render + "\n"
|
30
|
+
document.send(:"#{destination}=", content)
|
31
|
+
nil
|
32
|
+
end
|
31
33
|
nil
|
32
34
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
LivingStyleGuide.command :set do |arguments, options, block|
|
2
2
|
options.each do |key, value|
|
3
3
|
document.options[key] = case value
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
when "true"
|
5
|
+
true
|
6
|
+
when "false"
|
7
|
+
false
|
8
|
+
when /^\d+$/
|
9
|
+
value.to_i
|
10
|
+
else
|
11
|
+
value
|
12
|
+
end
|
13
13
|
end
|
14
14
|
nil
|
15
15
|
end
|
@@ -2,14 +2,14 @@ require "sass"
|
|
2
2
|
|
3
3
|
LivingStyleGuide.command :scss do |arguments, options, scss|
|
4
4
|
file = arguments.first
|
5
|
-
if file
|
5
|
+
if options[:scope] == "global" || file == "!global"
|
6
|
+
document.scss << scss
|
7
|
+
elsif file
|
6
8
|
if document.file
|
7
9
|
file = File.join(File.dirname(document.file), file)
|
8
10
|
end
|
9
11
|
document.depend_on file
|
10
12
|
document.scss << %Q(@import "#{file}";\n)
|
11
|
-
elsif options[:scope] == "global"
|
12
|
-
document.scss << scss
|
13
13
|
else
|
14
14
|
id = document.id.gsub(/[\/\.]/, '\\\\\0')
|
15
15
|
document.scss << "##{id} {\n#{scss}\n}\n"
|
@@ -18,12 +18,6 @@ LivingStyleGuide.command :scss do |arguments, options, scss|
|
|
18
18
|
end
|
19
19
|
|
20
20
|
LivingStyleGuide.command :sass do |arguments, options, sass|
|
21
|
-
|
22
|
-
|
23
|
-
scss(arguments, options, nil)
|
24
|
-
else
|
25
|
-
converted = Sass::Engine.new(sass).to_tree.to_scss
|
26
|
-
scss(arguments, options, converted)
|
27
|
-
end
|
28
|
-
nil
|
21
|
+
converted = Sass::Engine.new(sass).to_tree.to_scss unless sass.nil?
|
22
|
+
scss(arguments, options, converted)
|
29
23
|
end
|
@@ -3,8 +3,11 @@ LivingStyleGuide.default_options[:search_box] = {
|
|
3
3
|
}
|
4
4
|
|
5
5
|
LivingStyleGuide.command :search_box do |arguments, options, content|
|
6
|
-
placeholder = options[:placeholder]
|
7
|
-
|
8
|
-
document.
|
6
|
+
placeholder = options[:placeholder]
|
7
|
+
placeholder ||= LivingStyleGuide.default_options[:search_box][:placeholder]
|
8
|
+
document.before <<
|
9
|
+
LivingStyleGuide.template("search-box.html.erb", binding)
|
10
|
+
document.javascript <<
|
11
|
+
LivingStyleGuide.template("scripts/search.js.erb", binding)
|
9
12
|
nil
|
10
13
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
LivingStyleGuide.command :style do |arguments, options, block|
|
2
2
|
options.delete :block_type
|
3
3
|
options.each do |key, value|
|
4
|
-
document.scss << %Q($lsg
|
4
|
+
document.scss << %Q($lsg-#{key.to_s.tr('_', '-')}: #{value};\n)
|
5
5
|
end
|
6
6
|
nil
|
7
7
|
end
|
@@ -12,7 +12,9 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
12
12
|
attr_accessor :syntax
|
13
13
|
attr_reader :scope
|
14
14
|
|
15
|
-
%w(
|
15
|
+
%w(
|
16
|
+
scss head header footer defaults javascript before after files
|
17
|
+
).each do |attr|
|
16
18
|
define_method attr do
|
17
19
|
if options.has_key?(:livingstyleguide)
|
18
20
|
options[:livingstyleguide].send(attr)
|
@@ -25,7 +27,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
25
27
|
if options.has_key?(:livingstyleguide)
|
26
28
|
options[:livingstyleguide].send("#{attr}=", value)
|
27
29
|
else
|
28
|
-
|
30
|
+
instance_variable_set("@#{attr}", value)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -35,9 +37,14 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def prepare
|
40
|
+
if options.has_key?(:livingstyleguide)
|
41
|
+
@template = :default
|
42
|
+
else
|
43
|
+
@template = :layout
|
44
|
+
@files = []
|
45
|
+
end
|
38
46
|
@type = :lsg
|
39
47
|
@commands = LivingStyleGuide::Commands.new(self)
|
40
|
-
@template = options.has_key?(:livingstyleguide) ? :default : :layout
|
41
48
|
@classes = []
|
42
49
|
@scss = ""
|
43
50
|
@css = ""
|
@@ -82,7 +89,10 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
82
89
|
|
83
90
|
def erb
|
84
91
|
@erb ||= parse_commands do |name, arguments, options, block|
|
85
|
-
|
92
|
+
global = "document.defaults[:global]"
|
93
|
+
scoped = "document.defaults[:@#{name}] || {}"
|
94
|
+
local = options.inspect
|
95
|
+
options = "#{global}.merge(#{scoped}).merge(#{local})"
|
86
96
|
"<%= #{name}(#{arguments.inspect}, #{options}, #{block.inspect}) %>\n"
|
87
97
|
end
|
88
98
|
end
|
@@ -91,7 +101,8 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
91
101
|
@head = ""
|
92
102
|
@javascript = ""
|
93
103
|
%w(copy copy_code copy_colors toggle_code).each do |partial|
|
94
|
-
|
104
|
+
file = "scripts/#{partial}.js.erb"
|
105
|
+
@javascript << LivingStyleGuide.template(file, binding)
|
95
106
|
end
|
96
107
|
@header = ""
|
97
108
|
@before = ""
|
@@ -101,27 +112,31 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
101
112
|
result = ERB.new(erb).result(@commands.get_binding)
|
102
113
|
@source = result
|
103
114
|
@html = render_html(result, locals)
|
104
|
-
@classes.unshift "lsg
|
105
|
-
@classes.unshift "lsg
|
115
|
+
@classes.unshift "lsg-#{@type}-example"
|
116
|
+
@classes.unshift "lsg-example"
|
106
117
|
ERB.new(template_erb).result(binding).gsub(/\n\n+/, "\n")
|
107
118
|
end
|
108
119
|
|
109
120
|
def depend_on(file)
|
121
|
+
files << file
|
110
122
|
@scope.depend_on(File.expand_path(file)) if @scope.respond_to?(:depend_on)
|
111
123
|
end
|
112
124
|
|
113
125
|
private
|
126
|
+
|
114
127
|
def render_html(result, locals)
|
115
128
|
if @type == :lsg
|
116
|
-
|
117
|
-
|
129
|
+
renderer_options = LivingStyleGuide.default_options
|
130
|
+
renderer = LivingStyleGuide::RedcarpetHTML.new(self, renderer_options)
|
131
|
+
redcarpet_options = LivingStyleGuide::REDCARPET_RENDER_OPTIONS
|
132
|
+
redcarpet = ::Redcarpet::Markdown.new(renderer, redcarpet_options)
|
118
133
|
redcarpet.render(result)
|
119
134
|
elsif engine = Tilt[@type]
|
120
135
|
begin
|
121
136
|
require "tilt/#{template_name}"
|
122
137
|
rescue LoadError
|
123
138
|
end
|
124
|
-
template = engine.new{ remove_highlights(result) }
|
139
|
+
template = engine.new { remove_highlights(result) }
|
125
140
|
(@locals.is_a?(Array) ? @locals : [@locals]).map do |current_locals|
|
126
141
|
template.render(@scope || Object.new, current_locals.merge(locals))
|
127
142
|
end.join("\n")
|
@@ -132,14 +147,12 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
132
147
|
end
|
133
148
|
end
|
134
149
|
|
135
|
-
|
136
|
-
def set_highlights(code, &block)
|
150
|
+
def set_highlights(code)
|
137
151
|
code, positions = remove_highlight_marker_and_save_positions(code)
|
138
152
|
html = yield(code)
|
139
153
|
insert_html_highlight_marker(html, positions)
|
140
154
|
end
|
141
155
|
|
142
|
-
private
|
143
156
|
def remove_highlight_marker_and_save_positions(code)
|
144
157
|
positions = []
|
145
158
|
index = 0
|
@@ -150,7 +163,6 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
150
163
|
[code_without_highlights, positions]
|
151
164
|
end
|
152
165
|
|
153
|
-
private
|
154
166
|
def insert_html_highlight_marker(html, positions)
|
155
167
|
code_with_highlights = ""
|
156
168
|
index = 0
|
@@ -169,14 +181,14 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
169
181
|
code_with_highlights << %Q(</strong>)
|
170
182
|
inside_highlight = false
|
171
183
|
else
|
172
|
-
code_with_highlights << %Q(<strong class="lsg
|
184
|
+
code_with_highlights << %Q(<strong class="lsg-code-highlight">)
|
173
185
|
inside_highlight = true
|
174
186
|
end
|
175
187
|
next_position = positions.shift
|
176
188
|
end
|
177
189
|
if char == "&"
|
178
190
|
inside_character = true
|
179
|
-
elsif inside_character
|
191
|
+
elsif inside_character && char == ";"
|
180
192
|
inside_character = false
|
181
193
|
index += 1
|
182
194
|
elsif not inside_character
|
@@ -189,30 +201,24 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
189
201
|
code_with_highlights
|
190
202
|
end
|
191
203
|
|
192
|
-
private
|
193
204
|
def remove_highlights(code)
|
194
205
|
code.gsub(/\*\*\*/, "")
|
195
206
|
end
|
196
207
|
|
197
|
-
private
|
198
208
|
def template_erb
|
199
209
|
File.read("#{File.dirname(__FILE__)}/templates/#{@template}.html.erb")
|
200
210
|
end
|
201
211
|
|
202
|
-
private
|
203
212
|
def parse_commands
|
204
|
-
data.gsub("<%", "<%%")
|
205
|
-
|
206
|
-
content
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
}
|
211
|
-
|
212
|
-
|
213
|
-
if options[:block_type] == :indented
|
214
|
-
block.gsub!(/\A\n(\s*)((?:.|\n)+)\Z/){ $2.gsub(/^#{$1}/, "") }
|
215
|
-
end
|
213
|
+
doc = (data || "").gsub("<%", "<%%")
|
214
|
+
doc.gsub(/\G(?<content>.*?)(?<code_block>(?:```.+?```)|\Z)/m) do
|
215
|
+
content = $~[:content]
|
216
|
+
code_block = $~[:code_block]
|
217
|
+
content.gsub!(LivingStyleGuide::COMMANDS_REGEXP) do
|
218
|
+
name = $~[:name].tr("-", "_").to_sym
|
219
|
+
options = {}
|
220
|
+
arguments = parse_arguments($~[:arguments], options)
|
221
|
+
block = parse_block($~[:braces], $~[:indented], $~[:colon], options)
|
216
222
|
yield name, arguments, options, block
|
217
223
|
end
|
218
224
|
content.gsub!(/^\\@/, "@")
|
@@ -220,14 +226,14 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
220
226
|
end
|
221
227
|
end
|
222
228
|
|
223
|
-
private
|
224
229
|
def parse_arguments(arguments_string, options)
|
230
|
+
return [] if arguments_string.nil?
|
225
231
|
arguments = arguments_string.split(/(?<!\\);/)
|
226
232
|
arguments.map! do |argument|
|
227
233
|
argument.strip!
|
228
234
|
argument.gsub! "\\;", ";"
|
229
235
|
if /^(?<key>[a-zA-Z0-9_\-]+):(?<value>.+)$/ =~ argument
|
230
|
-
options[key.downcase.
|
236
|
+
options[key.downcase.tr("-", "_").to_sym] = remove_quots(value.strip)
|
231
237
|
nil
|
232
238
|
else
|
233
239
|
remove_quots(argument)
|
@@ -236,12 +242,32 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
236
242
|
arguments.compact
|
237
243
|
end
|
238
244
|
|
239
|
-
|
245
|
+
def parse_block(braces_block, indented_block, colon_block, options)
|
246
|
+
if braces_block
|
247
|
+
options[:block_type] = :braces
|
248
|
+
braces_block
|
249
|
+
elsif indented_block
|
250
|
+
options[:block_type] = :indented
|
251
|
+
unindent(indented_block)
|
252
|
+
elsif colon_block
|
253
|
+
options[:block_type] = :colon
|
254
|
+
colon_block
|
255
|
+
else
|
256
|
+
options[:block_type] = :none
|
257
|
+
nil
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def unindent(block)
|
262
|
+
block.gsub(/\A\n(?<indent>(?: |\t)*)(?<content>(?:.|\n)+)\Z/) do
|
263
|
+
$~[:content].gsub(/^#{$~[:indent]}/, "")
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
240
267
|
def remove_quots(string)
|
241
268
|
string.sub(/^"(.*)"$|^"(.*)"$|^(.*)$/, "\\1\\2\\3").gsub(/\\("|")/, "\\1")
|
242
269
|
end
|
243
270
|
|
244
|
-
private
|
245
271
|
def gsub_content(regexp, &block)
|
246
272
|
if @type == :lsg
|
247
273
|
data.gsub(/\G(.+?)((```.+?```)|\Z)/m) do
|
@@ -253,12 +279,10 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
253
279
|
end
|
254
280
|
end
|
255
281
|
|
256
|
-
private
|
257
282
|
def template_name
|
258
|
-
(@type == :lsg
|
283
|
+
(@type == :lsg || @type == :markdown) ? :redcarpet : @type
|
259
284
|
end
|
260
285
|
|
261
|
-
private
|
262
286
|
def generate_id
|
263
287
|
if @file
|
264
288
|
id = Pathname.new(@file).cleanpath.to_s
|
@@ -268,12 +292,10 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
268
292
|
end
|
269
293
|
end
|
270
294
|
|
271
|
-
private
|
272
295
|
def scss_template
|
273
296
|
::LivingStyleGuide.default_options[:scss_template] || Tilt["scss"]
|
274
297
|
end
|
275
298
|
|
276
|
-
private
|
277
299
|
def render_scss(scss)
|
278
300
|
sass_options = options.merge(custom: { sprockets_context: @scope })
|
279
301
|
sass_options[:load_paths] ||= []
|
@@ -283,7 +305,8 @@ class LivingStyleGuide::Document < ::Tilt::Template
|
|
283
305
|
sass_options[:load_paths] << path
|
284
306
|
end
|
285
307
|
end
|
286
|
-
scss_template.new(file, sass_options){ scss }
|
308
|
+
template = scss_template.new(file, sass_options) { scss }
|
309
|
+
template.render(@scope || Object.new)
|
287
310
|
end
|
288
311
|
end
|
289
312
|
|