livingstyleguide 1.1.1 → 1.2.0.pre.1

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: 56208f284daa1f7b7353302654d9f5afa13092e7
4
- data.tar.gz: fe9bae1832214c6ac1bf2fbf44989745ab08b2b7
3
+ metadata.gz: 86825c04643629696331540ff589ba16fb57d592
4
+ data.tar.gz: 8b7c01b7e88a6bfd3af8ba4616d7101a5928ce4f
5
5
  SHA512:
6
- metadata.gz: b8d0caf0f12defe2d316f2f89d4807473be7ab9981ef4eb489df7e29a1509a6cc2cfcda62cbf92ba30a9e5b0a4243490c90fb88dd1735fb34d9bd64060c6777c
7
- data.tar.gz: 4e10438988bde6607deb69d2cd796d8213c713763683ffbbf3899c59601bfa4a2f1e97a54bac8ac92da163844f0a1b1d28afca20486e9f3b3bee5770831afada
6
+ metadata.gz: 5cacdc1aca7c7da0e9bd6a5b65877daa7ec01eab7b52f438c502fd7b19b12a5a1c8d12dd16634aa1003ef5921f1bdb2fb4b5ed03cf2fd8861bc4ee69910fbae2
7
+ data.tar.gz: 278a316fe32545e1c046e7be77f1f2fb2e2f5690553e5fcd6ddd712e2dfe61ca2e2c14adddbec0d4ddb2375368ef8444421d3da1a90307a23c5b7a257d55b58b
@@ -1,5 +1,8 @@
1
1
  require 'rubygems'
2
+ begin
2
3
  require 'bundler/setup'
4
+ rescue LoadError
5
+ end
3
6
  require 'thor'
4
7
  require 'tilt'
5
8
 
@@ -8,10 +11,12 @@ module LivingStyleGuide
8
11
 
9
12
  desc 'compile filename', 'Compiles the living style guide to HTML.'
10
13
  def compile(file)
11
- Compass.add_project_configuration
12
- html = Tilt.new(file).render
13
14
  output_file = file.sub(/\.lsg$/, '')
14
- output_file.sub! /^#{Compass.configuration.sass_dir}/, Compass.configuration.css_dir
15
+ if defined?(Compass)
16
+ Compass.add_project_configuration
17
+ output_file.sub! /^#{Compass.configuration.sass_dir}/, Compass.configuration.css_dir
18
+ end
19
+ html = Tilt.new(file).render
15
20
  File.write output_file, html
16
21
  puts "Successfully generated a living style guide at #{output_file}."
17
22
  end
@@ -1,7 +1,7 @@
1
1
  module LivingStyleGuide
2
2
 
3
3
  class Engine
4
- attr_accessor :markdown, :files, :options
4
+ attr_accessor :markdown, :files, :options, :variables
5
5
 
