livingstyleguide 2.0.0.alpha.5 → 2.0.0.alpha.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54f48cd7f49da48fb013eb94ef814c352b0b36d8
4
- data.tar.gz: 708b10793c5522b1ce06c4b44b9b88130b410d09
3
+ metadata.gz: 99011854cea04c29122a5e4014eca155e1972da2
4
+ data.tar.gz: 324abacc9ef03fa22b0fa570b8fee64f686c5312
5
5
  SHA512:
6
- metadata.gz: 4db4eee6c6208f7887ebc193b8e878dbd73f0a464206e0ebd3e31fdab7a176073217f06f293035534442c9b9039fe8c19cde309cf30c801ad8a75d46cdc245a3
7
- data.tar.gz: 168434570778b35daa37373c6827e2d1a86166c2da1123d72d0608586a6eeb0d2b52b27f26541d5663a0f142a1638255241a285f086904adf34c5f2fc25fa41b
6
+ metadata.gz: 201d20433e57bce205aa2fc8086678e49455b33c97fadacded15fc9538d8b2be1d24876c005bb671662cdb2918ad0bb0ee460ee7a06773c9e2bcba03e7312e67
7
+ data.tar.gz: 4c8f285365e917fd882f173c03827a195dc66df295a9f5051264c4b0368ba6c679beda37212dc16c96b291054110fd39f568c8f04aa27dcce344737586c64832
@@ -8,6 +8,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
8
8
  attr_accessor :source, :type, :filters, :template, :classes, :html
9
9
  attr_accessor :css, :id, :locals
10
10
  attr_accessor :title
11
+ attr_accessor :defaults
11
12
  attr_reader :scope
12
13
 
13
14
  %w(scss head header footer).each do |attr|
@@ -36,10 +37,10 @@ class LivingStyleGuide::Document < ::Tilt::Template
36
37
  @scss = ''
37
38
  @css = ''
38
39
  @locals = {}
39
- end
40
-
41
- def source
42
- @source ||= erb.gsub(/<%.*?%>\n?/, '').strip
40
+ @defaults = { global: {} }
41
+ @head = ""
42
+ @header = ""
43
+ @footer = ""
43
44
  end
44
45
 
45
46
  def highlighted_source
@@ -64,13 +65,15 @@ class LivingStyleGuide::Document < ::Tilt::Template
64
65
 
65
66
  def erb
66
67
  @erb ||= parse_filters do |name, arguments, options, block|
