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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.md +20 -0
  4. data/MIT-LICENSE.md +11 -0
  5. data/README.md +44 -6
  6. data/lib/livingstyleguide.rb +6 -27
  7. data/lib/livingstyleguide/code_block.rb +35 -0
  8. data/lib/livingstyleguide/engine.rb +93 -0
  9. data/lib/livingstyleguide/example.rb +86 -0
  10. data/lib/livingstyleguide/filter_hooks.rb +34 -0
  11. data/lib/livingstyleguide/filters.rb +8 -0
  12. data/lib/livingstyleguide/filters/add_wrapper_class.rb +4 -0
  13. data/lib/livingstyleguide/filters/coffee_script.rb +18 -0
  14. data/lib/livingstyleguide/filters/font_example.rb +20 -0
  15. data/lib/livingstyleguide/filters/full_width.rb +4 -0
  16. data/lib/livingstyleguide/filters/haml.rb +16 -0
  17. data/lib/livingstyleguide/filters/highlights.rb +9 -0
  18. data/lib/livingstyleguide/filters/javascript.rb +10 -0
  19. data/lib/livingstyleguide/importer.rb +19 -6
  20. data/lib/livingstyleguide/markdown_extensions.rb +24 -59
  21. data/lib/livingstyleguide/tilt_template.rb +30 -7
  22. data/lib/livingstyleguide/version.rb +1 -1
  23. data/livingstyleguide.gemspec +4 -1
  24. data/stylesheets/_livingstyleguide.scss +1 -1
  25. data/stylesheets/livingstyleguide/_content.scss +9 -8
  26. data/templates/layouts/default.html.erb +6 -6
  27. data/test/example_test_helper.rb +22 -0
  28. data/test/fixtures/markdown/code-block-and-example.md +8 -0
  29. data/test/fixtures/markdown/example-with-highlight.md +1 -1
  30. data/test/fixtures/markdown/example.md +1 -1
  31. data/test/fixtures/markdown/font-example.md +4 -1
  32. data/test/fixtures/markdown/{layout-example.md → full-width-example.md} +2 -1
  33. data/test/fixtures/markdown/haml-example-with-highlight.md +2 -1
  34. data/test/fixtures/markdown/haml-example.md +2 -1
  35. data/test/fixtures/standalone/modules/_buttons.md +1 -1
  36. data/test/integration/markdown_test.rb +17 -14
  37. data/test/integration/sprockets_test.rb +19 -0
  38. data/test/integration/standalone_test.rb +1 -1
  39. data/test/integration/variables_test.rb +1 -1
  40. data/test/test_helper.rb +9 -1
  41. data/test/unit/code_block_test.rb +53 -0
  42. data/test/unit/example_test.rb +142 -0
  43. data/test/unit/filter_hooks_test.rb +46 -0
  44. data/test/unit/filters/add_wrapper_class_test.rb +15 -0
  45. data/test/unit/filters/coffee_script_test.rb +19 -0
  46. data/test/unit/filters/font_example_test.rb +47 -0
  47. data/test/unit/filters/full_width_test.rb +16 -0
  48. data/test/unit/filters/haml_test.rb +20 -0
  49. data/test/unit/filters/highlights_test.rb +26 -0
  50. data/test/unit/filters/javascript_test.rb +18 -0
  51. data/test/unit/sass_extensions_test.rb +1 -1
  52. metadata +87 -10
  53. data/LICENSE.txt +0 -22
  54. data/lib/livingstyleguide/renderer.rb +0 -36
  55. data/test/fixtures/markdown/javascript-example.md +0 -4
@@ -1 +1,4 @@
1
- {{font-example:16px Courier}}
1
+ ~~~
2
+ @font-example 16px Courier
3
+ ~~~
4
+
@@ -1,4 +1,5 @@
1
- ~~~ layout-example
1
+ ~~~
2
+ @full-width
2
3
  <button class="button">Test</button>
3
4
  ~~~
