livingstyleguide 2.0.0.alpha.1 → 2.0.0.alpha.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a49c1cde2fda30398815711988fe1e027bce952a
4
- data.tar.gz: f1dfdca1b72c4ff39fbfa139f443528d5797d524
3
+ metadata.gz: 97dd9be7998179472959f4e7960605b573e36fa1
4
+ data.tar.gz: 29cc7df7aa57af22558c1dba29eac0fe5d335337
5
5
  SHA512:
6
- metadata.gz: b7a55067c4098eb7ba738970330e3a5d250771c2836dfcfef23a005bf68b6ba17a5cec64a970a929cf7641cc4a89c8324a5875a5c906b3a59c68f5add6e393b5
7
- data.tar.gz: d3774e206d621568b6ebb96cfafdbe2379ed1fe26ff6607e4feaf3db396df1bc3bda1a5e4409ee0c10bb1fa465fefe4e6ce793de057135fdd51c21a77303b10d
6
+ metadata.gz: 31aec84356a0b49da04a65d92dbbf6358f520f173528ed95f9cc755362f280ca3efb6311be04672776fa24acdc011c0498ce4122d9340b9d73f840dea2871937
7
+ data.tar.gz: 5e685372e9cc6d331e6164c4a8738b0de7b4e6a6357079ba36a64282afd80275dc2522bc68710fa352980ea4dde892e7fcf3728ece11ada5ffe94b16e2dc3934
data/bin/livingstyleguide CHANGED
@@ -1,7 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'livingstyleguide'))
4
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'livingstyleguide', 'command_line_interface'))
3
+ require 'rubygems'
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ end
8
+
9
+ lib = File.expand_path('../lib', File.dirname(__FILE__))
10
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
11
+
12
+ require 'livingstyleguide'
13
+ require 'livingstyleguide/command_line_interface'
5
14
 
6
15
  LivingStyleGuide::CommandLineInterface.start(ARGV)
7
16
 
@@ -7,19 +7,25 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  module LivingStyleGuide
10
+ @@default_options = {
11
+ default_language: :example,
12
+ title: 'Living Style Guide',
13
+ header: '<h1 class="livingstyleguide--page-title">Living Style Guide</h1>',
14
+ footer: '<div class="livingstyleguide--footer"><a class="livingstyleguide--logo" href="http://livingstyleguide.org">Made with the LivingStyleGuide gem.</a></div>',
15
+ root: '/'
16
+ }
17
+
18
+ def self.default_options
19
+ @@default_options
20
+ end
21
+
10
22
  def self.add_filter(*keys, &block)
11
23
  Filters.add_filter(*keys, &block)
12
24
  end
13
25
  end
14
26
 
15
27
  require 'livingstyleguide/version'
16
- require 'livingstyleguide/filter_hooks'
17
- require 'livingstyleguide/sass_extensions'
18
- require 'livingstyleguide/engine'
19
28
  require 'livingstyleguide/markdown_extensions'
20
- require 'livingstyleguide/tilt_template'
21
- require 'livingstyleguide/code_block'
22
- require 'livingstyleguide/example'
23
29
  require 'livingstyleguide/document'
24
30
  require 'livingstyleguide/filters'
25
31
  require 'livingstyleguide/integration'
@@ -1,8 +1,3 @@
1
- require 'rubygems'
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- end
6
1
  require 'thor'
7
2
  require 'tilt'
8
3
 
@@ -11,10 +6,10 @@ module LivingStyleGuide
11
6
 
12
7
  desc 'compile input_file output_file', 'Compiles the living style guide to HTML.'
13
8
  def compile(input_file = nil, output_file = nil)
14
- template = LivingStyleGuide::TiltTemplate.new(input_file) do
9
+ doc = LivingStyleGuide::Document.new(input_file) do
15
10
  input(input_file)
16
11
  end
17
- output template.render, input_file, output_file
12
+ output doc.render, input_file, output_file
18
13
  end
19
14
 
20
15
  desc 'version', 'Shows the current version of the Gem'
@@ -39,7 +39,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
39
39
  end
40
40
 
41
41
  def source
42
- @source ||= erb.gsub(/<%.*?%>\n?/, '')
42
+ @source ||= set_highlights(@erb.gsub(/<%.*?%>\n?/, ''))
43
43
  end
44
44
 
45
45
  def css
