livingstyleguide 2.0.0.alpha.4 → 2.0.0.alpha.5

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: 09fd1db6eea766e1fc9ce49ea9093fcba7cb5cf0
4
- data.tar.gz: 9e677d67f85cea4e8067e25af350057599fb7b74
3
+ metadata.gz: 54f48cd7f49da48fb013eb94ef814c352b0b36d8
4
+ data.tar.gz: 708b10793c5522b1ce06c4b44b9b88130b410d09
5
5
  SHA512:
6
- metadata.gz: 23abb326faa5c71f9432c9e44d677f12bcc29510e9ce9d13df4d316b1032e43d693798bd03c30be56eb70a573ea3e2f690499ac75303a6aa01e7d02f4af8e963
7
- data.tar.gz: 197222fd5eb577683377373f5d0a1034d06c2874851076c0e7a7d494a594aa3de5ee05d34e3efec64dcb726a718d692659aa52cd8f7a95d8b7aee09399d95f9c
6
+ metadata.gz: 4db4eee6c6208f7887ebc193b8e878dbd73f0a464206e0ebd3e31fdab7a176073217f06f293035534442c9b9039fe8c19cde309cf30c801ad8a75d46cdc245a3
7
+ data.tar.gz: 168434570778b35daa37373c6827e2d1a86166c2da1123d72d0608586a6eeb0d2b52b27f26541d5663a0f142a1638255241a285f086904adf34c5f2fc25fa41b
@@ -29,7 +29,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
29
29
  end
30
30
 
31
31
  def prepare
32
- @type = :markdown
32
+ @type = :lsg
33
33
  @filters = LivingStyleGuide::Filters.new(self)
34
34
  @template = options.has_key?(:livingstyleguide) ? :default : :layout
35
35
  @classes = []
@@ -63,28 +63,15 @@ class LivingStyleGuide::Document < ::Tilt::Template
63
63
  end
64
64
 
65
65
  def erb
66
- @erb ||= parse_filters do |name, arguments|
67
- arguments = arguments.map do |argument|
68
- %Q("#{argument.gsub('"', '\\"').gsub("\n", '\\n')}")
69
- end
70
- "<%= #{name}(#{arguments.join(', ')}) %>"
66
+ @erb ||= parse_filters do |name, arguments, options, block|
67
+ "<%= #{name}(#{arguments.inspect}, #{options.inspect}, #{block.inspect}) %>\n"
71
68
  end
72
69
  end
73
70
 
74
71
  def evaluate(scope, locals, &block)
75
72
  @scope = scope
76
73
  result = ERB.new(erb).result(@filters.get_binding)
77
- @html = case @type
78
- when :plain, :example, :html, :javascript
79
- remove_highlights(result)
80
- when :markdown
81
- renderer = LivingStyleGuide::RedcarpetHTML.new(LivingStyleGuide.default_options, self)
82
- redcarpet = ::Redcarpet::Markdown.new(renderer, LivingStyleGuide::REDCARPET_RENDER_OPTIONS)
83
- remove_highlights(redcarpet.render(result))
84
- else
85
- require "tilt/#{@type}"
86
- template_class.new{ remove_highlights(result) }.render(@scope, @locals.merge(locals))
87
- end
74
+ @html = render_html(result, locals)
88
75
  @classes.unshift "livingstyleguide--#{@type}-example"
89
76
  @classes.unshift "livingstyleguide--example"
90
77
  ERB.new(template_erb).result(binding).gsub(/\n\n+/, "\n")
@@ -94,6 +81,25 @@ class LivingStyleGuide::Document < ::Tilt::Template
94
81
  @scope.depend_on(File.expand_path(file)) if @scope.respond_to?(:depend_on)
95
82
  end
96
83
 
84
+ private
85
+ def render_html(result, locals)
86
+ if @type == :lsg
87
+ renderer = LivingStyleGuide::RedcarpetHTML.new(LivingStyleGuide.default_options, self)
88
+ redcarpet = ::Redcarpet::Markdown.new(renderer, LivingStyleGuide::REDCARPET_RENDER_OPTIONS)
89
+ redcarpet.render(result)
90
+ elsif engine = Tilt[@type]
91
+ begin
92
+ require "tilt/#{template_name}"
93
+ rescue LoadError
94
+ end
95
+ engine.new{ remove_highlights(result) }.render(@scope, @locals.merge(locals))
96
+ elsif @type == :escaped
97
+ ERB::Util.h(remove_highlights(result))
98
+ else
99
+ remove_highlights(result)
100
+ end
101
+ end
102
+
97
103
  private