4
5
 
@@ -1,4 +1,5 @@
1
- ~~~ haml-example
1
+ ~~~
2
+ @haml
2
3
  %button***.button*** Test
3
4
  ~~~
4
5
 
@@ -1,4 +1,5 @@
1
- ~~~ haml-example
1
+ ~~~
2
+ @haml
2
3
  %button.button Test
3
4
  ~~~
4
5
 
@@ -1,6 +1,6 @@
1
1
  # Buttons
2
2
 
3
- ~~~ example
3
+ ~~~
4
4
  <button class="button">A button</button>
5
5
  ~~~
6
6
 
@@ -1,16 +1,17 @@
1
1
  require 'test_helper'
2
2
  require 'tilt'
3
3
 
4
- class MarkdownTest < Test::Unit::TestCase
4
+ class MarkdownTest < Minitest::Test
5
5
 
6
- def render(file)
7
- template = Tilt.new(file)
8
- template.render
6
+ def render_markdown(file, options)
7
+ engine = LivingStyleGuide::Engine.new('', options, {})
8
+ engine.markdown = File.read(file)
9
+ engine.html
9
10
  end
10
11
 
11
- def assert_markdown(expected, file)
12
+ def assert_markdown(expected, file, options = {})
12
13
  expected = expected.gsub(/\s+/m, ' ').gsub(/([\$\(\)\[\]])/) { |s| "\\#{s}" }.strip
