livingstyleguide 2.0.0.alpha.9 → 2.0.0.alpha.10

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: e03cd21e33364ddfbf67d1a6d9f9c76e07d44ba2
4
- data.tar.gz: 7f1ebb09b674d7846a915b3fb8547c9e191e62eb
3
+ metadata.gz: ba96e42a926901d8cd5997497cec4602f05f179c
4
+ data.tar.gz: b2e505615ea2fdcb6e5d6112bc8fe1d4c69b41ca
5
5
  SHA512:
6
- metadata.gz: 532de7e59bd8e913945e6983bf635533f662c9cc702ce1b086dccc2a33dbd64aa4e0359520272cbc5afde6e64e304aaa698ac2ebb3dc0aa742377653cd19c9a3
7
- data.tar.gz: 68cad8cb19c4cc277794f312fac26d010bd3018a239f8610c06cf18a363859574fe31014b05f8e00ba9a549285daec12453a78e342542372ae53726871758f35
6
+ metadata.gz: 8f9fac2110874728aad315e163252dec08023263415490220151b45ac208a53ab5ac2d7a9c1b390ff6f734789ed568460e75bb8c9cbb48f7ece2eb649fa1247c
7
+ data.tar.gz: d3f407cef912bb92a79cf0f80ffe98a7ddb75ee5b740e28a241550f813f968cc0999d1ca6ba7d296abdddffd9e45745952c9d3d61be5f67a883957f2e7bc546f
@@ -38,7 +38,11 @@ class LivingStyleGuide::Document < ::Tilt::Template
38
38
  @scss = ''
39
39
  @css = ''
40
40
  @locals = {}
41
- @defaults = { global: {} }
41
+ @defaults = {
42
+ global: {
43
+ type: :html
44
+ }
45
+ }
42
46
  end
43
47
 
44
48
  def highlighted_source
@@ -81,6 +85,9 @@ class LivingStyleGuide::Document < ::Tilt::Template
81
85
 
82
86
  def evaluate(scope, locals, &block)
83
87
  @head = ""
88
+ @head << ERB.new(File.read("#{File.dirname(__FILE__)}/templates/javascript-copy.html.erb")).result(binding)
89
+ @head << ERB.new(File.read("#{File.dirname(__FILE__)}/templates/code-example.html.erb")).result(binding)
90
+ @head << ERB.new(File.read("#{File.dirname(__FILE__)}/templates/colors-example.html.erb")).result(binding)
84
91
  @header = ""
85
92
  @footer = ""
86
93
  @scope = scope
@@ -35,3 +35,4 @@ require 'livingstyleguide/filters/style'
35
35
  require 'livingstyleguide/filters/data'
36
36
  require 'livingstyleguide/filters/layout'
37
37
  require 'livingstyleguide/filters/syntax'
38
+ require 'livingstyleguide/filters/search_box'
@@ -3,8 +3,6 @@ LivingStyleGuide.add_filter :colors do |arguments, options, content|
3
3
  columns = colors.map{ |l| l.size }.max
4
4
  colors = colors.flatten
5
5
 
6
- document.head << ERB.new(File.read("#{File.dirname(__FILE__)}/../templates/colors-example.html.erb")).result
7
-
8
6
  document.scss << <<-SCSS
9
7
  $lsg--variables: () !default;
10
8
  $lsg--variables: join(
@@ -15,11 +13,12 @@ LivingStyleGuide.add_filter :colors do |arguments, options, content|
15
13
  })
16
14
  );
17
15
  SCSS
16
+
18
17
  colors_html = colors.map do |variable|
