livingstyleguide 0.6.0.alpha.2 → 1.0.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c33ece860e06225991997ea016a1bb63296bcc80
4
- data.tar.gz: 5ce8ad16bad308ed0b874b27e7e2dd8de467f55f
3
+ metadata.gz: 7ab15e228a445c7b95dac21e5e7b08cd52ebbd65
4
+ data.tar.gz: 978c972a638c80ffb4e90179d31b0767656b0310
5
5
  SHA512:
6
- metadata.gz: 473fcd6e4a359e8f3246113a8b5c832408b1dde659038d55444c4fdf82da4d3cd32fc1943dc02b03a92885683a2d75e19b5328f0bd873add7c0dbb22c0e7077f
7
- data.tar.gz: de49cd6ffa45fd89f67d9e8c2f396237ba92f9091b352ee9eae3587e3e2ed57d86b7c6423385919f65d0311ee680ec4a9cd8d375974557865bfbe37f103d660e
6
+ metadata.gz: 50f4df04107e5f799d4599f73092227ad3cc145cc96d5ef23155d04785d841e415645adca2a982a5ccedaeac23557fb80b4fb5bf62e35c9a5d717d8a78ca7c61
7
+ data.tar.gz: 6b59104477eeaddf0a38e5876fc0c8e913f2fbeb4d453fa477aa239bff2ae235fcf1040addb0fbdbb87f35c95e89b45841571b34fee245f62f0e1acaa55cce5e
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 1.8.7
5
- - rbx-19mode
4
+ - 2.0.0
5
+ - 2.1.0
data/CHANGELOG.md CHANGED
@@ -36,4 +36,24 @@
36
36
 
37
37
  * Better support for load paths in Rails
38
38
  * Fix for colors
