livingstyleguide 2.0.0.alpha.3 → 2.0.0.alpha.4

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: 7a51a7d18383f9d9667786275263bc1b71af49b0
4
- data.tar.gz: a6ef46207a4b6add73873de1a2141629f8da8917
3
+ metadata.gz: 09fd1db6eea766e1fc9ce49ea9093fcba7cb5cf0
4
+ data.tar.gz: 9e677d67f85cea4e8067e25af350057599fb7b74
5
5
  SHA512:
6
- metadata.gz: 79e37f2e32f51c8478f69d0f958fc0a19a6dc187854ffd604bb9a6688ee0e14735b08167293bf7aa29b03d55d7c8972ad6243971b3a3b30b34016cfa2aadd14a
7
- data.tar.gz: 8b9f37570cecc6ebb507cdb703dee17c401e4761c16bfaa2afd92f325fed36a56614a3ef2e5473383c7f5ae59a961287c6603713ae1a45371cb36d5803eb7d5b
6
+ metadata.gz: 23abb326faa5c71f9432c9e44d677f12bcc29510e9ce9d13df4d316b1032e43d693798bd03c30be56eb70a573ea3e2f690499ac75303a6aa01e7d02f4af8e963
7
+ data.tar.gz: 197222fd5eb577683377373f5d0a1034d06c2874851076c0e7a7d494a594aa3de5ee05d34e3efec64dcb726a718d692659aa52cd8f7a95d8b7aee09399d95f9c
@@ -39,7 +39,18 @@ class LivingStyleGuide::Document < ::Tilt::Template
39
39
  end
40
40
 
41
41
  def source
42
- @source ||= set_highlights(erb.gsub(/<%.*?%>\n?/, ''))
42
+ @source ||= erb.gsub(/<%.*?%>\n?/, '').strip
43
+ end
44
+
45
+ def highlighted_source
46
+ set_highlights(source.strip) do |without_highlights|
47
+ if type == :plain
48
+ without_highlights
49
+ else
50
+ without_highlights = ERB::Util.h(without_highlights) if type == :html
51
+ ::MiniSyntax.highlight(without_highlights, type)
52
+ end
53
+ end.gsub("\n", "<br>")
43
54
  end
44
55
 
45
56
  def css
@@ -62,7 +73,6 @@ class LivingStyleGuide::Document < ::Tilt::Template
62
73
 
63
74
  def evaluate(scope, locals, &block)
64
75
  @scope = scope
65
- depend_on file if file and options.has_key?(:livingstyleguide)
66
76
  result = ERB.new(erb).result(@filters.get_binding)
67
77
  @html = case @type
68
78
  when :plain, :example, :html, :javascript
@@ -85,14 +95,64 @@ class LivingStyleGuide::Document < ::Tilt::Template
85
95
  end
86
96
 
87
97
  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>))
98
+ def set_highlights(code, &block)
99
+ code, positions = remove_highlight_marker_and_save_positions(code)
100
+ html = yield(code)
101
+ insert_html_highlight_marker(html, positions)
102
+ end
103
+
104
+ private
105
+ def remove_highlight_marker_and_save_positions(code)
106
+ positions = []
107
+ index = 0
108
+ code_without_highlights = code.gsub(/(.*?)\*\*\*/m) do
109
+ positions << index += $1.length
110
+ $1
111
+ end
112
+ [code_without_highlights, positions]
113
+ end
114
+
115
+ private
116
+ def insert_html_highlight_marker(html, positions)
117
+ code_with_highlights = ""
118
+ index = 0
119
+ next_position = positions.shift
120
+ inside_highlight = false
121
+ inside_character = false
122
+ inside_html = false
123
+ html.each_char do |char|
124
+ if char == "<"
125
+ inside_html = true
126
+ elsif char == ">"
127
+ inside_html = false
128
+ elsif not inside_html
129
+ if index == next_position
130
+ if inside_highlight
131
+ code_with_highlights << %Q(</strong>)
132
+ inside_highlight = false
133
+ else
134
+ code_with_highlights << %Q(<strong class="livingstyleguide--code-highlight">)
135
+ inside_highlight = true
136
+ end
137
+ next_position = positions.shift
138
+ end
139
+ if char == "&"
140
+ inside_character = true
141
+ elsif inside_character and char == ";"
142
+ inside_character = false
143
+ index += 1
144
+ elsif not inside_character
145
+ index += 1
146
+ end
147
+ end
148
+ code_with_highlights << char
149
+ end
150
+ code_with_highlights
91
151
  end