13
- given = render(File.join(%W(test fixtures markdown #{file})))
14
+ given = render_markdown(File.join(%W(test fixtures markdown #{file})), options)
14
15
  given = given.gsub(/\s+/m, ' ').strip
15
16
  assert_match /#{expected}/, given
16
17
  end
@@ -24,9 +25,9 @@ class MarkdownTest < Test::Unit::TestCase
24
25
  HTML
25
26
  end
26
27
 
27
- def test_layout_examples
28
- assert_markdown <<-HTML, 'layout-example.md'
29
- <div class="livingstyleguide--layout-example">
28
+ def test_full_width_examples
29
+ assert_markdown <<-HTML, 'full-width-example.md'
30
+ <div class="livingstyleguide--example -lsg-has-full-width">
30
31
  <button class="button">Test</button>
31
32
  </div>
32
33
  <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">.+button.+Test.+button.+</code></pre>
@@ -88,7 +89,7 @@ class MarkdownTest < Test::Unit::TestCase
88
89
 
89
90
  def test_code_with_highlight_block
90
91
  assert_markdown <<-HTML, 'code-with-highlight-block.md'
91
- <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><strong class="livingstyleguide--code-highlight-block">.+Block example.+</strong></code></pre>
92
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">.+<strong class="livingstyleguide--code-highlight-block">.+Block example.+</strong>.+</code></pre>
92
93
  HTML
93
94
  end
94
95
 
@@ -123,10 +124,12 @@ class MarkdownTest < Test::Unit::TestCase
123
124
  HTML
124
125
  end
125
126
 
126
- def test_javascript_example
127
- assert_markdown <<-HTML, 'javascript-example.md'
128
- <script>alert("Hello world!"); </script>
129
- <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">alert(<q>"<b>Hello</b> world!"</q>);</code></pre>
127
+ def test_resetting_language
128
+ assert_markdown <<-HTML, 'code-block-and-example.md', default_language: 'code'
129
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">Normal code block</code></pre><div class="livingstyleguide--example">
130
+ Example
131
+ </div>
132
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">Example</code></pre>
130
133
  HTML
131
134
  end
132
135
 
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'tilt'
3
+
4
+ describe "Sprockets integration" do
5
+
6
+ describe "sprockets should know when to invalidate cache" do
7
+ template = Tilt.new('test/fixtures/standalone/styleguide.html.lsg')
8
+ context = Minitest::Mock.new
9
+ %w(style.scss modules/_buttons.scss modules/_buttons.md styleguide.html.lsg).each do |file|
10
+ context.expect :depend_on, nil, ["test/fixtures/standalone/#{file}"]
11
+ end
12
+
13
+ template.render context
14
+
15
+ context.verify
16
+ end
17
+
18
+ end
19
+
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'tilt'
3
3
 
4
- class MarkdownTest < Test::Unit::TestCase
4
+ class MarkdownTest < Minitest::Test
5
5
 
6
6
  def test_standalone_project
7
7
  html = render('test/fixtures/standalone/styleguide.html.lsg')
@@ -4,7 +4,7 @@ require 'compass'
4
4
  require 'compass/logger'
5
5
  require 'sass/plugin'
6
6
 
7
- class VariablesImporterTest < Test::Unit::TestCase
7
+ class VariablesImporterTest < Minitest::Test
8
8
 
9
9
  def setup
10
10
  Compass.configure_sass_plugin!
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
+ require 'minitest/autorun'
1
2
  require 'compass'
2
3
  require 'livingstyleguide'
3
- require 'test/unit'
4
+ require 'heredoc_unindent'
4
5
 
5
6
  Compass.configuration.add_import_path File.join(%w(test fixtures stylesheets))
6
7
 
@@ -18,3 +19,10 @@ def parse_file(filename)
18
19
  Sass::Engine.new(File.read(filename), options)
19
20
  end
20
21
 
22
+ def normalize(html)
23
+ html.gsub! /\s+/, ' '
24
+ html.gsub! '><', '> <'
25
+ html.strip!
26
+ html
27
+ end
28
+
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ describe LivingStyleGuide::CodeBlock do
4
+
5
+ before do
6
+ @code_block = Class.new(LivingStyleGuide::CodeBlock)
7
+ end
8
+
9
+ describe "when no language is given" do
10
+ it "should output the code" do
11
+ @code_block.new("My Code").render.must_equal <<-HTML.unindent.strip
12
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">My Code</code></pre>
13
+ HTML
14
+ end
15
+
16
+ it "should html escape the code" do
17
+ @code_block.new("1 < 2 > 0 &\"").render.must_equal <<-HTML.unindent.strip
18
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">1 &lt; 2 &gt; 0 &amp;"</code></pre>
19
+ HTML
20
+ end
21
+ end
22
+
23
+ describe "when a language is given" do
24
+ it "should output the code with syntax highlighting" do
25
+ @code_block.new("<my-code>", :html).render.must_equal <<-HTML.unindent.strip
26
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><b>&lt;<em>my-code</em></b><b>&gt;</b></code></pre>
27
+ HTML
28
+ end
29
+ end
30
+
31
+ describe "when filters are set" do
32
+ it "should filter the code" do
33
+ @code_block.filter_code do |code|
34
+ code.gsub(/ugly/, 'beautiful')
35
+ end
36
+
37
+ @code_block.new("my ugly code").render.must_equal <<-HTML.unindent.strip
38
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">my beautiful code</code></pre>
39
+ HTML
40
+ end
41
+
42
+ it "should use own syntax highlighter" do
43
+ @code_block.syntax_highlight do |code|
44
+ code.gsub(/language/, language)
45
+ end
46
+
47
+ @code_block.new("my ugly language code", "html").render.must_equal <<-HTML.unindent.strip
48
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">my ugly html code</code></pre>
49
+ HTML
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,142 @@
1
+ require 'example_test_helper'
2
+
3
+ class ExampleTest < ExampleTestCase
4
+
5
+ def test_default
6
+ assert_render_equals <<-INPUT, <<-OUTPUT
7
+ <button>Hello World</button>
8
+ INPUT
9
+ <div class="livingstyleguide--example"> <button>Hello World</button> </div>
10
+ <pre class="livingstyleguide--code-block">
11
+ <code class="livingstyleguide--code">
12
+ <b>&lt;<em>button</em></b><b>&gt;</b>Hello World<b>&lt;/<em>button</em>&gt</b>
13
+ </code>
14
+ </pre>
15
+ OUTPUT
16
+ end
17
+
18
+ def test_filters_with_underscore_and_dash_case
19
+ @class.add_filter :test_filter do
20
+ filter_before do |html|
21
+ "TEST"
22
+ end
23
+ end
24
+ %w(test_filter test-filter).each do |filter|
25
+ assert_render_equals <<-INPUT, <<-OUTPUT
26
+ @#{filter}
27
+ <button>Hello World</button>
28
+ INPUT
29
+ <div class="livingstyleguide--example"> TEST </div>
30
+ <pre class="livingstyleguide--code-block">
31
+ <code class="livingstyleguide--code">
32
+ <b>&lt;<em>button</em></b><b>&gt;</b>Hello World<b>&lt;/<em>button</em>&gt</b>
33
+ </code>
34
+ </pre>
35
+ OUTPUT
36
+ end
37
+ end
38
+
39
+ def test_filters
40
+ @class.add_filter do
41
+ filter_before do |html|
42
+ "TEST"
43
+ end
44
+ end
45
+ assert_render_equals <<-INPUT, <<-OUTPUT
46
+ <button>Hello World</button>
47
+ INPUT
48
+ <div class="livingstyleguide--example"> TEST </div>
49
+ <pre class="livingstyleguide--code-block">
50
+ <code class="livingstyleguide--code">
51
+ <b>&lt;<em>button</em></b><b>&gt;</b>Hello World<b>&lt;/<em>button</em>&gt</b>
52
+ </code>
53
+ </pre>
54
+ OUTPUT
55
+ end
56
+
57
+ def test_filters_with_argument
58
+ @class.add_filter :test_filter do |argument|
59
+ filter_before do |html|
60
+ argument
61
+ end
62
+ end
63
+ assert_render_equals <<-INPUT, <<-OUTPUT
64
+ @test_filter Another Test
65
+ <button>Hello World</button>
66
+ INPUT
67
+ <div class="livingstyleguide--example"> Another Test </div>
68
+ <pre class="livingstyleguide--code-block">
69
+ <code class="livingstyleguide--code">
70
+ <b>&lt;<em>button</em></b><b>&gt;</b>Hello World<b>&lt;/<em>button</em>&gt</b>
71
+ </code>
72
+ </pre>
73
+ OUTPUT
74
+ end
75
+
76
+ def test_default_filters
77
+ @class.add_filter :test_filter do
78
+ filter_before do |html|
79
+ "TEST"
80
+ end
81
+ end
82
+ assert_render_equals <<-INPUT, <<-OUTPUT, { default_filters: ['@test-filter'] }
83
+ <button>Hello World</button>
84
+ INPUT
85
+ <div class="livingstyleguide--example"> TEST </div>
86
+ <pre class="livingstyleguide--code-block">
87
+ <code class="livingstyleguide--code">
88
+ <b>&lt;<em>button</em></b><b>&gt;</b>Hello World<b>&lt;/<em>button</em>&gt</b>
89
+ </code>
90
+ </pre>
91
+ OUTPUT
92
+ end
93
+
94
+ def test_outer_html
95
+ @class.html do |c|
96
+ "<span>#{c}</span>"
97
+ end
98
+ assert_render_equals <<-INPUT, <<-OUTPUT
99
+ <button>Hello World</button>
100
+ INPUT
101
+ <span> <button>Hello World</button> </span>
102
+ <pre class="livingstyleguide--code-block">
103
+ <code class="livingstyleguide--code">
104
+ <b>&lt;<em>button</em></b><b>&gt;</b>Hello World<b>&lt;/<em>button</em>&gt</b>
105
+ </code>
106
+ </pre>
107
+ OUTPUT
108
+ end
109
+
110
+ def test_hide_code_block
111
+ @class.add_filter :suppress_code_block do
112
+ suppress_code_block
113
+ end
114
+ assert_render_equals <<-INPUT, <<-OUTPUT
115
+ @suppress-code-block
116
+ <button>Hello World</button>
117
+ INPUT
118
+ <div class="livingstyleguide--example"> <button>Hello World</button> </div>
119
+ OUTPUT
120
+ end
121
+
122
+ def test_pre_processor
123
+ @class.add_filter :pre_processor_one do
124
+ pre_processor { |source| 'fail' }
125
+ end
126
+ @class.add_filter :pre_processor_two do
127
+ pre_processor { |source| source.gsub(/World/, 'Moon') }
128
+ end
129
+ assert_render_equals <<-INPUT, <<-OUTPUT
130
+ @pre-processor-one
131
+ @pre-processor-two
132
+ Hello World
133
+ INPUT
134
+ <div class="livingstyleguide--example"> Hello Moon </div>
135
+ <pre class="livingstyleguide--code-block">
136
+ <code class="livingstyleguide--code">Hello World</code>
137
+ </pre>
138
+ OUTPUT
139
+ end
140
+
141
+ end
142
+
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ describe LivingStyleGuide::FilterHooks do
4
+
5
+ before do
6
+ @class = Class.new
7
+ @class.class_eval do
8
+ include Hooks
9
+ include Hooks::InstanceHooks
10
+ include LivingStyleGuide::FilterHooks
11
+ define_hook :filter
12
+ end
13
+ end
14
+
15
+ describe "running filters after each other" do
16
+ it "should filter one filter" do
17
+ @class.filter { |text| text * 2 }
18
+ @class.run_filter_hook(:filter, "hello world").must_equal "hello worldhello world"
19
+ end
20
+
21
+ it "should filter several filter in a row" do
22
+ @class.filter { |text| text * 2 }
23
+ @class.filter { |text| text.gsub(/worldhello/, 'beautiful') }
24
+ @class.run_filter_hook(:filter, "hello world").must_equal "hello beautiful world"
25
+ end
26
+
27
+ it "should work on instances" do
28
+ @class.filter { |text| text * 2 }
29
+ @class.new.run_filter_hook(:filter, "hello world").must_equal "hello worldhello world"
30
+ end
31
+ end
32
+
33
+ describe "run only the latest added filter" do
34
+ it "should should run only one filter" do
35
+ @class.filter { |text| text.gsub(/animal/, 'fish') }
36
+ @class.filter { |text| text.gsub(/animal/, 'bird') }
37
+ @class.run_last_filter_hook(:filter, "the animal").must_equal "the bird"
38
+ end
39
+
40
+ it "should return the original string if no hooks are defined" do
41
+ @class.run_last_filter_hook(:filter, "the animal").must_equal "the animal"
42
+ end
43
+ end
44
+
45
+ end
46
+
@@ -0,0 +1,15 @@
1
+ require 'example_test_helper'
2
+
3
+ class AddWrapperClassTest < ExampleTestCase
4
+
5
+ def test_add_wrapper_class
6
+ assert_render_match <<-INPUT, <<-OUTPUT
7
+ @add-wrapper-class my-class
8
+ <section>Something wide</section>
9
+ INPUT
10
+ <div class="livingstyleguide--example my-class">
11
+ OUTPUT
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,19 @@
1
+ require 'example_test_helper'
2
+
3
+ class CoffeeScriptTest < ExampleTestCase
4
+
5
+ def test_coffee_script
6
+ assert_render_equals <<-INPUT, <<-OUTPUT
7
+ @coffee-script
8
+ alert "Hello world!"
9
+ INPUT
10
+ <div class="livingstyleguide--example -lsg-for-javascript"> <script>(function() { alert("Hello world!"); }).call(this); </script> </div>
11
+ <pre class="livingstyleguide--code-block">
12
+ <code class="livingstyleguide--code">alert "Hello world!"</code>
13
+ </pre>
14
+ OUTPUT
15
+ end
16
+
17
+ end
18
+
19
+