@@ -65,15 +65,15 @@ class LivingStyleGuide::Document < ::Tilt::Template
65
65
  depend_on file if file and options.has_key?(:livingstyleguide)
66
66
  result = ERB.new(erb).result(@filters.get_binding)
67
67
  @html = case @type
68
- when :plain, :example
69
- result
68
+ when :plain, :example, :html, :javascript
69
+ remove_highlights(result)
70
70
  when :markdown
71
- renderer = LivingStyleGuide::RedcarpetHTML.new(LivingStyleGuide::Engine.default_options, self)
71
+ renderer = LivingStyleGuide::RedcarpetHTML.new(LivingStyleGuide.default_options, self)
72
72
  redcarpet = ::Redcarpet::Markdown.new(renderer, LivingStyleGuide::REDCARPET_RENDER_OPTIONS)
73
- redcarpet.render(result)
73
+ remove_highlights(redcarpet.render(result))
74
74
  else
75
75
  require "tilt/#{@type}"
76
- template_class.new{ result }.render(@scope, @locals.merge(locals))
76
+ template_class.new{ remove_highlights(result) }.render(@scope, @locals.merge(locals))
77
77
  end
78
78
  @classes.unshift "livingstyleguide--#{@type}-example"
79
79
  @classes.unshift "livingstyleguide--example"
@@ -84,6 +84,17 @@ class LivingStyleGuide::Document < ::Tilt::Template
84
84
  @scope.depend_on(File.expand_path(file)) if @scope.respond_to?(:depend_on)
85
85
  end
86
86
 
87
+ private
88
+ def set_highlights(code)
89
+ code.gsub!(/^\s*\*\*\*\n(.+?)\n\s*\*\*\*(\n|$)/m, %Q(\n<strong class="livingstyleguide--code-highlight-block">\\1</strong>\n))
90
+ code.gsub(/\*\*\*(.+?)\*\*\*/, %Q(<strong class="livingstyleguide--code-highlight">\\1</strong>))
91
+ end
92
+
93
+ private
94
+ def remove_highlights(code)
95
+ code.gsub(/\*\*\*(.+?)\*\*\*/m, '\\1')
96
+ end
97
+
87
98
  private
88
99
  def template_erb
89
100
  File.read("#{File.dirname(__FILE__)}/templates/#{@template}.html.erb")
@@ -93,7 +104,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
93
104
  def parse_filters
94
105
  (@type == :erb ? data.gsub('<%', '<%%') : data).gsub(/\G(.*?)((```.+?```)|\Z)/m) do
95
106
  content, code_block = $1, $2
96
- content.gsub(/@([\w\d_-]+)(?: ([^\{\n]+))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*\n)+))?/) do
107
+ content.gsub(/^@([\w\d_-]+)(?: ([^\{\n]+))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*\n)+))?/) do
97
108
  name, arguments, block = $1, $2 || '', $3 || $4
98
109
  name = name.gsub('-', '_').to_sym
99
110
  arguments = arguments.split(',').map(&:strip)
@@ -3,20 +3,8 @@ module LivingStyleGuide
3
3
  class Engine
4
4
  attr_accessor :markdown, :files, :options, :variables
5
5
 
6
- @@default_options = {
7
- default_language: :example,
8
- title: 'Living Style Guide',
9
- header: '<h1 class="livingstyleguide--page-title">Living Style Guide</h1>',
10
- footer: '<div class="livingstyleguide--footer"><a class="livingstyleguide--logo" href="http://livingstyleguide.org">Made with the LivingStyleGuide gem.</a></div>',
11
- root: '/'
12
- }
13
-
14
- def self.default_options
15
- @@default_options
16
- end
17
-
18
6
  def initialize(options, sass_options)
19
- @options = @@default_options.merge(options)
7
+ @options = LivingStyleGuide.default_options.merge(options)
20
8
  @sass_options = sass_options
21
9
  @variables = {}
22
10
  @files = []
@@ -18,7 +18,6 @@ end
18
18
 
19
19
  require 'livingstyleguide/filters/options'
20
20
  require 'livingstyleguide/filters/import'
21
- require 'livingstyleguide/filters/highlights'
22
21
  require 'livingstyleguide/filters/full_width'
23
22
  require 'livingstyleguide/filters/haml'
24
23
  require 'livingstyleguide/filters/markdown'