39
+ * New YAML based configuration
40
+ ([see this gist](https://gist.github.com/hagenburger/7945859#file-styleguide-1-html-lsg))
41
+ * Option to set the HTML title
42
+ * Custom footer and header HTML
43
+ ([example](https://github.com/hagenburger/livingstyleguide/blob/master/test/fixtures/standalone/styleguide-with-header-footer.html.lsg))
44
+ * Linking of JavaScript files (like jQuery, application.js, …) into the
45
+ style guide
46
+ ([example](https://github.com/hagenburger/livingstyleguide/blob/master/test/fixtures/standalone/styleguide-with-javascript.html.lsg))
47
+ * Custom styles can be set within YAML configuration
48
+ ([example](https://github.com/hagenburger/livingstyleguide/blob/master/test/fixtures/standalone/styleguide-with-style.html.lsg))
49
+
50
+ ## 1.0.0.alpha.3
51
+
52
+ * [Cache control for Sprockets](https://github.com/hagenburger/livingstyleguide/issues/25)
53
+ * API to provide [filters in examples](https://github.com/hagenburger/livingstyleguide/issues/22)
54
+ * Dropped `haml-example`, `layout-example`, `javascript-example` and `haml-layout-example`;
55
+ moved into [filters](https://github.com/hagenburger/livingstyleguide/issues/28)
56
+ * [A set of pre-defined filters](https://github.com/hagenburger/livingstyleguide/tree/master/lib/livingstyleguide/filters)
57
+ * [Default filters](https://github.com/hagenburger/livingstyleguide/issues/31) (e. g. all templates should use Haml)
58
+ * [CoffeeScript examples](https://github.com/hagenburger/livingstyleguide/issues/34)
39
59
 
data/MIT-LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2012++ Nico Hagenburger
2
+
3
+ http://www.hagenburger.net
4
+ http://twitter.com/hagenburger
5
+ http://github.com/hagenburger
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,12 +1,44 @@
1
1
  # Living Style Guide
2
2
 
3
- TODO: Write a gem description
3
+ Easily create living style guides by adding Markdown documentation to
4
+ your Sass.
5
+
6
+ ![Build Status Images](https://travis-ci.org/hagenburger/livingstyleguide.png)
7
+
8
+ ## Rails Integration
9
+
10
+ 1) Create *_app/assets/stylesheets/styleguide.html.lsg_* with:
11
+ ``` yaml
12
+ source: application.css.scss # replace with your default Sass/SCSS file name
13
+ title: "My Living Style Guide"
14
+ ```
15
+
16
+ 2) Write documentation for each module *app/assets/stylesheets/partials/_buttons.md* (to describe *_buttons.sass* in the same folder):
17
+ ``` markdown
18
+ Buttons
19
+ =======
20
+
21
+ ~~~ example
22
+ <button class="button">Example button</button>
23
+ ~~~ 
24
+
25
+ ~~~ example
26
+ <button class="button -is-primary">Example button</button>
27
+ ~~~ 
28
+ ```
29
+
30
+ 3) Open <http://localhost:3000/assets/styleguide.html>.
31
+ This will automatically:
32
+ * Combine all Markdown files and convert them to HTML
33
+ * Create a beautyful style guide
34
+ * Show the HTML source syntax highlighted close to each example
35
+
4
36
 
5
37
  ## Installation
6
38
 
7
39
  Add this line to your application's Gemfile:
8
40
 
9
- gem 'livingstyleguide'
41
+ gem 'livingstyleguide', '0.6.0.alpha.2'
10
42
 
11
43
  And then execute:
12
44
 
@@ -14,11 +46,8 @@ And then execute:
14
46
 
15
47
  Or install it yourself as:
16
48
 
17
- $ gem install livingstyleguide
49
+ $ gem install livingstyleguide -v0.6.0.alpha.2
18
50
 
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
51
 
23
52
  ## Contributing
24
53
 
@@ -27,3 +56,12 @@ TODO: Write usage instructions here
27
56
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
57
  4. Push to the branch (`git push origin my-new-feature`)
29
58
  5. Create new Pull Request
59
+
60
+
61
+ ## Copyright
62
+
63
+ Copyright (c) 2012 – 2014 [Nico Hagenburger](http://www.hagenburger.net).
64
+ See [MIT-LICENSE.md](MIT-LICENSE.md) for details.
65
+ Get in touch with [@hagenburger](http://twitter.com/hagenburger) on Twitter.
66
+
67
+
@@ -1,38 +1,17 @@
1
1
  require 'livingstyleguide/version'
2
2
  require 'compass'
3
+ require 'livingstyleguide/filter_hooks'
3
4
  require 'livingstyleguide/sass_extensions'
5
+ require 'livingstyleguide/engine'
4
6
  require 'livingstyleguide/variables_importer'
5
7
  require 'livingstyleguide/importer'
6
- require 'livingstyleguide/renderer'
7
8
  require 'livingstyleguide/markdown_extensions'
8
9
  require 'livingstyleguide/tilt_template'
10
+ require 'livingstyleguide/code_block'
11
+ require 'livingstyleguide/example'
12
+ require 'livingstyleguide/filters'
13
+ require 'livingstyleguide/integration'
9
14
 
10
15
  module LivingStyleGuide
11
- @@markdown = nil
12
-
13
- def self.reset
14
- @@markdown = nil
15
- end
16
-
17
- def self.add_markdown(markdown)
18
- (@@markdown ||= '') << markdown
19
- end
20
-
21
- def self.markdown
22
- @@markdown
23
- end
24
-
25
16
  end
26
17
 
27
- class Sass::Engine
28
- include LivingStyleGuide::Renderer
29
- end
30
-
31
- class String
32
- def blank?
33
- self.nil? || self.empty?
34
- end
35
- end
36
-
37
- require 'livingstyleguide/integration'
38
-
@@ -0,0 +1,35 @@
1
+ require 'minisyntax'
2
+ require 'erb'
3
+ require 'hooks'
4
+
5
+ class LivingStyleGuide::CodeBlock
6
+ include Hooks
7
+ include Hooks::InstanceHooks
8
+ include LivingStyleGuide::FilterHooks
9
+ define_hooks :filter_code, :syntax_highlight
10
+
11
+ attr_accessor :source, :language
12
+
13
+ syntax_highlight do |code|
14
+ if language.nil?
15
+ code
16
+ else
17
+ ::MiniSyntax.highlight(code, language)
18
+ end
19
+ end
20
+
21
+ def initialize(source, language = nil)
22
+ @source = source
23
+ @language = language
24
+ end
25
+
26
+ def render
27
+ code = @source.strip
28
+ code = ERB::Util.html_escape(code).gsub(/&quot;/, '"')
29
+ code = run_last_filter_hook(:syntax_highlight, code)
30
+ code = run_filter_hook(:filter_code, code)
31
+ %Q(<pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">#{code}</code></pre>)
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,93 @@
1
+ module LivingStyleGuide
2
+
3
+ class Engine
4
+ attr_accessor :markdown, :files, :options
5
+
6
+ @@default_options = {
7
+ default_language: 'example'
8
+ }
9
+
10
+ def self.default_options
11
+ @@default_options
12
+ end
13
+
14
+ def initialize(source, options, sass_options)
15
+ @source = source
16
+ @options = @@default_options.merge(options)
17
+ @sass_options = sass_options
18
+ @markdown = ''
19
+ @files = []
20
+ end
21
+
22
+ def render
23
+ data = TemplateData.new(self)
24
+ template = File.read(File.join(File.dirname(__FILE__), '..', '..', 'templates', 'layouts', 'default.html.erb'))
25
+ ERB.new(template).result(data.get_binding)
26
+ end
27
+
28
+ def css
29
+ sass_engine.render
30
+ end
31
+
32
+ def html
33
+ renderer = RedcarpetHTML.new(@options)
34
+ redcarpet = ::Redcarpet::Markdown.new(renderer, REDCARPET_RENDER_OPTIONS)
35
+ redcarpet.render(markdown)
36
+ end
37
+
38
+ private
39
+ def sass_engine
40
+ return @sass_engine if @sass_engine
41
+ sass_options = @sass_options.clone
42
+ sass_options[:living_style_guide] = self
43
+ @sass_engine = ::Sass::Engine.new(@source, sass_options)
44
+ end
45
+
46
+ end
47
+
48
+ class TemplateData
49
+ include ERB::Util
50
+
51
+ def initialize(engine)
52
+ @engine = engine
53
+ end
54
+
55
+ def get_binding
56
+ binding
57
+ end
58
+
59
+ def title
60
+ @engine.options[:title]
61
+ end
62
+
63
+ def css
64
+ @engine.css
65
+ end
66
+
67
+ def html
68
+ @engine.html
69
+ end
70
+
71
+ def head
72
+ (@engine.options[:javascript_before] || []).map do |src|
73
+ %Q(<script src="#{src}"></script>)
74
+ end.join("\n")
75
+ end
76
+
77
+ def header
78
+ contents = [@engine.options[:header]]
79
+ contents.join("\n")
80
+ end
81
+
82
+ def footer
83
+ contents = [@engine.options[:footer]]
84
+ contents << (@engine.options[:javascript_after] || []).map do |src|
85
+ %Q(<script src="#{src}"></script>)
86
+ end
87
+ contents.join("\n")
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,86 @@
1
+ require 'minisyntax'
2
+ require 'erb'
3
+ require 'hooks'
4
+
5
+ class LivingStyleGuide::Example
6
+ include Hooks
7
+ include Hooks::InstanceHooks
8
+ include LivingStyleGuide::FilterHooks
9
+
10
+ FILTER_REGEXP = /^@([a-z\-_]+)(\s+(.+?))?$/
11
+
12
+ define_hooks :filter_before, :filter_after, :html, :pre_processor
13
+ attr_reader :options
14
+ @@filters = {}
15
+
16
+ def initialize(input, options = {})
17
+ @options = { default_filters: [] }.merge(options)
18
+ @source = input
19
+ @wrapper_classes = %w(livingstyleguide--example)
20
+ @syntax = :html
21
+ @filters = @options[:default_filters].clone
22
+ @output_code_block = true
23
+ parse_filters
24
+ apply_filters
25
+ end
26
+
27
+ html do |content|
28
+ %Q(<div class="#{wrapper_classes}">\n #{content}\n</div>\n)
29
+ end
30
+
31
+ def render
32
+ html = run_last_filter_hook(:html, filtered_example)
33
+ code_block = LivingStyleGuide::CodeBlock.new(@source, @syntax).render if @output_code_block
34
+ "#{html}#{code_block}"
35
+ end
36
+
37
+ def self.add_filter(key = nil, &block)
38
+ if key
39
+ @@filters[key.to_sym] = block
40
+ else
41
+ instance_eval &block
42
+ end
43
+ end
44
+
45
+ def add_wrapper_class(class_name)
46
+ @wrapper_classes << class_name
47
+ end
48
+
49
+ def wrapper_classes
50
+ @wrapper_classes.join(' ')
51
+ end
52
+
53
+ def suppress_code_block
54
+ @output_code_block = false
55
+ end
56
+
57
+ private
58
+ def parse_filters
59
+ lines = @source.split(/\n/)
60
+ @source = lines.reject do |line|
61
+ if line =~ FILTER_REGEXP
62
+ @filters << line
63
+ end
64
+ end.join("\n")
65
+ end
66
+
67
+ private
68
+ def apply_filters
69
+ @filters.each do |filter|
70
+ set_filter *filter.match(FILTER_REGEXP)[1..2]
71
+ end
72
+ end
73
+
74
+ private
75
+ def set_filter(key, argument = nil)
76
+ instance_exec argument, &@@filters[key.to_s.gsub('-', '_').to_sym]
77
+ end
78
+
79
+ private
80
+ def filtered_example
81
+ source = run_filter_hook(:filter_before, @source)
82
+ source = run_last_filter_hook(:pre_processor, source)
83
+ run_filter_hook(:filter_after, source)
84
+ end
85
+ end
86
+
@@ -0,0 +1,34 @@
1
+ module LivingStyleGuide::FilterHooks
2
+ def self.included(base)
3
+ base.class_eval do
4
+ extend Methods
5
+ include Methods
6
+ end
7
+ end
8
+
9
+ module Methods
10
+ def run_filter_hook(name, source)
11
+ _hooks[name].each do |hook|
12
+ source = run_single_hook(hook, source)
13
+ end
14
+ source
15
+ end
16
+
17
+ def run_last_filter_hook(name, source)
18
+ run_single_hook(_hooks[name].last, source)
19
+ end
20
+
21
+ private
22
+ def run_single_hook(hook, source)
23
+ if hook.kind_of?(Symbol)
24
+ send(hook, source)
25
+ elsif hook.nil?
26
+ source
27
+ else
28
+ instance_exec(source, &hook)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+
@@ -0,0 +1,8 @@
1
+ require 'livingstyleguide/filters/highlights'
2
+ require 'livingstyleguide/filters/full_width'
3
+ require 'livingstyleguide/filters/haml'
4
+ require 'livingstyleguide/filters/javascript'
5
+ require 'livingstyleguide/filters/coffee_script'
6
+ require 'livingstyleguide/filters/add_wrapper_class'
7
+ require 'livingstyleguide/filters/font_example'
8
+
@@ -0,0 +1,4 @@
1
+ LivingStyleGuide::Example.add_filter :add_wrapper_class do |css_class|
2
+ add_wrapper_class css_class
3
+ end
4
+