livingstyleguide 2.0.0.alpha.10 → 2.0.0.alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/livingstyleguide +5 -6
- data/lib/livingstyleguide.rb +18 -12
- data/lib/livingstyleguide/command_line_interface.rb +5 -6
- data/lib/livingstyleguide/commands.rb +39 -0
- data/lib/livingstyleguide/commands/add_wrapper_class.rb +4 -0
- data/lib/livingstyleguide/commands/coffee_script.rb +5 -0
- data/lib/livingstyleguide/{filters → commands}/colors.rb +1 -1
- data/lib/livingstyleguide/{filters → commands}/css.rb +1 -1
- data/lib/livingstyleguide/{filters → commands}/data.rb +1 -1
- data/lib/livingstyleguide/{filters → commands}/default.rb +1 -1
- data/lib/livingstyleguide/{filters → commands}/font_example.rb +2 -2
- data/lib/livingstyleguide/commands/full_width.rb +4 -0
- data/lib/livingstyleguide/commands/haml.rb +4 -0
- data/lib/livingstyleguide/{filters → commands}/import_and_use.rb +5 -5
- data/lib/livingstyleguide/{filters → commands}/javascript.rb +1 -1
- data/lib/livingstyleguide/{filters → commands}/layout.rb +4 -4
- data/lib/livingstyleguide/commands/markdown.rb +4 -0
- data/lib/livingstyleguide/{filters → commands}/options.rb +3 -3
- data/lib/livingstyleguide/commands/require.rb +4 -0
- data/lib/livingstyleguide/{filters → commands}/sass.rb +4 -2
- data/lib/livingstyleguide/commands/search_box.rb +10 -0
- data/lib/livingstyleguide/{filters → commands}/style.rb +1 -1
- data/lib/livingstyleguide/commands/syntax.rb +4 -0
- data/lib/livingstyleguide/commands/toggle_code.rb +4 -0
- data/lib/livingstyleguide/commands/type.rb +4 -0
- data/lib/livingstyleguide/document.rb +29 -26
- data/lib/livingstyleguide/integration.rb +4 -4
- data/lib/livingstyleguide/integration/compass.rb +2 -3
- data/lib/livingstyleguide/integration/rails.rb +3 -6
- data/lib/livingstyleguide/integration/sass.rb +1 -1
- data/lib/livingstyleguide/integration/sprockets.rb +2 -3
- data/lib/livingstyleguide/markdown_extensions.rb +9 -9
- data/lib/livingstyleguide/templates/code.html.erb +1 -1
- data/lib/livingstyleguide/templates/example.html.erb +1 -1
- data/lib/livingstyleguide/templates/javascript.html.erb +1 -1
- data/lib/livingstyleguide/templates/layout.html.erb +13 -1
- data/lib/livingstyleguide/templates/scripts/copy.js.erb +24 -0
- data/lib/livingstyleguide/templates/scripts/copy_code.js.erb +19 -0
- data/lib/livingstyleguide/templates/scripts/copy_colors.js.erb +36 -0
- data/lib/livingstyleguide/templates/scripts/search.js.erb +66 -0
- data/lib/livingstyleguide/templates/scripts/toggle_code.js.erb +53 -0
- data/lib/livingstyleguide/templates/search-box.html.erb +1 -68
- data/lib/livingstyleguide/templates/toggle-code.html.erb +1 -0
- data/lib/livingstyleguide/version.rb +1 -1
- data/stylesheets/_livingstyleguide.scss +6 -3
- data/stylesheets/livingstyleguide/_before.scss +10 -0
- data/stylesheets/livingstyleguide/_code.scss +4 -7
- data/stylesheets/livingstyleguide/_color-swatches.scss +15 -16
- data/stylesheets/livingstyleguide/_content.scss +5 -5
- data/stylesheets/livingstyleguide/_layout.scss +4 -3
- data/stylesheets/livingstyleguide/_reset.scss +2 -1
- data/stylesheets/livingstyleguide/_toggle-code.scss +21 -0
- data/stylesheets/livingstyleguide/_variables.scss +5 -1
- metadata +46 -29
- data/assets/javascripts/livingstyleguide.js +0 -75
- data/lib/livingstyleguide/engine.rb +0 -194
- data/lib/livingstyleguide/filters.rb +0 -38
- data/lib/livingstyleguide/filters/add_wrapper_class.rb +0 -4
- data/lib/livingstyleguide/filters/coffee_script.rb +0 -5
- data/lib/livingstyleguide/filters/full_width.rb +0 -4
- data/lib/livingstyleguide/filters/haml.rb +0 -4
- data/lib/livingstyleguide/filters/markdown.rb +0 -4
- data/lib/livingstyleguide/filters/require.rb +0 -4
- data/lib/livingstyleguide/filters/search_box.rb +0 -9
- data/lib/livingstyleguide/filters/syntax.rb +0 -4
- data/lib/livingstyleguide/filters/type.rb +0 -4
- data/lib/livingstyleguide/templates/code-example.html.erb +0 -21
- data/lib/livingstyleguide/templates/colors-example.html.erb +0 -38
- data/lib/livingstyleguide/templates/javascript-copy.html.erb +0 -26
- data/stylesheets/livingstyleguide/_search.scss +0 -8
@@ -1,194 +0,0 @@
|
|
1
|
-
module LivingStyleGuide
|
2
|
-
|
3
|
-
class Engine
|
4
|
-
attr_accessor :markdown, :files, :options, :variables
|
5
|
-
|
6
|
-
def initialize(options, sass_options)
|
7
|
-
@options = LivingStyleGuide.default_options.merge(options)
|
8
|
-
@sass_options = sass_options
|
9
|
-
@variables = {}
|
10
|
-
@files = []
|
11
|
-
@markdown = ''
|
12
|
-
end
|
13
|
-
|
14
|
-
def render
|
15
|
-
template('layout.html.erb')
|
16
|
-
end
|
17
|
-
|
18
|
-
def files
|
19
|
-
collect_data if @files.empty?
|
20
|
-
@files
|
21
|
-
end
|
22
|
-
|
23
|
-
def variables
|
24
|
-
collect_data if @variables.empty?
|
25
|
-
@variables
|
26
|
-
end
|
27
|
-
|
28
|
-
def markdown
|
29
|
-
generate_markdown if @markdown.empty?
|
30
|
-
@markdown
|
31
|
-
end
|
32
|
-
|
33
|
-
def sass
|
34
|
-
separator = @options[:syntax] == :sass ? "\n" : ';'
|
35
|
-
[
|
36
|
-
%Q(@import "#{@options[:source]}"),
|
37
|
-
style_variables,
|
38
|
-
%Q(@import "livingstyleguide"),
|
39
|
-
@options[:styleguide_sass] || @options[:styleguide_scss]
|
40
|
-
].flatten.join(separator)
|
41
|
-
end
|
42
|
-
|
43
|
-
def css
|
44
|
-
sass_engine.render
|
45
|
-
end
|
46
|
-
|
47
|
-
def html
|
48
|
-
renderer = RedcarpetHTML.new(@options, self)
|
49
|
-
redcarpet = ::Redcarpet::Markdown.new(renderer, REDCARPET_RENDER_OPTIONS)
|
50
|
-
redcarpet.render(markdown)
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
def collect_data
|
55
|
-
traverse_children sass_engine.to_tree
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
def traverse_children(node)
|
60
|
-
node.children.each do |child|
|
61
|
-
if child.is_a?(Sass::Tree::ImportNode)
|
62
|
-
add_file child.imported_file.to_tree
|
63
|
-
elsif child.is_a?(Sass::Tree::VariableNode)
|
64
|
-
add_variable child
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
def add_file(node)
|
71
|
-
filename = File.expand_path(node.filename)
|
72
|
-
if local_sass_file?(filename)
|
73
|
-
@files << filename
|
74
|
-
traverse_children node
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
def add_variable(node)
|
80
|
-
key = import_filename(node.filename)
|
81
|
-
@variables[key] ||= []
|
82
|
-
@variables[key] << node.name
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
def local_sass_file?(filename)
|
87
|
-
@local_sass_file_regexp ||= /^#{File.expand_path(@options[:root])}\/.+\.s[ac]ss$/
|
88
|
-
filename =~ @local_sass_file_regexp
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
def import_filename(filename)
|
93
|
-
@import_filename_regexp ||= /(?<=^|\/)_?([^\/]+?)\.s[ac]ss$/
|
94
|
-
filename.sub(@import_filename_regexp, '\\1')
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
def sass_engine
|
99
|
-
return @sass_engine if @sass_engine
|
100
|
-
sass_options = @sass_options.clone
|
101
|
-
sass_options[:living_style_guide] = self
|
102
|
-
@sass_engine = ::Sass::Engine.new(sass, sass_options)
|
103
|
-
collect_data
|
104
|
-
@sass_engine
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
def style_variables
|
109
|
-
return unless @options.has_key?(:style)
|
110
|
-
@options[:style].map do |key, value|
|
111
|
-
"$lsg--#{key}: #{value}"
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
def generate_markdown
|
117
|
-
files.clone.each do |sass_filename|
|
118
|
-
next unless sass_filename.is_a?(String)
|
119
|
-
glob = "#{sass_filename.sub(/\.s[ac]ss$/, '')}.md"
|
120
|
-
Dir.glob(glob) do |markdown_filename|
|
121
|
-
next if files.include?(markdown_filename)
|
122
|
-
|
123
|
-
files << markdown_filename
|
124
|
-
@markdown << File.read(markdown_filename)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
private
|
130
|
-
def template(filename)
|
131
|
-
data = TemplateData.new(self)
|
132
|
-
erb = File.read(File.join(File.dirname(__FILE__), 'templates', filename))
|
133
|
-
ERB.new(erb).result(data.get_binding)
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
class TemplateData
|
139
|
-
include ERB::Util
|
140
|
-
|
141
|
-
def initialize(engine)
|
142
|
-
@engine = engine
|
143
|
-
end
|
144
|
-
|
145
|
-
def get_binding
|
146
|
-
binding
|
147
|
-
end
|
148
|
-
|
149
|
-
def title
|
150
|
-
@engine.options[:title]
|
151
|
-
end
|
152
|
-
|
153
|
-
def css
|
154
|
-
@engine.css
|
155
|
-
end
|
156
|
-
|
157
|
-
def variables
|
158
|
-
@engine.variables
|
159
|
-
end
|
160
|
-
|
161
|
-
def html
|
162
|
-
@engine.html
|
163
|
-
end
|
164
|
-
|
165
|
-
def head
|
166
|
-
javascript_tags_for(@engine.options[:javascript_before]).join("\n")
|
167
|
-
end
|
168
|
-
|
169
|
-
def header
|
170
|
-
contents = [@engine.options[:header]]
|
171
|
-
contents.join("\n")
|
172
|
-
end
|
173
|
-
|
174
|
-
def footer
|
175
|
-
contents = [@engine.options[:footer]]
|
176
|
-
contents << javascript_tags_for(@engine.options[:javascript_after])
|
177
|
-
contents.join("\n")
|
178
|
-
end
|
179
|
-
|
180
|
-
private
|
181
|
-
def javascript_tags_for(list)
|
182
|
-
return [] unless list
|
183
|
-
list.map do |src|
|
184
|
-
if src =~ /\.js$/
|
185
|
-
%Q(<script src="#{src}"></script>)
|
186
|
-
else
|
187
|
-
%Q(<script>#{src}</script>)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
class LivingStyleGuide::Filters
|
2
|
-
attr_reader :document
|
3
|
-
|
4
|
-
def initialize(doc)
|
5
|
-
@document = doc
|
6
|
-
end
|
7
|
-
|
8
|
-
def get_binding
|
9
|
-
binding
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.add_filter(*keys, &block)
|
13
|
-
keys.each do |key|
|
14
|
-
define_method key, &block
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'livingstyleguide/filters/options'
|
20
|
-
require 'livingstyleguide/filters/default'
|
21
|
-
require 'livingstyleguide/filters/import_and_use'
|
22
|
-
require 'livingstyleguide/filters/require'
|
23
|
-
require 'livingstyleguide/filters/full_width'
|
24
|
-
require 'livingstyleguide/filters/haml'
|
25
|
-
require 'livingstyleguide/filters/type'
|
26
|
-
require 'livingstyleguide/filters/markdown'
|
27
|
-
require 'livingstyleguide/filters/javascript'
|
28
|
-
require 'livingstyleguide/filters/coffee_script'
|
29
|
-
require 'livingstyleguide/filters/add_wrapper_class'
|
30
|
-
require 'livingstyleguide/filters/font_example'
|
31
|
-
require 'livingstyleguide/filters/colors'
|
32
|
-
require 'livingstyleguide/filters/css'
|
33
|
-
require 'livingstyleguide/filters/sass'
|
34
|
-
require 'livingstyleguide/filters/style'
|
35
|
-
require 'livingstyleguide/filters/data'
|
36
|
-
require 'livingstyleguide/filters/layout'
|
37
|
-
require 'livingstyleguide/filters/syntax'
|
38
|
-
require 'livingstyleguide/filters/search_box'
|
@@ -1,9 +0,0 @@
|
|
1
|
-
LivingStyleGuide.default_options[:search_box] = {
|
2
|
-
placeholder: "Search …"
|
3
|
-
}
|
4
|
-
|
5
|
-
LivingStyleGuide.add_filter :search_box do |arguments, options, content|
|
6
|
-
placeholder = options[:placeholder] || LivingStyleGuide.default_options[:search_box][:placeholder]
|
7
|
-
document.header << ERB.new(File.read("#{File.dirname(__FILE__)}/../templates/search-box.html.erb")).result(binding)
|
8
|
-
nil
|
9
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
document.addEventListener("DOMContentLoaded", function() {
|
3
|
-
if (testCopy()) {
|
4
|
-
var code = document.getElementsByClassName("lsg--code");
|
5
|
-
|
6
|
-
for (var i = 0; i < code.length; i++) {
|
7
|
-
var newButton = createButton()
|
8
|
-
code[i].appendChild(newButton)
|
9
|
-
newButton.addEventListener("click", function(event) {
|
10
|
-
selectElementRange(this.parentNode);
|
11
|
-
})
|
12
|
-
}
|
13
|
-
}
|
14
|
-
});
|
15
|
-
|
16
|
-
function createButton(copyCodeSelect) {
|
17
|
-
var buttonCopy = document.createElement("button");
|
18
|
-
buttonCopy.className = "lsg--button";
|
19
|
-
return buttonCopy;
|
20
|
-
}
|
21
|
-
</script>
|
@@ -1,38 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
document.addEventListener("DOMContentLoaded", function() {
|
3
|
-
if (testCopy()) {
|
4
|
-
var colorSwatches = document.getElementsByClassName("lsg--color-swatch");
|
5
|
-
for (var i = 0; i < colorSwatches.length; i++) {
|
6
|
-
if (!colorSwatches[i].classList.contains("-lsg-empty")) {
|
7
|
-
colorSwatches[i].appendChild(createSpan());
|
8
|
-
colorSwatches[i].addEventListener("click", function(event) {
|
9
|
-
if (event.altKey) {
|
10
|
-
var copyHexColors = window.getComputedStyle(this, ":after").getPropertyValue("content");
|
11
|
-
copyHexColors = copyHexColors.replace(/'/g, "");
|
12
|
-
selectElementRange(createDiv(copyHexColors));
|
13
|
-
}
|
14
|
-
else {
|
15
|
-
selectElementRange(this.children[0]);
|
16
|
-
}
|
17
|
-
});
|
18
|
-
}
|
19
|
-
}
|
20
|
-
}
|
21
|
-
});
|
22
|
-
|
23
|
-
function createDiv(copyHexColors) {
|
24
|
-
var divCopy = document.createElement("div");
|
25
|
-
divCopy.className = "-lsg-remove";
|
26
|
-
divCopy.setAttribute("style", "opacity: 0; position: absolute; top: -10000px");
|
27
|
-
divCopy.appendChild(document.createTextNode(copyHexColors));
|
28
|
-
document.body.appendChild(divCopy);
|
29
|
-
return divCopy
|
30
|
-
}
|
31
|
-
|
32
|
-
function createSpan() {
|
33
|
-
var spanHover = document.createElement("span");
|
34
|
-
spanHover.className = "lsg--copy-color";
|
35
|
-
spanHover.appendChild(document.createTextNode("Click to copy variable\nAlt + click to copy HEX code"));
|
36
|
-
return spanHover
|
37
|
-
}
|
38
|
-
</script>
|
@@ -1,26 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
function selectElementRange(copyElementSelect) {
|
3
|
-
var range = document.createRange();
|
4
|
-
range.selectNode(copyElementSelect);
|
5
|
-
window.getSelection().removeAllRanges();
|
6
|
-
window.getSelection().addRange(range);
|
7
|
-
|
8
|
-
document.execCommand("copy");
|
9
|
-
|
10
|
-
if (copyElementSelect.classList.contains("-lsg-remove")) {
|
11
|
-
document.body.removeChild(copyElementSelect);
|
12
|
-
}
|
13
|
-
|
14
|
-
window.getSelection().removeAllRanges();
|
15
|
-
}
|
16
|
-
|
17
|
-
function testCopy() {
|
18
|
-
try {
|
19
|
-
document.execCommand("copy");
|
20
|
-
return true;
|
21
|
-
}
|
22
|
-
catch(err) {
|
23
|
-
return false;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
</script>
|