@@ -1,7 +1,4 @@
1
- LivingStyleGuide::Example.add_filter :add_wrapper_class do |css_class|
2
- add_wrapper_class css_class
3
- end
4
-
5
1
  LivingStyleGuide.add_filter :add_wrapper_class do |css_class|
6
2
  document.classes << css_class
3
+ nil
7
4
  end
@@ -1,23 +1,5 @@
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
-
19
-
20
1
  LivingStyleGuide.add_filter :coffee_script, :coffee do
21
2
  document.type = :coffee
3
+ document.template = :javascript
22
4
  nil
23
5
  end
@@ -1,32 +1,3 @@
1
- LivingStyleGuide::Example.add_filter :colors do |file|
2
- suppress_code_block
3
-
4
-
5
- if file
6
- colors = [engine.variables[file]]
7
- else
8
- colors = []
9
- end
10
-
11
- html do |content|
12
- content
13
- end
14
-
15
- pre_processor do |content|
16
- colors += content.split(/\n+/).map{ |l| l.split(/\s+/) }
17
- columns = colors.map{ |l| l.size }.max
18
- colors_html = colors.flatten.map do |variable|
19
- if variable == '-'
20
- css_class = '-lsg-empty'
21
- elsif variable[0] != '$'
22
- variable = "$#{variable}"
23
- end
24
- %Q(<li class="livingstyleguide--color-swatch #{css_class || variable}">#{variable}</li>\n)
25
- end.join("\n")
26
- %(<ul class="livingstyleguide--color-swatches -lsg-#{columns}-columns">\n#{colors_html}\n</ul>\n)
27
- end
28
- end
29
-
30
1
  LivingStyleGuide.add_filter :colors do |content|
31
2
  colors = content.split(/\n+/).map{ |l| l.split(/\s+/) }
32
3
  columns = colors.map{ |l| l.size }.max
@@ -1,3 +1,6 @@
1
+ require 'json'
2
+
1
3
  LivingStyleGuide.add_filter :data do |data|
2
4
  document.locals.merge! JSON.parse("{#{data}}")
5
+ nil
3
6
  end
@@ -1,26 +1,12 @@
1
- LivingStyleGuide::Engine.default_options[:font_example] = { text: <<-TEXT }
1
+ LivingStyleGuide.default_options[:font_example] = { text: <<-TEXT }
2
2
  ABCDEFGHIJKLMNOPQRSTUVWXYZ
3
3
  abcdefghijklmnopqrstuvwxyz
4
4
  0123456789
5
5
  !&/()$=@;:,.
6
6
  TEXT
7
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: #{ERB::Util.html_escape(font)}">\n#{content}\n</div>\n)
13
- end
14
-
15
- pre_processor do |content|
16
- content = options[:font_example][:text] if content == ''
17
- content = ERB::Util.html_escape(content)
18
- content.strip.gsub(/\n/, "<br>\n")
19
- end
20
- end
21
-
22
8
  LivingStyleGuide.add_filter :font_example do |font, text = nil|
23
- text ||= LivingStyleGuide::Engine.default_options[:font_example][:text]
9
+ text ||= LivingStyleGuide.default_options[:font_example][:text]
24
10
  text = ERB::Util.html_escape(text)
25
11
  text.strip!
26
12
  text.gsub!(/\n/, "<br>\n")
@@ -1,7 +1,4 @@
1
- LivingStyleGuide::Example.add_filter :full_width do
2
- add_wrapper_class '-lsg-has-full-width'
3
- end
4
-
5
1
  LivingStyleGuide.add_filter :full_width do
6
2
  document.classes << '-lsg-has-full-width'
3
+ nil
7
4
  end
@@ -1,20 +1,3 @@
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
-
17
-
18
1
  LivingStyleGuide.add_filter :haml do
19
2
  document.type = :haml
20
3
  nil
@@ -4,6 +4,7 @@ LivingStyleGuide.add_filter :import do |glob, data = nil|
4
4
  glob << '.lsg' unless glob =~ /\.(\w+|\*)$/
5
5
  glob.gsub!(/[^\/]+$/, '{_,}\\0')
6
6
  if data
7
+ require 'json'
7
8
  data = JSON.parse("{#{data}}")
8
9
  end
9
10
  Dir.glob(glob).map do |file|
@@ -1,10 +1,5 @@
1
- LivingStyleGuide::Example.add_filter :javascript do
2
- @syntax = :javascript
3
-
4
- add_wrapper_class '-lsg-for-javascript'
5
-
6
- pre_processor do |javascript|
7
- %Q(<script>#{javascript}</script>\n)
8
- end
1
+ LivingStyleGuide.add_filter :javascript do
2
+ document.type = :javascript
3
+ document.template = :javascript
4
+ nil
9
5
  end
10
-
@@ -17,6 +17,7 @@ module LivingStyleGuide
17
17
 
18
18
  def initialize(options = {}, document)
19
19
  @options = options
20
+ @options[:prefix] ||= 'livingstyleguide--'
20
21
  @document = document
21
22
  super @options
22
23
  end
@@ -25,34 +26,34 @@ module LivingStyleGuide
25
26
  id = slug(text)
26
27
  klass = %w(page-title headline sub-headline sub-sub-headline)[header_level]
27
28
  header_level += 1
28
- %Q(<h#{header_level} class="livingstyleguide--#{klass}" id="#{id}"><a class="livingstyleguide--anchor" href="##{id}"></a>#{text}</h#{header_level}>\n)
29
+ %Q(<h#{header_level} class="#{@options[:prefix]}#{klass}" id="#{id}"><a class="livingstyleguide--anchor" href="##{id}"></a>#{text}</h#{header_level}>\n)
29
30
  end
30
31
 
31
32
  def paragraph(text)
32
- %Q(<p class="livingstyleguide--paragraph">#{text}</p>\n)
33
+ %Q(<p class="#{@options[:prefix]}paragraph">#{text}</p>\n)
33
34
  end
34
35
 
35
36
  def list(contents, list_type)
36
37
  tag_name = "#{list_type.to_s[0, 1]}l"
37
- %Q(<#{tag_name} class="livingstyleguide--#{list_type}-list">\n#{contents}</#{tag_name}>\n)
38
+ %Q(<#{tag_name} class="#{@options[:prefix]}#{list_type}-list">\n#{contents}</#{tag_name}>\n)
38
39
  end
39
40
 
40
41
  def list_item(text, list_type)
41
- %Q(<li class="livingstyleguide--#{list_type}-list-item">#{text.strip}</li>\n)
42
+ %Q(<li class="#{@options[:prefix]}#{list_type}-list-item">#{text.strip}</li>\n)
42
43
  end
43
44
 
44
45
  def block_code(code, language)
45
46
  language = language.to_s.strip.to_sym
46
47
  language = @options[:default_language] if language == :''
47
48
  document = Document.new(livingstyleguide: @document) { code }
48
- document.type = language == :example ? :plain : language
49
+ document.type = language == :example ? :html : language
49
50
  document.template = template_for(language)
50
51
  document.render(@document.scope)
51
52
  end
52
53
 
53
54
  def codespan(code)
54
55
  code = ERB::Util.html_escape(code)
55
- %Q(<code class="livingstyleguide--code-span livingstyleguide--code">#{code}</code>)
56
+ %Q(<code class="#{@options[:prefix]}code-span #{@options[:prefix]}code">#{code}</code>)
56
57
  end
57
58
 
58
59
  private
@@ -1,8 +1,8 @@
1
- <section class="<%= classes.join(' ') %>">
1
+ <section class="<%= classes.join(' ') %>" id="<%= id %>">
2
2
  <div class="livingstyleguide--html">
3
3
  <%= html %>
4
4
  </div>
5
5
  <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><%=
6
- [:plain].index(type) ? source : ::MiniSyntax.highlight(source, type)
6
+ [:plain].index(type) ? source : ::MiniSyntax.highlight(type == :html ? ERB::Util.h(source) : source, type)
7
7
  %></code></pre>
8
8
  </section>
@@ -0,0 +1,6 @@
1
+ <section class="<%= classes.join(' ') %>" id="<%= id %>">
2
+ <script><%= html %></script>
3
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><%=
4
+ [:plain].index(type) ? source : ::MiniSyntax.highlight(source, type)
5
+ %></code></pre>
6
+ </section>
@@ -1,3 +1,3 @@
1
1
  module LivingStyleGuide
2
- VERSION = '2.0.0.alpha.1'
2
+ VERSION = '2.0.0.alpha.2'
3
3
  end
@@ -48,37 +48,11 @@ $livingstyleguide--color-swatches-per-line: 2 !default;
48
48
  $livingstyleguide--highlight-color: #f6ffa3 !default;
49
49
  $livingstyleguide--highlight-border-radius: 2px;
50
50
 
51
- //// RESET ////
52
-
53
- %livingstyleguide--reset {
54
- background: transparent;
55
- border: none;
56
- border-collapse: collapse;
57
- border-radius: 0;
58
- border-spacing: 0;
59
- -webkit-box-sizing: border-box;
60
- -moz-box-sizing: border-box;
61
- box-sizing: border-box;
62
- color: inherit;
63
- display: block;
64
- font-size: inherit;
65
- -webkit-font-smoothing: antialiased;
66
- font-style: inherit;
67
- font-weight: inherit;
68
- line-height: inherit;
69
- list-style: none;
70
- margin: 0;
71
- padding: 0;
72
- text-align: inherit;
73
- text-decoration: none;
74
- vertical-align: baseline;
75
- }
76
-
77
51
  //// IMPORTS ////
78
52
 
53
+ @import "livingstyleguide/reset";
79
54
  @import "livingstyleguide/layout";
80
55
  @import "livingstyleguide/content";
81
56
  @import "livingstyleguide/code";
82
57
  @import "livingstyleguide/color-swatches";
83
58
  @import "livingstyleguide/variables";
84
-
@@ -0,0 +1,24 @@
1
+ %livingstyleguide--reset {
2
+ background: transparent;
3
+ border: none;
4
+ border-collapse: collapse;
5
+ border-radius: 0;
6
+ border-spacing: 0;
7
+ -webkit-box-sizing: border-box;
8
+ -moz-box-sizing: border-box;
9
+ box-sizing: border-box;
10
+ color: inherit;
11
+ display: block;
12
+ font-size: inherit;
13
+ -webkit-font-smoothing: antialiased;
14
+ font-style: inherit;
15
+ font-weight: inherit;
16
+ line-height: inherit;
17
+ list-style: none;
18
+ margin: 0;
19
+ padding: 0;
20
+ text-align: inherit;
21
+ text-decoration: none;
22
+ vertical-align: baseline;
23
+ }
24
+
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.1
4
+ version: 2.0.0.alpha.2
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-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minisyntax
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: hooks
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '='
88
- - !ruby/object:Gem::Version
89
- version: 0.3.3
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '='
95
- - !ruby/object:Gem::Version
96
- version: 0.3.3
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: compass
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -190,12 +176,9 @@ files:
190
176
  - assets/javascripts/livingstyleguide.js
191
177
  - bin/livingstyleguide
192
178
  - lib/livingstyleguide.rb
193
- - lib/livingstyleguide/code_block.rb
194
179
  - lib/livingstyleguide/command_line_interface.rb
195
180
  - lib/livingstyleguide/document.rb
196
181
  - lib/livingstyleguide/engine.rb
197
- - lib/livingstyleguide/example.rb
198
- - lib/livingstyleguide/filter_hooks.rb
199
182
  - lib/livingstyleguide/filters.rb
200
183
  - lib/livingstyleguide/filters/add_wrapper_class.rb
201
184
  - lib/livingstyleguide/filters/coffee_script.rb
@@ -204,7 +187,6 @@ files:
204
187
  - lib/livingstyleguide/filters/font_example.rb
205
188
  - lib/livingstyleguide/filters/full_width.rb
206
189
  - lib/livingstyleguide/filters/haml.rb
207
- - lib/livingstyleguide/filters/highlights.rb
208
190
  - lib/livingstyleguide/filters/import.rb
209
191
  - lib/livingstyleguide/filters/javascript.rb
210
192
  - lib/livingstyleguide/filters/markdown.rb
@@ -216,20 +198,19 @@ files:
216
198
  - lib/livingstyleguide/integration/sass.rb
217
199
  - lib/livingstyleguide/integration/sprockets.rb
218
200
  - lib/livingstyleguide/markdown_extensions.rb
219
- - lib/livingstyleguide/sass_extensions.rb
220
- - lib/livingstyleguide/sass_extensions/functions.rb
221
201
  - lib/livingstyleguide/templates/default.html.erb
222
202
  - lib/livingstyleguide/templates/example.html.erb
223
203
  - lib/livingstyleguide/templates/font-example.html.erb
204
+ - lib/livingstyleguide/templates/javascript.html.erb
224
205
  - lib/livingstyleguide/templates/layout.html.erb
225
206
  - lib/livingstyleguide/templates/plain.html.erb
226
- - lib/livingstyleguide/tilt_template.rb
227
207
  - lib/livingstyleguide/version.rb
228
208
  - stylesheets/_livingstyleguide.scss
229
209
  - stylesheets/livingstyleguide/_code.scss
230
210
  - stylesheets/livingstyleguide/_color-swatches.scss
231
211
  - stylesheets/livingstyleguide/_content.scss
232
212
  - stylesheets/livingstyleguide/_layout.scss
213
+ - stylesheets/livingstyleguide/_reset.scss
233
214
  - stylesheets/livingstyleguide/_variables.scss
234
215
  homepage: http://livingstyleguide.org
235
216
  licenses: []
@@ -1,35 +0,0 @@
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
-
@@ -1,93 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'minisyntax'
4
- require 'erb'
5
- require 'hooks'
6
-
7
- class LivingStyleGuide::Example
8
- include Hooks
9
- include Hooks::InstanceHooks
10
- include LivingStyleGuide::FilterHooks
11
-
12
- FILTER_REGEXP = /^@([a-z\-_]+)(?:\s+(.+?))?$/
13
-
14
- define_hooks :filter_before, :filter_after, :html, :pre_processor
15
- attr_reader :options, :engine
16
- @@filters = {}
17
-
18
- def initialize(input, options, engine)
19
- @options = { default_filters: [] }.merge(options)
20
- @engine = engine
21
- @source = input
22
- @wrapper_classes = %w(livingstyleguide--example)
23
- @syntax = :html
24
- @filters = @options[:default_filters].clone
25
- @output_code_block = true
26
- parse_filters
27
- apply_filters
28
- end
29
-
30
- html do |content|
31
- %Q(<div class="#{wrapper_classes}">\n #{content}\n</div>\n)
32
- end
33
-
34
- def render
35
- html = run_last_filter_hook(:html, filtered_example)
36
- code_block = LivingStyleGuide::CodeBlock.new(@source, @syntax).render if @output_code_block
37
- "#{html}#{code_block}"
38
- end
39
-
40
- def self.add_filter(key = nil, &block)
41
- if key
42
- @@filters[key.to_sym] = block
43
- else
44
- instance_eval &block
45
- end
46
- end
47
-
48
- def add_wrapper_class(class_name)
49
- @wrapper_classes << class_name
50
- end
51
-
52
- def wrapper_classes
53
- @wrapper_classes.join(' ')
54
- end
55
-
56
- def suppress_code_block
57
- @output_code_block = false
58
- end
59
-
60
- private
61
- def parse_filters
62
- lines = @source.split(/\n/)
63
- @source = lines.reject do |line|
64
- if line =~ FILTER_REGEXP
65
- @filters << line
66
- end
67
- end.join("\n")
68
- end
69
-
70
- private
71
- def apply_filters
72
- @filters.each do |filter|
73
- set_filter *filter.match(FILTER_REGEXP)[1..2]
74
- end
75
- end
76
-
77
- private
78
- def set_filter(key, argument = nil)
79
- name = key.to_s.gsub('-', '_').to_sym
80
- unless @@filters.has_key?(name)
81
- raise NameError.new("Undefined filter “@#{key}” called.", name)
82
- end
83
- instance_exec argument, &@@filters[name]
84
- end
85
-
86
- private
87
- def filtered_example
88
- source = run_filter_hook(:filter_before, @source)
89
- source = run_last_filter_hook(:pre_processor, source)
90
- run_filter_hook(:filter_after, source)
91
- end
92
- end
93
-
@@ -1,34 +0,0 @@
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
-
@@ -1,9 +0,0 @@
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
-
@@ -1,9 +0,0 @@
1
- module LivingStyleGuide::SassExtensions
2
- end
3
-
4
- require 'livingstyleguide/sass_extensions/functions'
5
- require 'sass'
6
-
7
- module Sass::Script::Functions
8
- include LivingStyleGuide::SassExtensions::Functions
9
- end
@@ -1,49 +0,0 @@
1
- module LivingStyleGuide::SassExtensions::Functions
2
-
3
- def list_variables(uri)
4
- Sass::Util.sass_warn '`list-variables()` is deprecated and will be removed in v2.0.0.'
5
- uri = uri.value
6
- variables = parse_variables(uri)
7
- variables.map! do |name|
8
- Sass::Script::String.new(name)
9
- end
10
- Sass::Script::List.new(variables, :space)
11
- end
12
-
13
- def global_variables
14
- ruby = environment.global_env.instance_variable_get(:@vars)
15
- sass_script = {}
16
- ruby.each do |name, value|
17
- sass_script[Sass::Script::String.new(name)] = value
18
- end
19
- Sass::Script::Value::Map.new(sass_script)
20
- end
21
-
22
- if defined?(::Middleman)
23
- def asset_url(path, prefix)
24
- Sass::Script::String.new(options[:sprockets][:context].asset_url(path.value, prefix.value))
25
- end
26
- end
27
-
28
- private
29
- def parse_variables(uri)
30
- uri = uri.dup
31
- uri += '.s?ss' unless uri =~ /\.s[ac]ss$/
32
- uri.gsub! %r{^(.*)/(.+)$}, '\1/{_,}\2'
33
- variables = []
34
- paths = [Compass.configuration.sass_path, Compass.configuration.additional_import_paths].flatten
35
- paths.each do |path|
36
- if path.is_a? String
37
- Dir.glob(File.join(path, uri)).each do |file|
38
- sass = File.read(file)
39
- variables << sass.scan(%r(\$([a-z0-9\-_]+)\s*:))
40
- end
41
- end
42
- end
43
- variables.flatten!
44
- variables.uniq!
45
- variables
46
- end
47
-
48
- end
49
-
@@ -1,100 +0,0 @@
1
- require 'tilt'
2
- require 'erb'
3
- require 'yaml'
4
- require 'json'
5
-
6
- module LivingStyleGuide
7
- class TiltTemplate < ::Tilt::Template
8
- self.default_mime_type = 'text/html'
9
-
10
- def prepare
11
- end
12
-
13
- def evaluate(scope, locals, &block)
14
- @scope = scope
15
- parse_options(data)
16
- render_living_style_guide
17
- end
18
-
19
- private
20
- def sass_options
21
- if defined?(Compass)
22
- options = Compass.configuration.to_sass_plugin_options
23
- else
24
- load_path = File.join(File.dirname(__FILE__), '..', '..', 'stylesheets')
25
- options = { load_paths: [load_path] }
26
- end
27
- if defined?(Rails)
28
- options[:load_paths] += Rails.application.config.assets.paths
29
- end
30
- if @file.nil?
31
- options[:load_paths] << Dir.pwd
32
- end
33
- if options[:template_location]
34
- options[:template_location].each do |path, short|
35
- options[:load_paths] << path
36
- end
37
- end
38
- options[:filename] = eval_file
39
- options[:line] = line
40
- options[:syntax] = @options[:syntax]
41
- options[:sprockets] = { context: @scope }
42
- options[:custom] = { sprockets_context: @scope }
43
- if defined?(Sass::Rails::Resolver)
44
- options[:custom][:resolver] = Sass::Rails::Resolver.new(@scope)
45
- end
46
- options
47
- end
48
-
49
- private
50
- def parse_options(data)
51
- data.strip!
52
- @options = (data[0] == '{') ? JSON.parse(data) : YAML.load(data)
53
- @options = {} unless @options
54
- @options.keys.each do |key|
55
- @options[key.gsub('-', '_').to_sym] = @options.delete(key)
56
- end
57
- @options[:syntax] = @options.has_key?(:styleguide_sass) ? :sass : :scss
58
- @options[:source] ||= File.basename(file, '.html.lsg')
59
- @options[:filename] = file
60
- @options[:root] ||= root
61
- end
62
-
63
- private
64
- def configure_cache
65
- return unless @scope.respond_to?(:depend_on)
66
- @engine.files.uniq.each do |file|
67
- @scope.depend_on file
68
- end
69
- end
70
-
71
- private
72
- def root
73
- if @scope.respond_to?(:environment) and @scope.environment.respond_to?(:root)
74
- @scope.environment.root
75
- else
76
- find_root_path
77
- end
78
- end
79
-
80
- private
81
- def find_root_path
82
- path = @file.nil? ? Dir.pwd : File.dirname(@file)
83
- while path.length > 0 do
84
- if File.exists?(File.join(path, 'Gemfile')) or File.exists?(File.join(path, '.git'))
85
- break
86
- end
87
- path = File.expand_path('..', path)
88
- end
89
- path
90
- end
91
-
92
- private
93
- def render_living_style_guide
94
- @engine = ::LivingStyleGuide::Engine.new(@options, sass_options)
95
- html = @engine.render
96
- configure_cache
97
- html
98
- end
99
- end
100
- end