livingstyleguide 0.6.0.alpha.2 → 1.0.0.alpha.3
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 +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +20 -0
- data/MIT-LICENSE.md +11 -0
- data/README.md +44 -6
- data/lib/livingstyleguide.rb +6 -27
- data/lib/livingstyleguide/code_block.rb +35 -0
- data/lib/livingstyleguide/engine.rb +93 -0
- data/lib/livingstyleguide/example.rb +86 -0
- data/lib/livingstyleguide/filter_hooks.rb +34 -0
- data/lib/livingstyleguide/filters.rb +8 -0
- data/lib/livingstyleguide/filters/add_wrapper_class.rb +4 -0
- data/lib/livingstyleguide/filters/coffee_script.rb +18 -0
- data/lib/livingstyleguide/filters/font_example.rb +20 -0
- data/lib/livingstyleguide/filters/full_width.rb +4 -0
- data/lib/livingstyleguide/filters/haml.rb +16 -0
- data/lib/livingstyleguide/filters/highlights.rb +9 -0
- data/lib/livingstyleguide/filters/javascript.rb +10 -0
- data/lib/livingstyleguide/importer.rb +19 -6
- data/lib/livingstyleguide/markdown_extensions.rb +24 -59
- data/lib/livingstyleguide/tilt_template.rb +30 -7
- data/lib/livingstyleguide/version.rb +1 -1
- data/livingstyleguide.gemspec +4 -1
- data/stylesheets/_livingstyleguide.scss +1 -1
- data/stylesheets/livingstyleguide/_content.scss +9 -8
- data/templates/layouts/default.html.erb +6 -6
- data/test/example_test_helper.rb +22 -0
- data/test/fixtures/markdown/code-block-and-example.md +8 -0
- data/test/fixtures/markdown/example-with-highlight.md +1 -1
- data/test/fixtures/markdown/example.md +1 -1
- data/test/fixtures/markdown/font-example.md +4 -1
- data/test/fixtures/markdown/{layout-example.md → full-width-example.md} +2 -1
- data/test/fixtures/markdown/haml-example-with-highlight.md +2 -1
- data/test/fixtures/markdown/haml-example.md +2 -1
- data/test/fixtures/standalone/modules/_buttons.md +1 -1
- data/test/integration/markdown_test.rb +17 -14
- data/test/integration/sprockets_test.rb +19 -0
- data/test/integration/standalone_test.rb +1 -1
- data/test/integration/variables_test.rb +1 -1
- data/test/test_helper.rb +9 -1
- data/test/unit/code_block_test.rb +53 -0
- data/test/unit/example_test.rb +142 -0
- data/test/unit/filter_hooks_test.rb +46 -0
- data/test/unit/filters/add_wrapper_class_test.rb +15 -0
- data/test/unit/filters/coffee_script_test.rb +19 -0
- data/test/unit/filters/font_example_test.rb +47 -0
- data/test/unit/filters/full_width_test.rb +16 -0
- data/test/unit/filters/haml_test.rb +20 -0
- data/test/unit/filters/highlights_test.rb +26 -0
- data/test/unit/filters/javascript_test.rb +18 -0
- data/test/unit/sass_extensions_test.rb +1 -1
- metadata +87 -10
- data/LICENSE.txt +0 -22
- data/lib/livingstyleguide/renderer.rb +0 -36
- data/test/fixtures/markdown/javascript-example.md +0 -4
@@ -0,0 +1,18 @@
|
|
1
|
+
LivingStyleGuide::Example.add_filter :coffee_script do
|
2
|
+
begin
|
3
|
+
|
4
|
+
require 'coffee-script'
|
5
|
+
@syntax = :'coffee-script'
|
6
|
+
|
7
|
+
add_wrapper_class '-lsg-for-javascript'
|
8
|
+
|
9
|
+
pre_processor do |coffee_script|
|
10
|
+
javascript = CoffeeScript.compile(coffee_script)
|
11
|
+
%Q(<script>#{javascript}</script>\n)
|
12
|
+
end
|
13
|
+
|
14
|
+
rescue LoadError
|
15
|
+
raise "Please make sure `gem 'coffee-script'` is added to your Gemfile."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
LivingStyleGuide::Engine.default_options[:font_example] = { text: <<-TEXT }
|
2
|
+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
3
|
+
abcdefghijklmnopqrstuvwxyz
|
4
|
+
0123456789
|
5
|
+
!&/()$=@;:,.
|
6
|
+
TEXT
|
7
|
+
|
8
|
+
LivingStyleGuide::Example.add_filter :font_example do |font|
|
9
|
+
suppress_code_block
|
10
|
+
|
11
|
+
html do |content|
|
12
|
+
%(<div class="livingstyleguide--font-example" style="font: #{font}">\n#{content}\n</div>\n)
|
13
|
+
end
|
14
|
+
|
15
|
+
pre_processor do |content|
|
16
|
+
content = options[:font_example][:text] if content == ''
|
17
|
+
content.strip.gsub(/\n/, "<br>\n")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
LivingStyleGuide::Example.add_filter :haml do
|
2
|
+
begin
|
3
|
+
|
4
|
+
require 'haml'
|
5
|
+
Haml::Options.defaults[:attr_wrapper] = '"'
|
6
|
+
@syntax = :haml
|
7
|
+
|
8
|
+
pre_processor do |haml|
|
9
|
+
Haml::Engine.new(haml).render.strip
|
10
|
+
end
|
11
|
+
|
12
|
+
rescue LoadError
|
13
|
+
raise "Please make sure `gem 'haml'` is added to your Gemfile."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
LivingStyleGuide::CodeBlock.filter_code do |code|
|
2
|
+
code = code.gsub(/^\s*\*\*\*\n(.+?)\n\s*\*\*\*(\n|$)/m, %Q(\n<strong class="livingstyleguide--code-highlight-block">\\1</strong>\n))
|
3
|
+
code = code.gsub(/\*\*\*(.+?)\*\*\*/, %Q(<strong class="livingstyleguide--code-highlight">\\1</strong>))
|
4
|
+
end
|
5
|
+
|
6
|
+
LivingStyleGuide::Example.filter_before do |code|
|
7
|
+
code.gsub(/\*\*\*(.+?)\*\*\*/m, '\\1')
|
8
|
+
end
|
9
|
+
|
@@ -5,23 +5,36 @@ class LivingStyleGuide::Importer < Sass::Importers::Filesystem
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def find_relative(name, base, options, absolute = false)
|
8
|
-
|
9
|
-
super(name, base, options)
|
8
|
+
@options = options
|
9
|
+
engine = super(name, base, options)
|
10
|
+
find_markdown(options[:filename])
|
11
|
+
engine
|
10
12
|
end
|
11
13
|
|
12
14
|
def find(name, options)
|
13
|
-
|
15
|
+
@options = options
|
14
16
|
super(name, options)
|
15
17
|
end
|
16
18
|
|
19
|
+
private
|
17
20
|
def find_markdown(sass_filename)
|
21
|
+
files << sass_filename
|
18
22
|
glob = "#{sass_filename.sub(/\.s[ac]ss$/, '')}.md"
|
19
|
-
glob.sub!(/(.*)\//, '\\1/{_,}') unless glob =~ /\/_/
|
20
|
-
glob = '{_,}' + glob unless glob =~ /\//
|
21
23
|
Dir.glob(glob) do |markdown_filename|
|
22
|
-
|
24
|
+
files << markdown_filename
|
25
|
+
markdown << File.read(markdown_filename)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
29
|
+
private
|
30
|
+
def files
|
31
|
+
@options[:living_style_guide].files
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def markdown
|
36
|
+
@options[:living_style_guide].markdown
|
37
|
+
end
|
38
|
+
|
26
39
|
end
|
27
40
|
|
@@ -2,39 +2,26 @@ require 'redcarpet'
|
|
2
2
|
require 'tilt'
|
3
3
|
require 'minisyntax'
|
4
4
|
require 'erb'
|
5
|
-
require 'active_support/core_ext/string/inflections'
|
6
5
|
|
7
6
|
module LivingStyleGuide
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
7
|
+
REDCARPET_RENDER_OPTIONS = {
|
8
|
+
autolink: true,
|
9
|
+
fenced_code_blocks: true,
|
10
|
+
tables: true,
|
11
|
+
strikethrough: true,
|
12
|
+
space_after_headers: true,
|
13
|
+
superscript: true
|
14
|
+
}
|
17
15
|
|
18
|
-
|
19
|
-
RedcarpetHTML.new(RENDER_OPTIONS)
|
20
|
-
end
|
21
|
-
|
22
|
-
def prepare
|
23
|
-
@engine = ::Redcarpet::Markdown.new(generate_renderer, RENDER_OPTIONS)
|
24
|
-
@output = nil
|
25
|
-
end
|
16
|
+
class RedcarpetHTML < ::Redcarpet::Render::HTML
|
26
17
|
|
27
|
-
def
|
28
|
-
@
|
18
|
+
def initialize(options = {})
|
19
|
+
@options = options
|
29
20
|
super
|
30
21
|
end
|
31
22
|
|
32
|
-
end
|
33
|
-
|
34
|
-
class RedcarpetHTML < ::Redcarpet::Render::HTML
|
35
|
-
|
36
23
|
def header(text, header_level)
|
37
|
-
id = %Q( id="#{
|
24
|
+
id = %Q( id="#{slug(text)}")
|
38
25
|
klass = %w(page-title headline sub-headline sub-sub-headline)[header_level]
|
39
26
|
header_level += 1
|
40
27
|
%Q(<h#{header_level} class="livingstyleguide--#{klass}"#{id}>#{text}</h#{header_level}>\n)
|
@@ -48,16 +35,6 @@ module LivingStyleGuide
|
|
48
35
|
result << %Q(<li class="livingstyleguide--color-swatch $#{variable}">$#{variable}</li>\n)
|
49
36
|
end
|
50
37
|
result << "</ul>\n"
|
51
|
-
elsif text =~ /^\{\{font-example:(.+)\}\}$/
|
52
|
-
font = $1
|
53
|
-
<<-HTML.gsub(' ', '')
|
54
|
-
<div class="livingstyleguide--font-example" style="font: #{font}">
|
55
|
-
ABCDEFGHIJKLMNOPQRSTUVWXYZ<br>
|
56
|
-
abcdefghijklmnopqrstuvwxyz<br>
|
57
|
-
0123456789<br>
|
58
|
-
!&/()$=@;:,.
|
59
|
-
</div>
|
60
|
-
HTML
|
61
38
|
else
|
62
39
|
%Q(<p class="livingstyleguide--paragraph">#{text}</p>\n)
|
63
40
|
end
|
@@ -73,29 +50,11 @@ module LivingStyleGuide
|
|
73
50
|
end
|
74
51
|
|
75
52
|
def block_code(code, language)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
elsif %w(haml-example haml-layout-example).include?(language)
|
80
|
-
begin
|
81
|
-
type = language[5..-1]
|
82
|
-
require 'haml'
|
83
|
-
Haml::Options.defaults[:attr_wrapper] = '"'
|
84
|
-
haml = code.gsub(/\*\*\*(.+?)\*\*\*/m, '\\1')
|
85
|
-
html = Haml::Engine.new(haml).render.strip
|
86
|
-
%Q(<div class="livingstyleguide--#{type}">\n #{html}\n</div>) + "\n" + block_code(code, 'haml')
|
87
|
-
rescue LoadError
|
88
|
-
raise "Please make sure `gem 'haml'` is added to your Gemfile."
|
89
|
-
end
|
90
|
-
elsif %w(javascript-example).include?(language)
|
91
|
-
javascript = code.gsub(/\*\*\*(.+?)\*\*\*/m, '\\1')
|
92
|
-
%Q(<script>#{javascript}</script>\n) + block_code(code, 'javascript')
|
53
|
+
language ||= @options[:default_language]
|
54
|
+
if language == 'example'
|
55
|
+
Example.new(code, @options).render
|
93
56
|
else
|
94
|
-
|
95
|
-
code = ::MiniSyntax.highlight(code.strip, language.to_s.strip.to_sym)
|
96
|
-
code.gsub! /^\s*\*\*\*\n(.+?)\n\s*\*\*\*(\n|$)/m, %Q(<strong class="livingstyleguide--code-highlight-block">\\1</strong>)
|
97
|
-
code.gsub! /\*\*\*(.+?)\*\*\*/, %Q(<strong class="livingstyleguide--code-highlight">\\1</strong>)
|
98
|
-
%Q(<pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">#{code}</code></pre>)
|
57
|
+
CodeBlock.new(code.strip, language.to_s.strip.to_sym).render
|
99
58
|
end
|
100
59
|
end
|
101
60
|
|
@@ -104,8 +63,14 @@ module LivingStyleGuide
|
|
104
63
|
%Q(<code class="livingstyleguide--code-span livingstyleguide--code">#{code}</code>)
|
105
64
|
end
|
106
65
|
|
107
|
-
|
66
|
+
private
|
67
|
+
def slug(text)
|
68
|
+
require 'active_support/core_ext/string/inflections'
|
69
|
+
::ActiveSupport::Inflector.parameterize(text, '-')
|
70
|
+
rescue LoadError
|
71
|
+
text.downcase.gsub(/[ _\.\-!\?\(\)\[\]]+/, '-').gsub(/^-|-$/, '')
|
72
|
+
end
|
108
73
|
|
109
|
-
|
74
|
+
end
|
110
75
|
end
|
111
76
|
|
@@ -11,6 +11,7 @@ module ::Tilt
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def evaluate(scope, locals, &block)
|
14
|
+
@scope = scope
|
14
15
|
parse_options(data)
|
15
16
|
generate_sass
|
16
17
|
render_living_style_guide
|
@@ -25,11 +26,11 @@ module ::Tilt
|
|
25
26
|
options[:template_location].each do |path, short|
|
26
27
|
options[:load_paths] << ::LivingStyleGuide::Importer.new(path)
|
27
28
|
end
|
28
|
-
options[:filename]
|
29
|
-
options[:line]
|
30
|
-
options[:syntax]
|
31
|
-
options[:importer]
|
32
|
-
options[:
|
29
|
+
options[:filename] = eval_file
|
30
|
+
options[:line] = line
|
31
|
+
options[:syntax] = @options[:syntax]
|
32
|
+
options[:importer] = LivingStyleGuide::Importer.new('.')
|
33
|
+
options[:sprockets] = { context: @scope }
|
33
34
|
options
|
34
35
|
end
|
35
36
|
|
@@ -52,6 +53,26 @@ module ::Tilt
|
|
52
53
|
].flatten.join(@options[:syntax] == :sass ? "\n" : ';')
|
53
54
|
end
|
54
55
|
|
56
|
+
private
|
57
|
+
def configure_cache
|
58
|
+
return unless @scope.respond_to?(:depend_on)
|
59
|
+
test = /^#{root}/
|
60
|
+
@engine.files.uniq.each do |file|
|
61
|
+
if file =~ test
|
62
|
+
@scope.depend_on file
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def root
|
69
|
+
if @scope.respond_to?(:environment)
|
70
|
+
@scope.environment.root
|
71
|
+
else
|
72
|
+
File.dirname(@file)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
55
76
|
private
|
56
77
|
def style_variables
|
57
78
|
return unless @options.has_key?(:style)
|
@@ -62,8 +83,10 @@ module ::Tilt
|
|
62
83
|
|
63
84
|
private
|
64
85
|
def render_living_style_guide
|
65
|
-
engine = ::
|
66
|
-
engine.
|
86
|
+
@engine = ::LivingStyleGuide::Engine.new(@sass, @options, sass_options)
|
87
|
+
html = @engine.render
|
88
|
+
configure_cache
|
89
|
+
html
|
67
90
|
end
|
68
91
|
end
|
69
92
|
|
data/livingstyleguide.gemspec
CHANGED
@@ -22,9 +22,12 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_dependency 'sass'
|
23
23
|
gem.add_dependency 'redcarpet'
|
24
24
|
gem.add_dependency 'tilt'
|
25
|
-
gem.add_dependency 'activesupport'
|
26
25
|
gem.add_dependency 'thor'
|
26
|
+
gem.add_dependency 'hooks'
|
27
27
|
|
28
28
|
gem.add_development_dependency 'rake'
|
29
29
|
gem.add_development_dependency 'haml'
|
30
|
+
gem.add_development_dependency 'heredoc_unindent'
|
31
|
+
gem.add_development_dependency 'minitest'
|
32
|
+
gem.add_development_dependency 'coffee-script'
|
30
33
|
end
|
@@ -29,7 +29,7 @@ $livingstyleguide--border-radius: 0 !default;
|
|
29
29
|
$livingstyleguide--color: #505050 !default;
|
30
30
|
$livingstyleguide--width: 640px !default;
|
31
31
|
$livingstyleguide--gap-width: 10px !default;
|
32
|
-
$livingstyleguide--
|
32
|
+
$livingstyleguide--full-width-padding: $livingstyleguide--gap-width !default;
|
33
33
|
|
34
34
|
$livingstyleguide--code-background-color: #505050 !default;
|
35
35
|
$livingstyleguide--code-color: white !default;
|
@@ -62,17 +62,18 @@
|
|
62
62
|
@include box-sizing(border-box);
|
63
63
|
@include border-top-radius($livingstyleguide--border-radius);
|
64
64
|
|
65
|
-
|
65
|
+
&.-lsg-has-full-width {
|
66
|
+
@extend #{$livingstyleguide--layout-selector} !optional;
|
67
|
+
display: block;
|
68
|
+
height: auto;
|
66
69
|
margin: 0 auto;
|
70
|
+
min-height: auto;
|
71
|
+
padding: $livingstyleguide--full-width-padding;
|
67
72
|
width: 100%;
|
68
73
|
@include border-radius(0);
|
69
74
|
}
|
70
|
-
}
|
71
75
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
height: auto;
|
76
|
-
min-height: auto;
|
77
|
-
padding: $livingstyleguide--layout-example-padding;
|
76
|
+
&.-lsg-for-javascript {
|
77
|
+
display: none;
|
78
|
+
}
|
78
79
|
}
|
@@ -5,21 +5,21 @@
|
|
5
5
|
<meta charset="utf-8">
|
6
6
|
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
|
7
7
|
<meta content="The LivingStyleGuide Gem – http://livingstyleguide.org" name="generator">
|
8
|
-
<title><%= h(
|
8
|
+
<title><%= h(title) %></title>
|
9
9
|
<script>
|
10
10
|
// see: http://www.hagenburger.net/BLOG/Simple-HTML5-Fix-for-IE.html
|
11
11
|
for(var e,l='article aside footer header nav section time picture'.split(' ');e=l.pop();document.createElement(e));
|
12
12
|
</script>
|
13
13
|
<style>
|
14
|
-
<%=
|
14
|
+
<%= css %>
|
15
15
|
</style>
|
16
|
-
<%=
|
16
|
+
<%= head %>
|
17
17
|
</head>
|
18
18
|
|
19
19
|
<body class="livingstyleguide">
|
20
|
-
<%=
|
21
|
-
<%=
|
22
|
-
<%=
|
20
|
+
<%= header %>
|
21
|
+
<%= html %>
|
22
|
+
<%= footer %>
|
23
23
|
</body>
|
24
24
|
|
25
25
|
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ExampleTestCase < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@class = Class.new(LivingStyleGuide::Example)
|
7
|
+
end
|
8
|
+
|
9
|
+
def assert_render_equals(input, expected_output, options = nil)
|
10
|
+
options ||= LivingStyleGuide::Engine.default_options
|
11
|
+
output = @class.new(input.unindent, options).render
|
12
|
+
assert_equal(normalize(expected_output), normalize(output))
|
13
|
+
end
|
14
|
+
|
15
|
+
def assert_render_match(input, expected_output, options = nil)
|
16
|
+
options ||= LivingStyleGuide::Engine.default_options
|
17
|
+
output = @class.new(input.unindent, options).render
|
18
|
+
assert_match(/#{normalize(expected_output)}/, normalize(output))
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|