92
152
 
93
153
  private
94
154
  def remove_highlights(code)
95
- code.gsub(/\*\*\*(.+?)\*\*\*/m, '\\1')
155
+ code.gsub(/\*\*\*/, '')
96
156
  end
97
157
 
98
158
  private
@@ -104,7 +164,7 @@ class LivingStyleGuide::Document < ::Tilt::Template
104
164
  def parse_filters
105
165
  data.gsub('<%', '<%%').gsub(/\G(.*?)((```.+?```)|\Z)/m) do
106
166
  content, code_block = $1, $2
107
- content.gsub(/^@([\w\d_-]+)(?: ([^\{\n]+))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*\n)+))?/) do
167
+ content.gsub(/^@([\w\d_-]+)(?: ([^\{\n]+))?(?: *\{\n((?:.|\n)*?)\n\}|\n((?: .*(\n|\Z))+))?/) do
108
168
  name, arguments, block = $1, $2 || '', $3 || $4
109
169
  name = name.gsub('-', '_').to_sym
110
170
  arguments = arguments.split(',').map(&:strip)
@@ -159,6 +219,12 @@ class LivingStyleGuide::Document < ::Tilt::Template
159
219
  private
160
220
  def render_scss(scss)
161
221
  sass_options = options.merge(custom: { sprockets_context: @scope })
222
+ if defined?(Compass)
223
+ sass_options[:load_paths] ||= []
224
+ Compass.sass_engine_options[:load_paths].each do |path|
225
+ sass_options[:load_paths] << path
226
+ end
227
+ end
162
228
  scss_template.new(file, sass_options){ scss }.render(@scope)
163
229
  end
164
230
  end
@@ -18,6 +18,7 @@ end
18
18
 
19
19
  require 'livingstyleguide/filters/options'
20
20
  require 'livingstyleguide/filters/import'
21
+ require 'livingstyleguide/filters/require'
21
22
  require 'livingstyleguide/filters/full_width'
22
23
  require 'livingstyleguide/filters/haml'
23
24
  require 'livingstyleguide/filters/markdown'
@@ -26,5 +27,6 @@ require 'livingstyleguide/filters/coffee_script'
26
27
  require 'livingstyleguide/filters/add_wrapper_class'
27
28
  require 'livingstyleguide/filters/font_example'
28
29
  require 'livingstyleguide/filters/colors'
29
- require 'livingstyleguide/filters/scss'
30
+ require 'livingstyleguide/filters/css'
30
31
  require 'livingstyleguide/filters/data'
32
+ require 'livingstyleguide/filters/html_head'
@@ -0,0 +1,12 @@
1
+ LivingStyleGuide.add_filter :css, :scss do |source|
2
+ if source =~ /\.(css|scss|sass)$/
3
+ if document.file
4
+ source = File.join(File.dirname(document.file), source)
5
+ end
6
+ document.depend_on source
7
+ document.scss << %Q(@import "#{source}";\n)
8
+ else
9
+ document.scss << "##{document.id.gsub('/', '\\/')} {\n#{source}\n}\n"
10
+ end
11
+ nil
12
+ end
@@ -0,0 +1,4 @@
1
+ LivingStyleGuide.add_filter :title do |title|
2
+ document.title = title
3
+ nil
4
+ end
@@ -1,6 +1,9 @@
1
1
  require 'tilt'
2
2
 
3
3
  LivingStyleGuide.add_filter :import do |glob, data = nil|
4
+ if glob =~ /\.s[ac]ss$/
5
+ raise "Error: Please use `@css #{glob}` instead of `@import #{glob}` for importing Sass."
6
+ end
4
7
  glob << '.lsg' unless glob =~ /\.(\w+|\*)$/
5
8
  glob.gsub!(/[^\/]+$/, '{_,}\\0')
6
9
  if document.file
@@ -8,17 +11,14 @@ LivingStyleGuide.add_filter :import do |glob, data = nil|
8
11
  end
9
12
 
10
13
  if data
11
- require 'json'
14
+ Kernel.require 'json'
12
15
  data = JSON.parse("{#{data}}")
13
16
  end
14
17
 
15
18
  Dir.glob(glob).map do |file|
16
- if file =~ /\.s[ac]ss$/
17
- document.depend_on file
18
- document.scss << %Q(@import "#{file}";\n)
19
- nil
20
- else
21
- ::Tilt.new(file, livingstyleguide: document).render(document.scope, data)
22
- end
19
+ document.depend_on file
20
+ html = ::Tilt.new(file, livingstyleguide: document).render(document.scope, data)
21
+ html.gsub!("\n", "\n ")
22
+ "\n<div>\n#{html}\n</div>\n"
23
23
  end.join
24
24
  end
@@ -0,0 +1,4 @@
1
+ LivingStyleGuide.add_filter :require do |file|
2
+ Kernel.require file
3
+ nil
4
+ end
@@ -2,7 +2,5 @@
2
2
  <div class="livingstyleguide--html">
3
3
  <%= html %>
4
4
  </div>
5
- <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><%=
6
- [:plain].index(type) ? source : ::MiniSyntax.highlight(type == :html ? ERB::Util.h(source) : source, type)
7
- %></code></pre>
5
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><%= highlighted_source %></code></pre>
8
6
  </section>
@@ -1,6 +1,4 @@
1
1
  <section class="<%= classes.join(' ') %>" id="<%= id %>">
2
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>
3
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><%= highlighted_source %></code></pre>
6
4
  </section>
@@ -1,3 +1,3 @@
1
1
  module LivingStyleGuide
2
- VERSION = '2.0.0.alpha.3'
2
+ VERSION = '2.0.0.alpha.4'
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.3
4
+ version: 2.0.0.alpha.4
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-02-09 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minisyntax
@@ -183,15 +183,17 @@ files:
183
183
  - lib/livingstyleguide/filters/add_wrapper_class.rb
184
184
  - lib/livingstyleguide/filters/coffee_script.rb
185
185
  - lib/livingstyleguide/filters/colors.rb
186
+ - lib/livingstyleguide/filters/css.rb
186
187
  - lib/livingstyleguide/filters/data.rb
187
188
  - lib/livingstyleguide/filters/font_example.rb
188
189
  - lib/livingstyleguide/filters/full_width.rb
189
190
  - lib/livingstyleguide/filters/haml.rb
191
+ - lib/livingstyleguide/filters/html_head.rb
190
192
  - lib/livingstyleguide/filters/import.rb
191
193
  - lib/livingstyleguide/filters/javascript.rb
192
194
  - lib/livingstyleguide/filters/markdown.rb
193
195
  - lib/livingstyleguide/filters/options.rb
194
- - lib/livingstyleguide/filters/scss.rb
196
+ - lib/livingstyleguide/filters/require.rb
195
197
  - lib/livingstyleguide/integration.rb
196
198
  - lib/livingstyleguide/integration/compass.rb
197
199
  - lib/livingstyleguide/integration/rails.rb
@@ -236,3 +238,4 @@ signing_key:
236
238
  specification_version: 4
237
239
  summary: Generate beautiful front-end style guides
238
240
  test_files: []
241
+ has_rdoc:
@@ -1,4 +0,0 @@
1
- LivingStyleGuide.add_filter :scss do |source|
2
- document.scss << "##{document.id.gsub('/', '\\/')} {\n#{source}\n}\n"
3
- nil
4
- end