6
6
  @@default_options = {
7
7
  default_language: 'example',
@@ -15,18 +15,41 @@ module LivingStyleGuide
15
15
  @@default_options
16
16
  end
17
17
 
18
- def initialize(source, options, sass_options)
19
- @source = source
18
+ def initialize(options, sass_options)
20
19
  @options = @@default_options.merge(options)
21
20
  @sass_options = sass_options
22
- @markdown = ''
21
+ @variables = {}
23
22
  @files = []
23
+ @markdown = ''
24
24
  end
25
25
 
26
26
  def render
27
- data = TemplateData.new(self)
28
- template = File.read(File.join(File.dirname(__FILE__), '..', '..', 'templates', 'layouts', 'default.html.erb'))
29
- ERB.new(template).result(data.get_binding)
27
+ template('layout.html.erb')
28
+ end
29
+
30
+ def files
31
+ collect_data if @files.empty?
32
+ @files
33
+ end
34
+
35
+ def variables
36
+ collect_data if @variables.empty?
37
+ @variables
38
+ end
39
+
40
+ def markdown
41
+ generate_markdown if @markdown.empty?
42
+ @markdown
43
+ end
44
+
45
+ def sass
46
+ separator = @options[:syntax] == :sass ? "\n" : ';'
47
+ [
48
+ %Q(@import "#{@options[:source]}"),
49
+ style_variables,
50
+ %Q(@import "livingstyleguide"),
51
+ @options[:styleguide_sass] || @options[:styleguide_scss]
52
+ ].flatten.join(separator)
30
53
  end
31
54
 
32
55
  def css
@@ -34,17 +57,97 @@ module LivingStyleGuide
34
57
  end
35
58
 
36
59
  def html
37
- renderer = RedcarpetHTML.new(@options)
60
+ renderer = RedcarpetHTML.new(@options, self)
38
61
  redcarpet = ::Redcarpet::Markdown.new(renderer, REDCARPET_RENDER_OPTIONS)
39
62
  redcarpet.render(markdown)
40
63
  end
41
64
 
65
+ private
66
+ def collect_data
67
+ traverse_children sass_engine.to_tree
68
+ end
69
+
70
+ private
71
+ def traverse_children(node)
72
+ node.children.each do |child|
73
+ if child.is_a?(Sass::Tree::ImportNode)
74
+ add_file child.imported_file.to_tree
75
+ elsif child.is_a?(Sass::Tree::VariableNode)
76
+ add_variable child
77
+ end
78
+ end
79
+ end
80
+
81
+ private
82
+ def add_file(node)
83
+ filename = File.expand_path(node.filename)
84
+ if local_sass_file?(filename)
85
+ @files << filename
86
+ traverse_children node
87
+ end
88
+ end
89
+
90
+ private
91
+ def add_variable(node)
92
+ key = import_filename(node.filename)
93
+ @variables[key] ||= []
94
+ @variables[key] << node.name
95
+ end
96
+
97
+ private
98
+ def local_sass_file?(filename)
99
+ @local_sass_file_regexp ||= /^#{File.expand_path(@options[:root])}\/.+\.s[ac]ss$/
100
+ filename =~ @local_sass_file_regexp
101
+ end
102
+
103
+ private
104
+ def import_filename(filename)
105
+ @import_filename_regexp ||= /(?<=^|\/)_?([^\/]+?)\.s[ac]ss$/
106
+ filename.sub(@import_filename_regexp, '\\1')
107
+ end
108
+
42
109
  private
43
110
  def sass_engine
44
111
  return @sass_engine if @sass_engine
45
112
  sass_options = @sass_options.clone
46
113
  sass_options[:living_style_guide] = self
47
- @sass_engine = ::Sass::Engine.new(@source, sass_options)
114
+ @sass_engine = ::Sass::Engine.new(sass, sass_options)
115
+ collect_data
116
+ @sass_engine.to_tree << output_variables
117
+ @sass_engine
118
+ end
119
+
120
+ private
121
+ def output_variables
122
+ scss = template('variables.scss.erb')
123
+ ::Sass::Engine.new(scss, syntax: :scss).to_tree.children
124
+ end
125
+
126
+ private
127
+ def style_variables
128
+ return unless @options.has_key?(:style)
129
+ @options[:style].map do |key, value|
130
+ "$livingstyleguide--#{key}: #{value}"
131
+ end
132
+ end
133
+
134
+ private
135
+ def generate_markdown
136
+ files.clone.each do |sass_filename|
137
+ next unless sass_filename.is_a?(String)
138
+ glob = "#{sass_filename.sub(/\.s[ac]ss$/, '')}.md"
139
+ Dir.glob(glob) do |markdown_filename|
140
+ files << markdown_filename
141
+ @markdown << File.read(markdown_filename)
142
+ end
143
+ end
144
+ end
145
+
146
+ private
147
+ def template(filename)
148
+ data = TemplateData.new(self)
149
+ erb = File.read(File.join(File.dirname(__FILE__), 'templates', filename))
150
+ ERB.new(erb).result(data.get_binding)
48
151
  end
49
152
 
50
153
  end
@@ -68,6 +171,10 @@ module LivingStyleGuide
68
171
  @engine.css
69
172
  end
70
173
 
174
+ def variables
175
+ @engine.variables
176
+ end
177
+
71
178
  def html
72
179
  @engine.html
73
180
  end
@@ -10,11 +10,12 @@ class LivingStyleGuide::Example
10
10
  FILTER_REGEXP = /^@([a-z\-_]+)(?:\s+(.+?))?$/
11
11
 
12
12
  define_hooks :filter_before, :filter_after, :html, :pre_processor
13
- attr_reader :options
13
+ attr_reader :options, :engine
14
14
  @@filters = {}
15
15
 
16
- def initialize(input, options = {})
16
+ def initialize(input, options, engine)
17
17
  @options = { default_filters: [] }.merge(options)
18
+ @engine = engine
18
19
  @source = input
19
20
  @wrapper_classes = %w(livingstyleguide--example)
20
21
  @syntax = :html
@@ -3,7 +3,7 @@ LivingStyleGuide::Example.add_filter :colors do |file|
3
3
 
4
4
 
5
5
  if file
6
- colors = [LivingStyleGuide::VariablesImporter.variables(file)]
6
+ colors = [engine.variables[file]]
7
7
  else
8
8
  colors = []
9
9
  end
@@ -1,5 +1,5 @@
1
- Compass.configuration.add_import_path LivingStyleGuide::VariablesImporter.new
2
-
3
- base_directory = File.join(File.dirname(__FILE__), '..', '..', '..')
4
- Compass::Frameworks.register 'livingstyleguide', path: base_directory
1
+ if defined?(Compass)
2
+ base_directory = File.join(File.dirname(__FILE__), '..', '..', '..')
3
+ Compass::Frameworks.register 'livingstyleguide', path: base_directory
4
+ end
5
5
 
@@ -3,7 +3,7 @@ if defined?(Rails) and defined?(Rails::Railtie)
3
3
  require 'rails'
4
4
  class LivingStyleGuideRailtie < Rails::Railtie
5
5
  initializer 'living_style_guide.assets' do
6
- Rails.application.assets.register_engine('.lsg', ::Tilt::LivingStyleGuideTemplate)
6
+ Rails.application.assets.register_engine('.lsg', ::LivingStyleGuide::TiltTemplate)
7
7
  end
8
8
  end
9
9
 
@@ -1,6 +1,6 @@
1
1
  begin
2
2
  require 'sprockets'
3
- Sprockets.register_engine('.lsg', ::Tilt::LivingStyleGuideTemplate)
3
+ Sprockets.register_engine('.lsg', ::LivingStyleGuide::TiltTemplate)
4
4
  rescue LoadError
5
5
  end
6
6
 
@@ -15,9 +15,10 @@ module LivingStyleGuide
15
15
 
16
16
  class RedcarpetHTML < ::Redcarpet::Render::HTML
17
17
 
18
- def initialize(options = {})
18
+ def initialize(options = {}, engine)
19
19
  @options = options
20
- super
20
+ @engine = engine
21
+ super @options
21
22
  end
22
23
 
23
24
  def header(text, header_level)
@@ -43,7 +44,7 @@ module LivingStyleGuide
43
44
  def block_code(code, language)
44
45
  language ||= @options[:default_language]
45
46
  if language == 'example'
46
- Example.new(code, @options).render
47
+ Example.new(code, @options, @engine).render
47
48
  else
48
49
  CodeBlock.new(code.strip, language.to_s.strip.to_sym).render
49
50
  end
@@ -1,8 +1,9 @@
1
1
  module LivingStyleGuide::SassExtensions::Functions
2
2
 
3
3
  def list_variables(uri)
4
+ Sass::Util.sass_warn '`list-variables()` is depricated and will be removed in v2.0.0.'
4
5
  uri = uri.value
5
- variables = LivingStyleGuide::VariablesImporter.variables(uri)
6
+ variables = parse_variables(uri)
6
7
  variables.map! do |name|
7
8
  Sass::Script::String.new(name)
8
9
  end
@@ -15,5 +16,25 @@ module LivingStyleGuide::SassExtensions::Functions
15
16
  end
16
17
  end
17
18
 
19
+ private
20
+ def parse_variables(uri)
21
+ uri = uri.dup
22
+ uri += '.s?ss' unless uri =~ /\.s[ac]ss$/
23
+ uri.gsub! %r{^(.*)/(.+)$}, '\1/{_,}\2'
24
+ variables = []
25
+ paths = [Compass.configuration.sass_path, Compass.configuration.additional_import_paths].flatten
26
+ paths.each do |path|
27
+ if path.is_a? String
28
+ Dir.glob(File.join(path, uri)).each do |file|
29
+ sass = File.read(file)
30
+ variables << sass.scan(%r(\$([a-z0-9\-_]+)\s*:))
31
+ end
32
+ end
33
+ end
34
+ variables.flatten!
35
+ variables.uniq!
36
+ variables
37
+ end
38
+
18
39
  end
19
40
 
@@ -4,7 +4,7 @@
4
4
  }