19
- if variable == '-'
20
- css_class = '-lsg-empty'
21
- end
22
- %Q(<li class="lsg--color-swatch #{css_class || variable}"><span>#{variable}</span></li>\n)
23
- end.join("\n")
24
- %(<ul class="lsg--color-swatches -lsg-#{columns}-columns">\n#{colors_html}\n</ul>\n)
18
+ if variable == "-"
19
+ css_class = "-lsg-empty"
25
20
  end
21
+ %Q(<li class="lsg--color-swatch #{css_class || variable}"><span>#{variable}</span></li>\n)
22
+ end.join("\n")
23
+ %(<ul class="lsg--color-swatches -lsg-#{columns}-columns">\n#{colors_html}\n</ul>\n)
24
+ end
@@ -7,7 +7,7 @@ LivingStyleGuide.add_filter :css do |arguments, options, css|
7
7
  document.depend_on file
8
8
  document.scss << %Q(@import "#{file}";\n)
9
9
  else
10
- scope = "#" + document.id.gsub(/[\/\.]/, '\\\0')
10
+ scope = "#" + document.id.gsub(/[\/\.]/, '\\\\\0')
11
11
  scoped_css = css.gsub(/(?<=\}|\A|;)[^@\};]+?(?=\{)/) do |selector|
12
12
  selector.split(",").map do |single_selector|
13
13
  "#{scope} #{single_selector}"
@@ -22,10 +22,9 @@ end
22
22
  %w(head header footer).each do |part|
23
23
  eval <<-RUBY
24
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"
25
+ html = LivingStyleGuide::Document.new(livingstyleguide: document) { block }
26
+ html.type = options[:type]
27
+ document.#{part} << html.render + "\n"
29
28
  nil
30
29
  end
31
30
  RUBY
@@ -7,7 +7,7 @@ LivingStyleGuide.add_filter :scss do |arguments, options, scss|
7
7
  document.depend_on file
8
8
  document.scss << %Q(@import "#{file}";\n)
9
9
  else
10
- document.scss << "##{document.id.gsub(/[\/\.]/, '\\\0')} {\n#{scss}\n}\n"
10
+ document.scss << "##{document.id.gsub(/[\/\.]/, '\\\\\0')} {\n#{scss}\n}\n"
11
11
  end
12
12
  nil
13
13
  end
@@ -22,7 +22,7 @@ LivingStyleGuide.add_filter :sass do |arguments, options, sass|
22
22
  document.scss << %Q(@import "#{file}";\n)
23
23
  else
24
24
  scss = Sass::Engine.new(sass).to_tree.to_scss
25
- document.scss << "##{document.id.gsub(/[\/\.]/, '\\\0')} {\n#{scss}\n}\n"
25
+ document.scss << "##{document.id.gsub(/[\/\.]/, '\\\\\0')} {\n#{scss}\n}\n"
26
26
  end
27
27
  nil
28
28
  end
@@ -0,0 +1,9 @@
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
@@ -48,7 +48,7 @@ module LivingStyleGuide
48
48
  language = @options[:default_language] if language == :''
49
49
  document = Document.new(livingstyleguide: @document) { code }
50
50
  document.id = document_id
51
- document.type = language == :example ? :html : language
51
+ document.type = language == :example ? @document.defaults[:global][:type] : language
52
52
  document.template = template_for(language)
53
53
  document.render(@document.scope)
54
54
  end
@@ -0,0 +1,21 @@
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,14 +1,13 @@
1
1
  <script>
2
- document.addEventListener('DOMContentLoaded', function() {
2
+ document.addEventListener("DOMContentLoaded", function() {
3
3
  if (testCopy()) {
4
- var colorSwatches = document.getElementsByClassName('lsg--color-swatch');
4
+ var colorSwatches = document.getElementsByClassName("lsg--color-swatch");
5
5
  for (var i = 0; i < colorSwatches.length; i++) {
6
-
7
- if (!colorSwatches[i].classList.contains('-lsg-empty')) {
6
+ if (!colorSwatches[i].classList.contains("-lsg-empty")) {
8
7
  colorSwatches[i].appendChild(createSpan());
9
- colorSwatches[i].addEventListener('click', function(event) {
8
+ colorSwatches[i].addEventListener("click", function(event) {
10
9
  if (event.altKey) {
11
- var copyHexColors = window.getComputedStyle(this, ':after').getPropertyValue('content');
10
+ var copyHexColors = window.getComputedStyle(this, ":after").getPropertyValue("content");
12
11
  copyHexColors = copyHexColors.replace(/'/g, "");
13
12
  selectElementRange(createDiv(copyHexColors));
14
13
  }
@@ -22,43 +21,18 @@
22
21
  });
23
22
 
24
23
  function createDiv(copyHexColors) {
25
- var divCopy = document.createElement('div');
26
- divCopy.className = '-lsg-remove';
27
- divCopy.setAttribute('style', 'opacity:0; position: absolute; top: -10000px');
24
+ var divCopy = document.createElement("div");
25
+ divCopy.className = "-lsg-remove";
26
+ divCopy.setAttribute("style", "opacity: 0; position: absolute; top: -10000px");
28
27
  divCopy.appendChild(document.createTextNode(copyHexColors));
29
28
  document.body.appendChild(divCopy);
30
29
  return divCopy
31
30
  }
32
31
 
33
32
  function createSpan() {
34
- var spanHover = document.createElement('span');
35
- spanHover.className = 'lsg--copy-color';
33
+ var spanHover = document.createElement("span");
34
+ spanHover.className = "lsg--copy-color";
36
35
  spanHover.appendChild(document.createTextNode("Click to copy variable\nAlt + click to copy HEX code"));
37
36
  return spanHover
38
37
  }
39
-
40
- function selectElementRange(copyElementSelect) {
41
- var range = document.createRange();
42
- range.selectNode(copyElementSelect);
43
- window.getSelection().removeAllRanges();
44
- window.getSelection().addRange(range);
45
-
46
- document.execCommand('copy');
47
-
48
- if (copyElementSelect.classList.contains('-lsg-remove')) {
49
- document.body.removeChild(copyElementSelect);
50
- }
51
-
52
- window.getSelection().removeAllRanges();
53
- }
54
-
55
- function testCopy() {
56
- try {
57
- document.execCommand('copy');
58
- return true;
59
- }
60
- catch(err) {
61
- return false;
62
- }
63
- }
64
38
  </script>
@@ -0,0 +1,26 @@
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>
@@ -4,6 +4,7 @@
4
4
  <head>
5
5
  <meta charset="utf-8">
6
6
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
7
+ <meta content="width=device-width, initial-scale=1.0" name="viewport">
7
8
  <meta content="The LivingStyleGuide Gem – http://livingstyleguide.org" name="generator">
8
9
  <title><%= ERB::Util.h(title) %></title>
9
10
  <script>
@@ -0,0 +1,68 @@
1
+ <div class="lsg--search">
2
+ <input type="search" class="lsg--search-box" placeholder="<%= placeholder %>" autofocus>
3
+ </div>
4
+ <script>
5
+ function hasClass(ele, cls) {
6
+ return ele.classList.contains(cls);
7
+ }
8
+
9
+ function addMatch(matched, node) {
10
+ if (node.nodeType !== Node.TEXT_NODE) {
11
+ if (node.className.match(/lsg--/)) {
12
+ matched.push(node);
13
+ }
14
+ }
15
+ }
16
+
17
+ var addNextElement = function(selection, matched, i) {
18
+ var j = i + 1;
19
+ while (j < selection.length) {
20
+ if (hasClass(selection[j], "lsg--headline")) {
21
+ break;
22
+ }
23
+ addMatch(matched, selection[j]);
24
+ j++;
25
+ }
26
+ }
27
+
28
+ var addPreviousElement = function(selection, matched, i) {
29
+ var j = i;
30
+ while (j >= 0) {
31
+ addMatch(matched, selection[j]);
32
+ if (hasClass(selection[j], "lsg--headline")) {
33
+ break;
34
+ }
35
+ j--;
36
+ }
37
+ }
38
+
39
+ document.querySelector(".lsg--search-box").addEventListener("input", function(event) {
40
+ var searchTerm = this.value;
41
+
42
+ var selection = document.querySelectorAll(".lsg--example, .lsg--color-swatches, .lsg--font-example, .lsg--paragraph, .lsg--unordered-list, .lsg--ordered-list, .lsg--headline, .lsg--sub-headline, .lsg--sub-sub-headline");
43
+ var regexp = new RegExp(searchTerm, "i");
44
+ selection = Array.prototype.slice.call(selection);
45
+ var matched = [];
46
+ var unmatched = [];
47
+
48
+ for (var i = 0; i < selection.length; i++) {
49
+ if (selection[i].textContent.match(regexp)) {
50
+ addMatch(matched, selection[i]);
51
+ addNextElement(selection, matched, i);
52
+ addPreviousElement(selection, matched, i);
53
+ };
54
+ };
55
+
56
+ unmatched = selection.filter(function(elem) {
57
+ return matched.indexOf(elem) === -1;
58
+ });
59
+
60
+ unmatched.map(function(item) {
61
+ item.style.display = "none";
62
+ });
63
+
64
+ matched.map(function(item) {
65
+ item.style.display = "block";
66
+ });
67
+ });
68
+ </script>
@@ -1,3 +1,3 @@
1
1
  module LivingStyleGuide
2
- VERSION = '2.0.0.alpha.9'
2
+ VERSION = '2.0.0.alpha.10'
3
3
  end
@@ -48,6 +48,15 @@ $lsg--color-swatches-per-line: 2 !default;
48
48
  $lsg--highlight-color: #f6ffa3 !default;
49
49
  $lsg--highlight-border-radius: 2px;
50
50
 
51
+ //// IMAGES - SVG ////
52
+
53
+ $lsg--copy-background-image: url("data:image/svg+xml;utf8,<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='100%' height='100%' viewBox='0 0 512 512' enable-background='new 0 0 512 512' xml:space='preserve'> <path id='copy-6-icon' d='M360.277,151.999V50.001H50v310.137h102v101.861h310v-310H360.277z M90,320.138V90.001h230.277v61.998 H152v168.139H90z M421.5,421.499h-230V191.832h20.569c10.639,0,20.745,4.656,27.657,12.744l19.023,22.256H358l19.366-22.408 c6.911-7.996,16.958-12.592,27.528-12.592H421.5V421.499z M379.479,338.581h-145.99v-29h145.99V338.581z M379.479,286.249h-145.99 v-29h145.99V286.249z M233.488,361.999h146.023v29H233.488V361.999z'/></svg>");
54
+
55
+ //// BUTTONS ////
56
+
57
+ $lsg--button-height: 23px !default;
58
+ $lsg--button-width: $lsg--button-height !default;
59
+
51
60
  //// IMPORTS ////
52
61
 
53
62
  @import "livingstyleguide/reset";
@@ -55,4 +64,5 @@ $lsg--highlight-border-radius: 2px;
55
64
  @import "livingstyleguide/content";
56
65
  @import "livingstyleguide/code";
57
66
  @import "livingstyleguide/color-swatches";
67
+ @import "livingstyleguide/search";
58
68
  @import "livingstyleguide/variables";
@@ -72,14 +72,20 @@
72
72
  }
73
73
 
74
74
  .lsg--code-block {
75
- display: block;//none;
75
+ display: block;
76
+ min-height: $lsg--gap-width + $lsg--button-height;
76
77
  line-height: $lsg--code-line-height;
77
78
  padding: 3px $lsg--gap-width;
78
- width: $lsg--width;
79
+ max-width: $lsg--width;
80
+ -ms-overflow-style: none;
79
81
 
80
82
  .show-code & {
81
83
  display: block;
82
84
  }
85
+
86
+ &::-webkit-scrollbar {
87
+ width: 0 !important;
88
+ }
83
89
  }
84
90
 
85
91
  .lsg--example + .lsg--code-block {
@@ -98,7 +104,27 @@
98
104
  .lsg--code {
99
105
  display: block;
100
106
  margin: auto;
101
- width: $lsg--width;
107
+ max-width: $lsg--width;
108
+ }
109
+ }
110
+
111
+ .lsg--button {
112
+ background-color: $lsg--background-color;
113
+ background-image: $lsg--copy-background-image;
114
+ background-position: 50%;
115
+ background-repeat: no-repeat;
116
+ background-size: 90%;
117
+ border-radius: $lsg--border-radius;
118
+ bottom: floor($lsg--gap-width / 2);
119
+ cursor: pointer;
120
+ height: $lsg--button-height;
121
+ position: absolute;
122
+ right: floor($lsg--gap-width / 2);
123
+ visibility: hidden;
124
+ width: $lsg--button-width;
125
+
126
+ .lsg--code:hover & {
127
+ visibility: visible;
102
128
  }
103
129
  }
104
130
 
@@ -121,4 +147,3 @@
121
147
  @extend .lsg--code-highlight;
122
148
  display: block;
123
149
  }
124
-
@@ -65,7 +65,7 @@
65
65
  margin: $lsg--gap-width auto (-$lsg--gap-width) auto;
66
66
  overflow: hidden;
67
67
  padding-left: $lsg--gap-width;
68
- width: $lsg--width + 2 * $lsg--gap-width;
68
+ max-width: $lsg--width + 2 * $lsg--gap-width;
69
69
  }
70
70
 
71
71
  @for $i from 1 through 12 {
@@ -10,7 +10,7 @@
10
10
  line-height: $lsg--base-line-height;
11
11
  margin: $lsg--gap-width auto;
12
12
  text-align: $lsg--base-text-align;
13
- width: $lsg--width;
13
+ max-width: $lsg--width;
14
14
  -webkit-font-smoothing: antialiased;
15
15
  }
16
16
 
@@ -35,7 +35,7 @@
35
35
  line-height: $lsg--headline-line-height;
36
36
  margin: (3 * $lsg--gap-width) auto $lsg--gap-width;
37
37
  text-align: $lsg--headline-text-align;
38
- width: $lsg--width;
38
+ max-width: $lsg--width;
39
39
  -webkit-font-smoothing: antialiased;
40
40
  }
41
41
 
@@ -89,7 +89,7 @@
89
89
  overflow: hidden;
90
90
  padding: $lsg--gap-width;
91
91
  position: relative;
92
- width: $lsg--width;
92
+ max-width: $lsg--width;
93
93
 
94
94
  &.-lsg-has-full-width {
95
95
  @extend #{$lsg--layout-selector} !optional;
@@ -14,7 +14,7 @@
14
14
  @extend %lsg--reset;
15
15
  display: block;
16
16
  margin: (4 * $lsg--gap-width) auto;
17
- width: $lsg--width;
17
+ max-width: $lsg--width;
18
18
  }
19
19
 
20
20
  .lsg--logo {
@@ -36,4 +36,3 @@
36
36
  filter: unquote("brightness(0.7)");
37
37
  }
38
38
  }
39
-
@@ -21,4 +21,3 @@
21
21
  text-decoration: none;
22
22
  vertical-align: baseline;
23
23
  }
24
-
@@ -0,0 +1,8 @@
1
+ .lsg--search {
2
+ margin: 0px auto;
3
+ width: $lsg--width + ($lsg--width / 2);
4
+ }
5
+
6
+ .lsg--search-box {
7
+ margin: 2 * $lsg--gap-width $lsg--width + ($lsg--width / 4);
8
+ }
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.9
4
+ version: 2.0.0.alpha.10
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-07-23 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minisyntax
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: redcarpet
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tilt
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -224,6 +224,7 @@ files:
224
224
  - lib/livingstyleguide/filters/options.rb
225
225
  - lib/livingstyleguide/filters/require.rb
226
226
  - lib/livingstyleguide/filters/sass.rb
227
+ - lib/livingstyleguide/filters/search_box.rb
227
228
  - lib/livingstyleguide/filters/style.rb
228
229
  - lib/livingstyleguide/filters/syntax.rb
229
230
  - lib/livingstyleguide/filters/type.rb
@@ -233,14 +234,17 @@ files:
233
234
  - lib/livingstyleguide/integration/sass.rb
234
235
  - lib/livingstyleguide/integration/sprockets.rb
235
236
  - lib/livingstyleguide/markdown_extensions.rb
237
+ - lib/livingstyleguide/templates/code-example.html.erb
236
238
  - lib/livingstyleguide/templates/code.html.erb
237
239
  - lib/livingstyleguide/templates/colors-example.html.erb
238
240
  - lib/livingstyleguide/templates/default.html.erb
239
241
  - lib/livingstyleguide/templates/example.html.erb
240
242
  - lib/livingstyleguide/templates/font-example.html.erb
243
+ - lib/livingstyleguide/templates/javascript-copy.html.erb
241
244
  - lib/livingstyleguide/templates/javascript.html.erb
242
245
  - lib/livingstyleguide/templates/layout.html.erb
243
246
  - lib/livingstyleguide/templates/plain.html.erb
247
+ - lib/livingstyleguide/templates/search-box.html.erb
244
248
  - lib/livingstyleguide/version.rb
245
249
  - stylesheets/_livingstyleguide.scss
246
250
  - stylesheets/livingstyleguide/_code.scss
@@ -248,6 +252,7 @@ files:
248
252
  - stylesheets/livingstyleguide/_content.scss
249
253
  - stylesheets/livingstyleguide/_layout.scss
250
254
  - stylesheets/livingstyleguide/_reset.scss
255
+ - stylesheets/livingstyleguide/_search.scss
251
256
  - stylesheets/livingstyleguide/_variables.scss
252
257
  homepage: http://livingstyleguide.org
253
258
  licenses: []