98
104
  def set_highlights(code, &block)
99
105
  code, positions = remove_highlight_marker_and_save_positions(code)
@@ -164,21 +170,45 @@ class LivingStyleGuide::Document < ::Tilt::Template
164
170
  def parse_filters
165
171
  data.gsub('<%', '<%%').gsub(/\G(.*?)((```.+?```)|\Z)/m) do
166
172
  content, code_block = $1, $2
167
- content.gsub(/^@([\w\d_-]+)(?: ([^\{\n]+))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*(\n|\Z))+))?/) do
168
- name, arguments, block = $1, $2 || '', $3 || $4
173
+ content.gsub(/^@([\w\d_-]+)(?: ([^\n]*[^\{\n:]))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*(?:\n|\Z))+)| *:\n((?:.|\n)*?)(?:\n\n|\Z))?/) do
174
+ name, arguments_string, block = $1, $2 || '', $3 || $4 || $5
175
+ options = {
176
+ block_type: $3 ? :braces : $4 ? :indented : $5 ? :block : :none
177
+ }
169
178
  name = name.gsub('-', '_').to_sym
170
- arguments = arguments.split(',').map(&:strip)
171
- if block
172
- arguments << block.gsub(/\A(\s*)((?:.|\n)+)\Z/){ $2.gsub(/^#{$1}/, '') }
179
+ arguments = parse_arguments(arguments_string, options)
180
+ if options[:block_type] == :indented
181
+ block.gsub!(/\A(\s*)((?:.|\n)+)\Z/){ $2.gsub(/^#{$1}/, '') }
173
182
  end
174
- yield name, arguments
183
+ yield name, arguments, options, block
175
184
  end + code_block
176
185
  end
177
186
  end
178
187
 
188
+ private
189
+ def parse_arguments(arguments_string, options)
190
+ arguments = arguments_string.split(/(?<!\\);/)
191
+ arguments.map! do |argument|
192
+ argument.strip!
193
+ argument.gsub! "\\;", ";"
194
+ if /^(?<key>[a-zA-Z0-9_\-]+):(?<value>.+)$/ =~ argument
195
+ options[key.downcase.gsub('-', '_').to_sym] = remove_quots(value.strip)
196
+ nil
197
+ else
198
+ remove_quots(argument)
199
+ end
200
+ end
201
+ arguments.compact
202
+ end
203
+
204
+ private
205
+ def remove_quots(string)
206
+ string.sub(/^"(.*)"$|^'(.*)'$|^(.*)$/, '\\1\\2\\3').gsub(/\\("|')/, "\\1")
207
+ end
208
+
179
209
  private
180
210
  def gsub_content(regexp, &block)
181
- if @type == :markdown
211
+ if @type == :lsg
182
212
  data.gsub(/\G(.+?)((```.+?```)|\Z)/m) do
183
213
  content, code_block = $1, $2
184
214
  content.to_s.gsub(regexp, &block) + code_block
@@ -190,16 +220,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
190
220
 
191
221
  private
192
222
  def template_name
193
- @type == :markdown ? :redcarpet : @type
194
- end
195
-
196
- private
197
- def template_class
198
- case @type
199
- when :coffee then Tilt::CoffeeScriptTemplate
200
- when :erb then Tilt::ERBTemplate
201
- else Tilt.const_get(@type.to_s.capitalize + 'Template')
202
- end
223
+ (@type == :lsg or @type == :markdown) ? :redcarpet : @type
203
224
  end
204
225
 
205
226
  private
@@ -21,6 +21,7 @@ require 'livingstyleguide/filters/import'
21
21
  require 'livingstyleguide/filters/require'
22
22
  require 'livingstyleguide/filters/full_width'
23
23
  require 'livingstyleguide/filters/haml'
24
+ require 'livingstyleguide/filters/type'
24
25
  require 'livingstyleguide/filters/markdown'
25
26
  require 'livingstyleguide/filters/javascript'
26
27
  require 'livingstyleguide/filters/coffee_script'
@@ -28,5 +29,6 @@ require 'livingstyleguide/filters/add_wrapper_class'
28
29
  require 'livingstyleguide/filters/font_example'
29
30
  require 'livingstyleguide/filters/colors'
30
31
  require 'livingstyleguide/filters/css'
32
+ require 'livingstyleguide/filters/style'
31
33
  require 'livingstyleguide/filters/data'
32
34
  require 'livingstyleguide/filters/html_head'
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :add_wrapper_class do |css_class|
2
- document.classes << css_class
1
+ LivingStyleGuide.add_filter :add_wrapper_class do |arguments, options, block|
2
+ document.classes << arguments.first
3
3
  nil
4
4
  end
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :coffee_script, :coffee do
1
+ LivingStyleGuide.add_filter :coffee_script, :coffee do |arguments, options, block|
2
2
  document.type = :coffee
3
3
  document.template = :javascript
4
4
  nil
@@ -1,5 +1,5 @@
1
- LivingStyleGuide.add_filter :colors do |content|
2
- colors = content.split(/\n+/).map{ |l| l.split(/\s+/) }
1
+ LivingStyleGuide.add_filter :colors do |arguments, options, content|
2
+ colors = content.split(/\n+/).map{ |l| l.strip.split(/\s+/) }
3
3
  columns = colors.map{ |l| l.size }.max
4
4
  colors = colors.flatten
5
5
  document.scss << <<-SCSS
@@ -1,10 +1,11 @@
1
- LivingStyleGuide.add_filter :css, :scss do |source|
2
- if source =~ /\.(css|scss|sass)$/
1
+ LivingStyleGuide.add_filter :css, :scss do |arguments, options, source|
2
+ file = arguments.first
3
+ if file =~ /\.(css|scss|sass)$/
3
4
  if document.file
4
- source = File.join(File.dirname(document.file), source)
5
+ file = File.join(File.dirname(document.file), file)
5
6
  end
6
- document.depend_on source
7
- document.scss << %Q(@import "#{source}";\n)
7
+ document.depend_on file
8
+ document.scss << %Q(@import "#{file}";\n)
8
9
  else
9
10
  document.scss << "##{document.id.gsub('/', '\\/')} {\n#{source}\n}\n"
10
11
  end
@@ -1,6 +1,6 @@
1
1
  require 'json'
2
2
 
3
- LivingStyleGuide.add_filter :data do |data|
3
+ LivingStyleGuide.add_filter :data do |arguments, options, data|
4
4
  document.locals.merge! JSON.parse("{#{data}}")
5
5
  nil
6
6
  end
@@ -5,11 +5,11 @@ LivingStyleGuide.default_options[:font_example] = { text: <<-TEXT }
5
5
  !&/()$=@;:,.
6
6
  TEXT
7
7
 
8
- LivingStyleGuide.add_filter :font_example do |font, text = nil|
8
+ LivingStyleGuide.add_filter :font_example do |arguments, options, text|
9
9
  text ||= LivingStyleGuide.default_options[:font_example][:text]
10
10
  text = ERB::Util.html_escape(text)
11
11
  text.strip!
12
12
  text.gsub!(/\n/, "<br>\n")
13
- font = ERB::Util.html_escape(font)
13
+ font = ERB::Util.html_escape(arguments.first)
14
14
  ERB.new(File.read("#{File.dirname(__FILE__)}/../templates/font-example.html.erb")).result(binding)
15
15
  end
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :full_width do
1
+ LivingStyleGuide.add_filter :full_width do |arguments, options, block|
2
2
  document.classes << '-lsg-has-full-width'
3
3
  nil
4
4
  end
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :haml do
1
+ LivingStyleGuide.add_filter :haml do |arguments, options, block|
2
2
  document.type = :haml
3
3
  nil
4
4
  end
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :title do |title|
2
- document.title = title
1
+ LivingStyleGuide.add_filter :title do |arguments, options, block|
2
+ document.title = arguments.first
3
3
  nil
4
4
  end
@@ -1,6 +1,7 @@
1
1
  require 'tilt'
2
2
 
3
- LivingStyleGuide.add_filter :import do |glob, data = nil|
3
+ LivingStyleGuide.add_filter :import do |arguments, options, data|
4
+ glob = arguments.first
4
5
  if glob =~ /\.s[ac]ss$/
5
6
  raise "Error: Please use `@css #{glob}` instead of `@import #{glob}` for importing Sass."
6
7
  end
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :javascript do
1
+ LivingStyleGuide.add_filter :javascript do |arguments, options, block|
2
2
  document.type = :javascript
3
3
  document.template = :javascript
4
4
  nil
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :markdown do
1
+ LivingStyleGuide.add_filter :markdown do |arguments, options, block|
2
2
  document.type = :markdown
3
3
  nil
4
4
  end
@@ -1,8 +1,6 @@
1
- LivingStyleGuide.add_filter :set do |option|
2
- if option =~ /^([\w\-]+):\s+(.+)$/
3
- key, value = $1, $2
4
- key = key.downcase.gsub('-', '_').to_sym
5
- value = case value
1
+ LivingStyleGuide.add_filter :set do |arguments, options, block|
2
+ options.each do |key, value|
3
+ document.options[key] = case value
6
4
  when 'true'
7
5
  true
8
6
  when 'false'
@@ -12,7 +10,6 @@ LivingStyleGuide.add_filter :set do |option|
12
10
  else
13
11
  value
14
12
  end
15
- document.options[key] = value
16
13
  end
17
14
  nil
18
15
  end
@@ -1,4 +1,4 @@
1
- LivingStyleGuide.add_filter :require do |file|
2
- Kernel.require file
1
+ LivingStyleGuide.add_filter :require do |arguments, options, block|
2
+ Kernel.require arguments.first
3
3
  nil
4
4
  end
@@ -0,0 +1,7 @@
1
+ LivingStyleGuide.add_filter :style do |arguments, options, block|
2
+ options.delete :block_type
3
+ options.each do |key, value|
4
+ document.scss << %Q($livingstyleguide--#{key.to_s.gsub("_", "-")}: #{value};\n)
5
+ nil
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ LivingStyleGuide.add_filter :type do |arguments, options, block|
2
+ document.type = arguments.first.to_sym
3
+ nil
4
+ end
@@ -0,0 +1,3 @@
1
+ <section class="<%= classes.join(' ') %>" id="<%= id %>">
2
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><%= highlighted_source %></code></pre>
3
+ </section>
@@ -1,3 +1,3 @@
1
1
  module LivingStyleGuide
2
- VERSION = '2.0.0.alpha.4'
2
+ VERSION = '2.0.0.alpha.5'
3
3
  end
@@ -111,6 +111,8 @@
111
111
  background-color: $livingstyleguide--highlight-color;
112
112
  border-radius: $livingstyleguide--highlight-border-radius;
113
113
  display: inline;
114
+ font-style: inherit;
115
+ font-weight: inherit;
114
116
  vertical-align: baseline;
115
117
  }
116
118
 
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.4
4
+ version: 2.0.0.alpha.5
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-09 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minisyntax
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.2.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.2.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sass
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +124,20 @@ dependencies:
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: heredoc_unindent
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.2.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.2.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: minitest
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - ">="
@@ -137,7 +151,7 @@ dependencies:
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
- name: minitest
154
+ name: coffee-script
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - ">="
@@ -151,7 +165,7 @@ dependencies:
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
- name: coffee-script
168
+ name: i18n
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - ">="
@@ -194,12 +208,15 @@ files:
194
208
  - lib/livingstyleguide/filters/markdown.rb
195
209
  - lib/livingstyleguide/filters/options.rb
196
210
  - lib/livingstyleguide/filters/require.rb
211
+ - lib/livingstyleguide/filters/style.rb
212
+ - lib/livingstyleguide/filters/type.rb
197
213
  - lib/livingstyleguide/integration.rb
198
214
  - lib/livingstyleguide/integration/compass.rb
199
215
  - lib/livingstyleguide/integration/rails.rb
200
216
  - lib/livingstyleguide/integration/sass.rb
201
217
  - lib/livingstyleguide/integration/sprockets.rb
202
218
  - lib/livingstyleguide/markdown_extensions.rb
219
+ - lib/livingstyleguide/templates/code.html.erb
203
220
  - lib/livingstyleguide/templates/default.html.erb
204
221
  - lib/livingstyleguide/templates/example.html.erb
205
222
  - lib/livingstyleguide/templates/font-example.html.erb