5
5
  <% end %>
6
6
 
7
- <% variables.each do |variable| %>
7
+ <% variables.values.flatten.each do |variable| %>
8
8
  $<%= variable %>: null !default;
9
9
  @if $<%= variable %> != null {//and type-of($<%= variable %>) != map {
10
10
  .\$<%= variable %> {
@@ -1,11 +1,10 @@
1
1
  require 'tilt'
2
2
  require 'erb'
3
- require 'compass'
4
3
  require 'yaml'
5
4
  require 'json'
6
5
 
7
- module ::Tilt
8
- class LivingStyleGuideTemplate < Template
6
+ module LivingStyleGuide
7
+ class TiltTemplate < ::Tilt::Template
9
8
  self.default_mime_type = 'text/html'
10
9
 
11
10
  def prepare
@@ -14,23 +13,28 @@ module ::Tilt
14
13
  def evaluate(scope, locals, &block)
15
14
  @scope = scope
16
15
  parse_options(data)
17
- generate_sass
18
16
  render_living_style_guide
19
17
  end
20
18
 
21
19
  private
22
20
  def sass_options
23
- options = Compass.configuration.to_sass_plugin_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
24
27
  if defined?(Rails)
25
- options[:load_paths] = options[:load_paths] | Rails.application.config.assets.paths
28
+ options[:load_paths] += Rails.application.config.assets.paths
26
29
  end
27
- options[:template_location].each do |path, short|
28
- options[:load_paths] << ::LivingStyleGuide::Importer.new(path)
30
+ if options[:template_location]
31
+ options[:template_location].each do |path, short|
32
+ options[:load_paths] << path
33
+ end
29
34
  end
30
35
  options[:filename] = eval_file
31
36
  options[:line] = line
32
37
  options[:syntax] = @options[:syntax]
33
- options[:importer] = LivingStyleGuide::Importer.new('.')
34
38
  options[:sprockets] = { context: @scope }
35
39
  options[:custom] = { sprockets_context: @scope }
36
40
  options
@@ -50,25 +54,11 @@ module ::Tilt
50
54
  @options[:root] ||= root
51
55
  end
52
56
 
53
- private
54
- def generate_sass
55
- @sass = [
56
- %Q(@import "#{@options[:source]}"),
57
- style_variables,
58
- %Q(@import "livingstyleguide"),
59
- %Q(@import "#{::LivingStyleGuide::VariablesImporter::VARIABLE_IMPORTER_STRING}"),
60
- @options[:styleguide_sass] || @options[:styleguide_scss]
61
- ].flatten.join(@options[:syntax] == :sass ? "\n" : ';')
62
- end
63
-
64
57
  private
65
58
  def configure_cache
66
59
  return unless @scope.respond_to?(:depend_on)
67
- test = /^#{root}/
68
60
  @engine.files.uniq.each do |file|
69
- if file =~ test
70
- @scope.depend_on file
71
- end
61
+ @scope.depend_on file
72
62
  end
73
63
  end
74
64
 
@@ -93,23 +83,15 @@ module ::Tilt
93
83
  path
94
84
  end
95
85
 
96
- private
97
- def style_variables
98
- return unless @options.has_key?(:style)
99
- @options[:style].map do |key, value|
100
- "$livingstyleguide--#{key}: #{value}"
101
- end
102
- end
103
-
104
86
  private
105
87
  def render_living_style_guide
106
- @engine = ::LivingStyleGuide::Engine.new(@sass, @options, sass_options)
88
+ @engine = ::LivingStyleGuide::Engine.new(@options, sass_options)
107
89
  html = @engine.render
108
90
  configure_cache
109
91
  html
110
92
  end
111
93
  end
112
-
113
- register 'lsg', LivingStyleGuideTemplate
114
94
  end
115
95
 
96
+ Tilt.register 'lsg', LivingStyleGuide::TiltTemplate
97
+
@@ -1,3 +1,3 @@
1
1
  module LivingStyleGuide
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0.pre.1'
3
3
  end
@@ -1,10 +1,12 @@
1
+ begin
2
+ require 'compass'
3
+ rescue LoadError
4
+ end
5
+
1
6
  require 'livingstyleguide/version'
2
- require 'compass'
3
7
  require 'livingstyleguide/filter_hooks'
4
8
  require 'livingstyleguide/sass_extensions'
5
9
  require 'livingstyleguide/engine'
6
- require 'livingstyleguide/variables_importer'
7
- require 'livingstyleguide/importer'
8
10
  require 'livingstyleguide/markdown_extensions'
9
11
  require 'livingstyleguide/tilt_template'
10
12
  require 'livingstyleguide/code_block'
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: 1.1.1
4
+ version: 1.2.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Hagenburger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
11
+ date: 2014-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minisyntax
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: compass
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: sass
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +94,20 @@ dependencies:
108
94
  - - '='
109
95
  - !ruby/object:Gem::Version
110
96
  version: 0.3.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: compass
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -204,7 +204,6 @@ files:
204
204
  - lib/livingstyleguide/filters/haml.rb
205
205
  - lib/livingstyleguide/filters/highlights.rb
206
206
  - lib/livingstyleguide/filters/javascript.rb
207
- - lib/livingstyleguide/importer.rb
208
207
  - lib/livingstyleguide/integration.rb
209
208
  - lib/livingstyleguide/integration/compass.rb
210
209
  - lib/livingstyleguide/integration/rails.rb
@@ -212,16 +211,15 @@ files:
212
211
  - lib/livingstyleguide/markdown_extensions.rb
213
212
  - lib/livingstyleguide/sass_extensions.rb
214
213
  - lib/livingstyleguide/sass_extensions/functions.rb
214
+ - lib/livingstyleguide/templates/layout.html.erb
215
+ - lib/livingstyleguide/templates/variables.scss.erb
215
216
  - lib/livingstyleguide/tilt_template.rb
216
- - lib/livingstyleguide/variables_importer.rb
217
- - lib/livingstyleguide/variables_importer/content.erb
218
217
  - lib/livingstyleguide/version.rb
219
218
  - stylesheets/_livingstyleguide.scss
220
219
  - stylesheets/livingstyleguide/_code.scss
221
220
  - stylesheets/livingstyleguide/_color-swatches.scss
222
221
  - stylesheets/livingstyleguide/_content.scss
223
222
  - stylesheets/livingstyleguide/_layout.scss
224
- - templates/layouts/default.html.erb
225
223
  homepage: http://livingstyleguide.org
226
224
  licenses: []
227
225
  metadata: {}
@@ -236,9 +234,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
234
  version: '0'
237
235
  required_rubygems_version: !ruby/object:Gem::Requirement
238
236
  requirements:
239
- - - ">="
237
+ - - ">"
240
238
  - !ruby/object:Gem::Version
241
- version: '0'
239
+ version: 1.3.1
242
240
  requirements: []
243
241
  rubyforge_project:
244
242
  rubygems_version: 2.2.2
@@ -1,40 +0,0 @@
1
- class LivingStyleGuide::Importer < Sass::Importers::Filesystem
2
-
3
- def initialize(root)
4
- super(root)
5
- end
6
-
7
- def find_relative(name, base, options, absolute = false)
8
- @options = options
9
- engine = super(name, base, options)
10
- find_markdown(options[:filename])
11
- engine
12
- end
13
-
14
- def find(name, options)
15
- @options = options
16
- super(name, options)
17
- end
18
-
19
- private
20
- def find_markdown(sass_filename)
21
- files << sass_filename
22
- glob = "#{sass_filename.sub(/\.s[ac]ss$/, '')}.md"
23
- Dir.glob(glob) do |markdown_filename|
24
- files << markdown_filename
25
- markdown << File.read(markdown_filename)
26
- end
27
- end
28
-
29
- private
30
- def files
31
- @options[:living_style_guide].files
32
- end
33
-
34
- private
35
- def markdown
36
- @options[:living_style_guide].markdown
37
- end
38
-
39
- end
40
-
@@ -1,96 +0,0 @@
1
- require 'erb'
2
- require 'ostruct'
3
- require 'compass'
4
-
5
- module LivingStyleGuide
6
- class VariablesImporter < Sass::Importers::Base
7
- VALID_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
8
- VARIABLE_IMPORTER_STRING = 'LivingStyleGuide::VariablesImporter'
9
- VALID_EXTENSIONS = %w(*.sass *.scss)
10
-
11
- TEMPLATE_FOLDER = File.join(File.expand_path('../', __FILE__), 'variables_importer')
12
- CONTENT_TEMPLATE_FILE = File.join(TEMPLATE_FOLDER, 'content.erb')
13
- CONTENT_TEMPLATE = ERB.new(File.read(CONTENT_TEMPLATE_FILE))
14
-
15
- def find(uri, options)
16
- if uri =~ /^#{VARIABLE_IMPORTER_STRING}$/
17
- @options = options
18
- return self.class.sass_engine(uri, all_variables, self, options)
19
- end
20
- nil
21
- end
22
-
23
- def find_relative(uri, base, options)
24
- nil
25
- end
26
-
27
- def to_s
28
- self.class.name
29
- end
30
-
31
- def hash
32
- self.class.name.hash
33
- end
34
-
35
- def eql?(other)
36
- other.class == self.class
37
- end
38
-
39
- def key(uri, options={})
40
- [self.class.name + ":variables:" + File.dirname(File.expand_path(uri)), File.basename(uri)]
41
- end
42
-
43
- def self.variables(uri)
44
- uri = uri.dup
45
- uri += '.s?ss' unless uri =~ /\.s[ac]ss$/
46
- uri.gsub! %r{^(.*)/(.+)$}, '\1/{_,}\2'
47
- variables = []
48
- paths = [Compass.configuration.sass_path, Compass.configuration.additional_import_paths].flatten
49
- paths.each do |path|
50
- if path.is_a? String
51
- Dir.glob(File.join(path, uri)).each do |file|
52
- sass = File.read(file)
53
- variables << sass.scan(%r(\$([a-z0-9\-_]+)\s*:))
54
- end
55
- end
56
- end
57
- variables.flatten!
58
- variables.uniq!
59
- variables
60
- end
61
-
62
- def all_variables
63
- variables = []
64
- test = /^#{File.expand_path(@options[:living_style_guide].options[:root])}/
65
- @options[:living_style_guide].files.each do |file|
66
- if File.expand_path(file) =~ test
67
- sass = File.read(file)
68
- variables << sass.scan(%r(\$([a-z\-_]+)\s*:))
69
- end
70
- end
71
- variables.flatten!
72
- variables.uniq!
73
- variables
74
- end
75
-
76
- def self.sass_options(uri, importer, options)
77
- options.merge! :filename => uri.gsub(%r{\*/},"*\\/"), :syntax => :scss, :importer => importer
78
- end
79
-
80
- def self.sass_engine(uri, name, importer, options)
81
- content = content_for_images(uri, name, options[:skip_overrides])
82
- Sass::Engine.new(content, sass_options(uri, importer, options))
83
- end
84
-
85
- def self.content_for_images(uri, variables, skip_overrides = false)
86
- binder = LivingStyleGuide::Binding.new(:variables => variables)
87
- CONTENT_TEMPLATE.result(binder.get_binding)
88
- end
89
- end
90
-
91
- class Binding < OpenStruct
92
- def get_binding
93
- binding
94
- end
95
- end
96
- end