67
- "<%= #{name}(#{arguments.inspect}, #{options.inspect}, #{block.inspect}) %>\n"
68
+ options = %Q(document.defaults[:global].merge(document.defaults[:@#{name}] || {}).merge(#{options.inspect}))
69
+ "<%= #{name}(#{arguments.inspect}, #{options}, #{block.inspect}) %>\n"
68
70
  end
69
71
  end
70
72
 
71
73
  def evaluate(scope, locals, &block)
72
74
  @scope = scope
73
75
  result = ERB.new(erb).result(@filters.get_binding)
76
+ @source = result
74
77
  @html = render_html(result, locals)
75
78
  @classes.unshift "livingstyleguide--#{@type}-example"
76
79
  @classes.unshift "livingstyleguide--example"
@@ -170,7 +173,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
170
173
  def parse_filters
171
174
  data.gsub('<%', '<%%').gsub(/\G(.*?)((```.+?```)|\Z)/m) do
172
175
  content, code_block = $1, $2
173
- content.gsub(/^@([\w\d_-]+)(?: ([^\n]*[^\{\n:]))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*(?:\n|\Z))+)| *:\n((?:.|\n)*?)(?:\n\n|\Z))?/) do
176
+ content.gsub(/^@([\w\d_-]+)(?: ([^\n]*[^\{\n:]))?(?: *\{\n((?:.|\n)*?)\n\}|((?:\n+ .*)+(?=\n|\Z))| *:\n((?:.|\n)*?)(?:\n\n|\Z))?/) do
174
177
  name, arguments_string, block = $1, $2 || '', $3 || $4 || $5
175
178
  options = {
176
179
  block_type: $3 ? :braces : $4 ? :indented : $5 ? :block : :none
@@ -178,7 +181,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
178
181
  name = name.gsub('-', '_').to_sym
179
182
  arguments = parse_arguments(arguments_string, options)
180
183
  if options[:block_type] == :indented
181
- block.gsub!(/\A(\s*)((?:.|\n)+)\Z/){ $2.gsub(/^#{$1}/, '') }
184
+ block.gsub!(/\A\n(\s*)((?:.|\n)+)\Z/){ $2.gsub(/^#{$1}/, '') }
182
185
  end
183
186
  yield name, arguments, options, block
184
187
  end + code_block
@@ -7,6 +7,9 @@ LivingStyleGuide.add_filter :css, :scss do |arguments, options, source|
7
7
  document.depend_on file
8
8
  document.scss << %Q(@import "#{file}";\n)
9
9
  else
10
+ if options[:preprocessor] == "sass"
11
+ source = Sass::Engine.new(source).to_tree.to_scss
12
+ end
10
13
  document.scss << "##{document.id.gsub('/', '\\/')} {\n#{source}\n}\n"
11
14
  end
12
15
  nil
@@ -1,6 +1,11 @@
1
1
  require 'json'
2
+ require 'yaml'
2
3
 
3
4
  LivingStyleGuide.add_filter :data do |arguments, options, data|
4
- document.locals.merge! JSON.parse("{#{data}}")
5
+ if options[:format] == "yaml"
6
+ document.locals.merge! Psych.load("{#{data}}")
7
+ else
8
+ document.locals.merge! JSON.parse("{#{data}}")
9
+ end
5
10
  nil
6
11
  end
@@ -0,0 +1,6 @@
1
+ LivingStyleGuide.add_filter :default do |arguments, options, block|
2
+ key = arguments.first ? arguments.first.gsub("-", "_").to_sym : :global
3
+ document.defaults[key] ||= {}
4
+ document.defaults[key].merge!(options)
5
+ nil
6
+ end
@@ -1,25 +1,39 @@
1
1
  require 'tilt'
2
2
 
3
- LivingStyleGuide.add_filter :import do |arguments, options, data|
4
- glob = arguments.first
5
- if glob =~ /\.s[ac]ss$/
6
- raise "Error: Please use `@css #{glob}` instead of `@import #{glob}` for importing Sass."
7
- end
3
+ def map_files(glob, &block)
8
4
  glob << '.lsg' unless glob =~ /\.(\w+|\*)$/
9
5
  glob.gsub!(/[^\/]+$/, '{_,}\\0')
10
6
  if document.file
11
7
  glob = File.join(File.dirname(document.file), glob)
12
8
  end
13
9
 
10
+ Dir.glob(glob).map do |file|
11
+ document.depend_on file
12
+ yield(file)
13
+ end.join
14
+ end
15
+
16
+ LivingStyleGuide.add_filter :import do |arguments, options, data|
17
+ glob = arguments.first
18
+ if glob =~ /\.s[ac]ss$/
19
+ raise "Error: Please use `@css #{glob}` instead of `@import #{glob}` for importing Sass."
20
+ end
21
+
14
22
  if data
15
23
  Kernel.require 'json'
16
24
  data = JSON.parse("{#{data}}")
17
25
  end
18
26
 
19
- Dir.glob(glob).map do |file|
20
- document.depend_on file
27
+ map_files glob do |file|
21
28
  html = ::Tilt.new(file, livingstyleguide: document).render(document.scope, data)
22
29
  html.gsub!("\n", "\n ")
23
30
  "\n<div>\n#{html}\n</div>\n"
24
- end.join
31
+ end
32
+ end
33
+
34
+ LivingStyleGuide.add_filter :use do |arguments, options, data|
35
+ glob = arguments.first
36
+ map_files glob do |file|
37
+ File.read(file)
38
+ end
25
39
  end
@@ -0,0 +1,33 @@
1
+ LivingStyleGuide.add_filter :title do |arguments, options, block|
2
+ document.title = arguments.first
3
+ nil
4
+ end
5
+
6
+ { :before => :head, :after => :footer }.each do |name, destination|
7
+ eval <<-RUBY
8
+ LivingStyleGuide.add_filter :javascript_#{name} do |arguments, options, block|
9
+ if src = arguments.first
10
+ document.#{destination} << %Q(<script src="\#{src}"></script>)
11
+ else
12
+ if options[:transpiler] == "coffee-script"
13
+ block = Tilt["coffee"].new{ block }.render
14
+ end
15
+ document.#{destination} << %Q(<script>\\n\#{block}\\n</script>)
16
+ end
17
+ nil
18
+ end
19
+ RUBY
20
+ end
21
+
22
+ %w(head header footer).each do |part|
23
+ eval <<-RUBY
24
+ LivingStyleGuide.add_filter :#{part} do |arguments, options, block|
25
+ if template = Tilt[options[:type]]
26
+ block = template.new{ block }.render
27
+ end
28
+ document.#{part} << block + "\n"
29
+ nil
30
+ end
31
+ RUBY
32
+ nil
33
+ end
@@ -2,6 +2,6 @@ LivingStyleGuide.add_filter :style do |arguments, options, block|
2
2
  options.delete :block_type
3
3
  options.each do |key, value|
4
4
  document.scss << %Q($livingstyleguide--#{key.to_s.gsub("_", "-")}: #{value};\n)
5
- nil
6
5
  end
6
+ nil
7
7
  end
@@ -17,7 +17,8 @@ class LivingStyleGuide::Filters
17
17
  end
18
18
 
19
19
  require 'livingstyleguide/filters/options'
20
- require 'livingstyleguide/filters/import'
20
+ require 'livingstyleguide/filters/default'
21
+ require 'livingstyleguide/filters/import_and_use'
21
22
  require 'livingstyleguide/filters/require'
22
23
  require 'livingstyleguide/filters/full_width'
23
24
  require 'livingstyleguide/filters/haml'
@@ -31,4 +32,4 @@ require 'livingstyleguide/filters/colors'
31
32
  require 'livingstyleguide/filters/css'
32
33
  require 'livingstyleguide/filters/style'
33
34
  require 'livingstyleguide/filters/data'
34
- require 'livingstyleguide/filters/html_head'
35
+ require 'livingstyleguide/filters/layout'
@@ -1,5 +1,5 @@
1
1
  <!doctype html>
2
- <html>
2
+ <html id="<%= id %>">
3
3
 
4
4
  <head>
5
5
  <meta charset="utf-8">
@@ -1,3 +1,3 @@
1
1
  module LivingStyleGuide
2
- VERSION = '2.0.0.alpha.5'
2
+ VERSION = '2.0.0.alpha.6'
3
3
  end
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.5
4
+ version: 2.0.0.alpha.6
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-04-28 00:00:00.000000000 Z
11
+ date: 2015-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minisyntax
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: erubis
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: heredoc_unindent
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -199,12 +213,13 @@ files:
199
213
  - lib/livingstyleguide/filters/colors.rb
200
214
  - lib/livingstyleguide/filters/css.rb
201
215
  - lib/livingstyleguide/filters/data.rb
216
+ - lib/livingstyleguide/filters/default.rb
202
217
  - lib/livingstyleguide/filters/font_example.rb
203
218
  - lib/livingstyleguide/filters/full_width.rb
204
219
  - lib/livingstyleguide/filters/haml.rb
205
- - lib/livingstyleguide/filters/html_head.rb
206
- - lib/livingstyleguide/filters/import.rb
220
+ - lib/livingstyleguide/filters/import_and_use.rb
207
221
  - lib/livingstyleguide/filters/javascript.rb
222
+ - lib/livingstyleguide/filters/layout.rb
208
223
  - lib/livingstyleguide/filters/markdown.rb
209
224
  - lib/livingstyleguide/filters/options.rb
210
225
  - lib/livingstyleguide/filters/require.rb
@@ -1,4 +0,0 @@
1
- LivingStyleGuide.add_filter :title do |arguments, options, block|
2
- document.title = arguments.first
3
- nil
4
- end