livingstyleguide 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. data/Rakefile +11 -1
  2. data/lib/livingstyleguide.rb +11 -2
  3. data/lib/livingstyleguide/markdown_extensions.rb +107 -0
  4. data/lib/livingstyleguide/sass_extensions.rb +9 -0
  5. data/lib/livingstyleguide/sass_extensions/functions.rb +12 -0
  6. data/lib/livingstyleguide/variables_importer.rb +81 -0
  7. data/lib/livingstyleguide/variables_importer/content.erb +19 -0
  8. data/lib/livingstyleguide/version.rb +1 -1
  9. data/livingstyleguide.gemspec +6 -0
  10. data/stylesheets/_livingstyleguide.scss +52 -0
  11. data/stylesheets/livingstyleguide/_code.scss +86 -0
  12. data/stylesheets/livingstyleguide/_color-swatches.scss +50 -0
  13. data/stylesheets/livingstyleguide/_content.scss +58 -0
  14. data/stylesheets/livingstyleguide/_layout.scss +4 -0
  15. data/test/fixtures/markdown/code-with-highlight-block.md +6 -0
  16. data/test/fixtures/markdown/code-with-highlight.md +4 -0
  17. data/test/fixtures/markdown/code.md +6 -0
  18. data/test/fixtures/markdown/example-with-highlight.md +5 -0
  19. data/test/fixtures/markdown/example.md +4 -0
  20. data/test/fixtures/markdown/font-example.md +1 -0
  21. data/test/fixtures/markdown/layout-example.md +4 -0
  22. data/test/fixtures/markdown/text.md +13 -0
  23. data/test/fixtures/markdown/variables.md +1 -0
  24. data/test/fixtures/stylesheets/variables/_more-other-colors.sass +2 -0
  25. data/test/fixtures/stylesheets/variables/colors.scss +2 -0
  26. data/test/fixtures/stylesheets/variables/other-colors.sass +2 -0
  27. data/test/integration/markdown_test.rb +107 -0
  28. data/test/integration/variables_test.rb +65 -0
  29. data/test/test_helper.rb +5 -0
  30. data/test/unit/sass_extensions_test.rb +28 -0
  31. metadata +127 -4
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new :test do |t|
5
+ t.libs << 'lib'
6
+ t.libs << 'test'
7
+ test_files = FileList['test/**/*_test.rb']
8
+ t.test_files = test_files
9
+ t.verbose = true
10
+ end
11
+
@@ -1,5 +1,14 @@
1
- require "livingstyleguide/version"
1
+ require 'livingstyleguide/version'
2
+ require 'livingstyleguide/sass_extensions'
3
+ require 'livingstyleguide/variables_importer'
4
+ require 'livingstyleguide/markdown_extensions'
5
+ require 'sass/plugin'
2
6
 
3
7
  module LivingStyleGuide
4
- # Your code goes here...
5
8
  end
9
+
10
+ Compass.configuration.add_import_path LivingStyleGuide::VariablesImporter.new
11
+
12
+ base_directory = File.join(File.dirname(__FILE__), '..')
13
+ Compass::Frameworks.register 'livingstyleguide', path: base_directory
14
+
@@ -0,0 +1,107 @@
1
+ require 'redcarpet'
2
+ require 'tilt'
3
+ require 'minisyntax'
4
+ require "erb"
5
+
6
+ module LivingStyleGuide
7
+ class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
8
+ RENDER_OPTIONS = {
9
+ autolink: true,
10
+ fenced_code_blocks: true,
11
+ tables: true,
12
+ strikethrough: true,
13
+ space_after_headers: true,
14
+ superscript: true
15
+ }
16
+
17
+ def generate_renderer
18
+ RedcarpetHTML.new(RENDER_OPTIONS)
19
+ end
20
+
21
+ def prepare
22
+ @engine = ::Redcarpet::Markdown.new(generate_renderer, RENDER_OPTIONS)
23
+ @output = nil
24
+ end
25
+
26
+ def evaluate(context, locals, &block)
27
+ @context ||= context
28
+
29
+ if @engine.renderer.respond_to? :middleman_app=
30
+ @engine.renderer.middleman_app = @context
31
+ end
32
+ super
33
+ end
34
+ end
35
+
36
+ class RedcarpetHTML < ::Redcarpet::Render::HTML
37
+ attr_accessor :middleman_app
38
+
39
+ def image(link, title, alt_text)
40
+ middleman_app.image_tag(link, :title => title, :alt => alt_text)
41
+ end
42
+
43
+ def link(link, title, content)
44
+ middleman_app.link_to(content, link, :title => title)
45
+ end
46
+
47
+ def header(text, header_level)
48
+ klass = %w(page-title headline sub-headline)[header_level]
49
+ header_level += 1
50
+ %Q(<h#{header_level} class="livingstyleguide--#{klass}">#{text}</h#{header_level}>\n)
51
+ end
52
+
53
+ def paragraph(text)
54
+ if text =~ /^\{\{variables:(.+)\}\}$/
55
+ uri = $1
56
+ result = %Q(<ul class="livingstyleguide--color-swatches">\n)
57
+ VariablesImporter.variables(uri).each do |variable|
58
+ result << %Q(<li class="livingstyleguide--color-swatch $#{variable}">$#{variable}</li>\n)
59
+ end
60
+ result << "</ul>\n"
61
+ elsif text =~ /^\{\{font-example:(.+)\}\}$/
62
+ font = $1
63
+ <<-HTML.gsub(' ', '')
64
+ <div class="livingstyleguide--font-example" style="font: #{font}">
65
+ ABCDEFGHIJKLMNOPQRSTUVWXYZ<br>
66
+ abcdefghijklmnopqrstuvwxyz<br>
67
+ 0123456789<br>
68
+ !&/()$=@;:,.
69
+ </div>
70
+ HTML
71
+ else
72
+ %Q(<p class="livingstyleguide--paragraph">#{text}</p>\n)
73
+ end
74
+ end
75
+
76
+ def list(contents, list_type)
77
+ tag_name = "#{list_type[0]}l"
78
+ %Q(<#{tag_name} class="livingstyleguide--#{list_type}-list">\n#{contents}</#{tag_name}>\n)
79
+ end
80
+
81
+ def list_item(text, list_type)
82
+ %Q(<li class="livingstyleguide--#{list_type}-list-item">#{text.strip}</li>\n)
83
+ end
84
+
85
+ def block_code(code, language)
86
+ if %w(example layout-example).include?(language)
87
+ html = code.gsub(/\*\*\*(.+?)\*\*\*/m, '\\1')
88
+ %Q(<div class="livingstyleguide--#{language}">\n #{html}\n</div>) + "\n" + block_code(code, 'html')
89
+ else
90
+ code = ERB::Util.html_escape(code).gsub(/&quot;/, '"')
91
+ code = ::MiniSyntax.highlight(code.strip, language.to_s.strip.to_sym)
92
+ code.gsub! /^\s*\*\*\*\n(.+?)\n\s*\*\*\*\n/m, %Q(<strong class="livingstyleguide--code-highlight-block">\\1</strong>)
93
+ code.gsub! /\*\*\*(.+?)\*\*\*/, %Q(<strong class="livingstyleguide--code-highlight">\\1</strong>)
94
+ %Q(<pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">#{code}</code></pre>)
95
+ end
96
+ end
97
+
98
+ def codespan(code)
99
+ code = ERB::Util.html_escape(code)
100
+ %Q(<code class="livingstyleguide--code-span livingstyleguide--code">#{code}</code>)
101
+ end
102
+
103
+ end
104
+
105
+ ::Tilt.register RedcarpetTemplate, 'markdown', 'mkd', 'md'
106
+ end
107
+
@@ -0,0 +1,9 @@
1
+ module LivingStyleGuide::SassExtensions
2
+ end
3
+
4
+ require 'livingstyleguide/sass_extensions/functions'
5
+ require 'sass'
6
+
7
+ module Sass::Script::Functions
8
+ include LivingStyleGuide::SassExtensions::Functions
9
+ end
@@ -0,0 +1,12 @@
1
+ module LivingStyleGuide::SassExtensions::Functions
2
+
3
+ def list_variables(uri)
4
+ uri = uri.value
5
+ variables = LivingStyleGuide::VariablesImporter.variables(uri)
6
+ variables.map! do |name|
7
+ Sass::Script::String.new(name)
8
+ end
9
+ Sass::Script::List.new(variables, :space)
10
+ end
11
+
12
+ end
@@ -0,0 +1,81 @@
1
+ require 'erb'
2
+ require 'ostruct'
3
+ require 'compass'
4
+
5
+ module LivingStyleGuide
6
+ class VariablesImporter < Sass::Importers::Base
7
+ VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
8
+ VARIABLE_IMPORTER_REGEX = %r{^variables:(((.+/)?([^\*.]+))/(.+?)(\.s[ac]ss)?)$}
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_REGEX
17
+ uri = $1
18
+ return self.class.sass_engine(uri, self.class.variables(uri), 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 += '.s?ss' unless uri =~ /\.s[ac]ss$/
45
+ uri.gsub! %r{^(.*)/(.+)$}, '\1/{_,}\2'
46
+ variables = []
47
+ paths = [Compass.configuration.sass_path, Compass.configuration.additional_import_paths].flatten
48
+ paths.each do |path|
49
+ if path.is_a? String
50
+ Dir.glob(File.join(path, uri)).each do |file|
51
+ sass = File.read(file)
52
+ variables << sass.scan(%r(\$([a-z\-_]+)\s*:))
53
+ end
54
+ end
55
+ end
56
+ variables.flatten!
57
+ variables.uniq!
58
+ variables
59
+ end
60
+
61
+ def self.sass_options(uri, importer, options)
62
+ options.merge! filename: uri.gsub(%r{\*/},"*\\/"), syntax: :scss, importer: importer
63
+ end
64
+
65
+ def self.sass_engine(uri, name, importer, options)
66
+ content = content_for_images(uri, name, options[:skip_overrides])
67
+ Sass::Engine.new(content, sass_options(uri, importer, options))
68
+ end
69
+
70
+ def self.content_for_images(uri, variables, skip_overrides = false)
71
+ binder = LivingStyleGuide::Binding.new(variables: variables)
72
+ CONTENT_TEMPLATE.result(binder.get_binding)
73
+ end
74
+ end
75
+
76
+ class Binding < OpenStruct
77
+ def get_binding
78
+ binding
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,19 @@
1
+ <% variables.each do |variable| %>
2
+ .\$<%= variable %> {
3
+ @if type-of($<%= variable %>) == color {
4
+ @extend %livingstyleguide--color-swatch !optional;
5
+ @if (lightness($<%= variable %>) < lightness($livingstyleguide--color)) {
6
+ color: $livingstyleguide--background-color;
7
+ }
8
+
9
+ &:before {
10
+ background: $<%= variable %>;
11
+ }
12
+ }
13
+
14
+ &:after {
15
+ @extend %livingstyleguide--code !optional;
16
+ content: "#{$<%= variable %>}";
17
+ }
18
+ }
19
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module LivingStyleGuide
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -16,4 +16,10 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'minisyntax'
21
+ gem.add_dependency 'middleman', '>= 3.0.9'
22
+ gem.add_dependency 'compass'
23
+ gem.add_dependency 'sass'
24
+ gem.add_dependency 'redcarpet'
19
25
  end
@@ -0,0 +1,52 @@
1
+ //// INTEGRATION ////
2
+
3
+ $livingstyleguide--layout-selector: body !default;
4
+
5
+ //// TYPOGRAPHY ////
6
+
7
+ $livingstyleguide--base-font: 'Georgia', 'Times New Roman', serif !default;
8
+ $livingstyleguide--base-font-size: 14px !default;
9
+ $livingstyleguide--base-font-weight: normal !default;
10
+ $livingstyleguide--base-line-height: 1.4 !default;
11
+ $livingstyleguide--headline-font: $livingstyleguide--base-font !default;
12
+ $livingstyleguide--page-title-font-size: 30px !default;
13
+ $livingstyleguide--headline-font-size: 22px !default;
14
+ $livingstyleguide--sub-headline-font-size: 16px !default;
15
+ $livingstyleguide--headline-font-weight: bold !default;
16
+ $livingstyleguide--headline-line-height: 1.1 !default;
17
+ $livingstyleguide--code-font: Courier, "Courier New", monospace !default;
18
+ $livingstyleguide--code-font-size: 12px !default;
19
+ $livingstyleguide--code-font-weight: normal !default;
20
+ $livingstyleguide--code-line-height: 1.5 !default;
21
+
22
+ //// STYLING ////
23
+
24
+ $livingstyleguide--background-color: #f7f7f7 !default;
25
+ $livingstyleguide--border-width: 1px !default;
26
+ $livingstyleguide--border-color: silver !default;
27
+ $livingstyleguide--border-radius: 0 !default;
28
+ $livingstyleguide--color: #505050 !default;
29
+ $livingstyleguide--width: 640px !default;
30
+ $livingstyleguide--gap-width: 10px !default;
31
+
32
+ $livingstyleguide--code-background-color: #505050 !default;
33
+ $livingstyleguide--code-color: white !default;
34
+ $livingstyleguide--code-border-width: $livingstyleguide--border-width !default;
35
+ $livingstyleguide--code-border-color: $livingstyleguide--border-color !default;
36
+ $livingstyleguide--code-border-radius: $livingstyleguide--border-radius !default;
37
+
38
+ $livingstyleguide--color-swatch-color: black !default;
39
+ $livingstyleguide--color-swatch-border-width: $livingstyleguide--border-width !default;
40
+ $livingstyleguide--color-swatch-border-color: $livingstyleguide--border-color !default;
41
+ $livingstyleguide--color-swatch-border-radius: $livingstyleguide--border-radius !default;
42
+ $livingstyleguide--color-swatches-per-line: 2 !default;
43
+
44
+ $livingstyleguide--highlight-color: #f6ffa3 !default;
45
+ $livingstyleguide--highlight-border-radius: 2px;
46
+
47
+ //// IMPORTS ////
48
+
49
+ @import "livingstyleguide/layout";
50
+ @import "livingstyleguide/content";
51
+ @import "livingstyleguide/code";
52
+ @import "livingstyleguide/color-swatches";
@@ -0,0 +1,86 @@
1
+ .livingstyleguide--code-span,
2
+ .livingstyleguide--code-block {
3
+ background: $livingstyleguide--code-background-color;
4
+ color: $livingstyleguide--code-color;
5
+ font-family: $livingstyleguide--code-font;
6
+ font-size: $livingstyleguide--code-font-size;
7
+ font-weight: $livingstyleguide--code-font-weight;
8
+ overflow: scroll;
9
+ padding: 0 3px;
10
+ -webkit-font-smoothing: subpixel-antialiased;
11
+ @include border-radius($livingstyleguide--code-border-radius);
12
+
13
+ kbd {
14
+ display: block;
15
+ font-weight: bold;
16
+
17
+ &:before {
18
+ content: "> ";
19
+ }
20
+ }
21
+
22
+ em {
23
+ color: lighten($livingstyleguide--code-color, 10%);
24
+ font-style: normal;
25
+ font-weight: bold;
26
+ text-decoration: underline;
27
+ }
28
+
29
+ b {
30
+ color: lighten($livingstyleguide--code-color, 20%);
31
+ font-weight: bold;
32
+ }
33
+
34
+ i {
35
+ color: lighten($livingstyleguide--code-color, 30%);
36
+ }
37
+
38
+ q {
39
+ color: lighten($livingstyleguide--code-color, 30%);
40
+ }
41
+
42
+ var {
43
+ text-decoration: underline;
44
+ }
45
+ }
46
+
47
+ .livingstyleguide--code-block {
48
+ display: block;
49
+ line-height: $livingstyleguide--code-line-height;
50
+ padding: 3px 6px;
51
+ width: $livingstyleguide--width - 2 * 6px;
52
+ }
53
+
54
+ .livingstyleguide--example + .livingstyleguide--code-block {
55
+ margin-top: 0;
56
+ @include border-top-radius(0);
57
+ }
58
+
59
+ .livingstyleguide--layout-example + .livingstyleguide--code-block {
60
+ background: $livingstyleguide--code-background-color;
61
+ margin: 0 0 $livingstyleguide--gap-width;
62
+ padding: $livingstyleguide--gap-width 0;
63
+ width: 100%;
64
+ @include border-radius(0);
65
+
66
+ .livingstyleguide--code {
67
+ display: block;
68
+ margin: auto;
69
+ width: $livingstyleguide--width;
70
+ }
71
+ }
72
+
73
+ .livingstyleguide--font-example {
74
+ @extend .livingstyleguide--example;
75
+ }
76
+
77
+ .livingstyleguide--code-highlight {
78
+ background-color: $livingstyleguide--highlight-color;
79
+ @include border-radius($livingstyleguide--highlight-border-radius);
80
+ }
81
+
82
+ .livingstyleguide--code-highlight-block {
83
+ @extend .livingstyleguide--code-highlight;
84
+ display: block;
85
+ }
86
+
@@ -0,0 +1,50 @@
1
+ %livingstyleguide--color-swatch {
2
+ color: $livingstyleguide--color-swatch-color;
3
+ float: left;
4
+ font-family: $livingstyleguide--code-font;
5
+ font-size: $livingstyleguide--code-font-size;
6
+ font-weight: bold;
7
+ height: 4em * $livingstyleguide--base-line-height;
8
+ line-height: $livingstyleguide--base-line-height;
9
+ list-style: none;
10
+ margin: 0 $livingstyleguide--gap-width $livingstyleguide--gap-width 0;
11
+ padding-top: 1em * $livingstyleguide--base-line-height;
12
+ position: relative;
13
+ text-align: center;
14
+ width: floor(
15
+ ($livingstyleguide--width - ($livingstyleguide--color-swatches-per-line - 1) * $livingstyleguide--gap-width)
16
+ /
17
+ $livingstyleguide--color-swatches-per-line
18
+ );
19
+ z-index: 1;
20
+ @include box-sizing(border-box);
21
+
22
+ &:nth-child(#{$livingstyleguide--color-swatches-per-line}n) {
23
+ margin-right: 0;
24
+ }
25
+
26
+ &:before {
27
+ border: $livingstyleguide--color-swatch-border-width $livingstyleguide--code-border-color solid;
28
+ content: "";
29
+ display: block;
30
+ height: 100%;
31
+ left: 0;
32
+ position: absolute;
33
+ top: 0;
34
+ width: 100%;
35
+ z-index: -1;
36
+ @include border-radius($livingstyleguide--color-swatch-border-radius);
37
+ @include box-sizing(border-box);
38
+ }
39
+
40
+ &:after {
41
+ display: block;
42
+ font-weight: normal;
43
+ }
44
+ }
45
+
46
+ .livingstyleguide--color-swatches {
47
+ margin: $livingstyleguide--gap-width auto (-$livingstyleguide--gap-width) auto;
48
+ width: $livingstyleguide--width;
49
+ @include clearfix;
50
+ }
@@ -0,0 +1,58 @@
1
+ .livingstyleguide--paragraph,
2
+ .livingstyleguide--code-block,
3
+ .livingstyleguide--unordered-list,
4
+ .livingstyleguide--ordered-list {
5
+ font-family: $livingstyleguide--base-font;
6
+ font-size: $livingstyleguide--base-font-size;
7
+ font-weight: $livingstyleguide--base-font-weight;
8
+ line-height: $livingstyleguide--base-line-height;
9
+ margin: $livingstyleguide--gap-width auto;
10
+ width: $livingstyleguide--width;
11
+ -webkit-font-smoothing: antialiased;
12
+ }
13
+
14
+ .livingstyleguide--unordered-list-item,
15
+ .livingstyleguide--ordered-list-item {
16
+ list-style: disc;
17
+ margin: ceil($livingstyleguide--gap-width / 2) 0 ceil($livingstyleguide--gap-width / 2) (2 * $livingstyleguide--gap-width);
18
+ }
19
+
20
+ .livingstyleguide--page-title,
21
+ .livingstyleguide--headline,
22
+ .livingstyleguide--sub-headline {
23
+ font-family: $livingstyleguide--headline-font;
24
+ font-size: $livingstyleguide--headline-font-size;
25
+ font-weight: $livingstyleguide--headline-font-weight;
26
+ line-height: $livingstyleguide--headline-line-height;
27
+ margin: (3 * $livingstyleguide--gap-width) auto $livingstyleguide--gap-width;
28
+ width: $livingstyleguide--width;
29
+ -webkit-font-smoothing: antialiased;
30
+ }
31
+
32
+ .livingstyleguide--page-title {
33
+ font-size: $livingstyleguide--page-title-font-size;
34
+ }
35
+
36
+ .livingstyleguide--sub-headline {
37
+ font-size: $livingstyleguide--sub-headline-font-size;
38
+ }
39
+
40
+ .livingstyleguide--example {
41
+ background: white;
42
+ margin: $livingstyleguide--gap-width auto 0;
43
+ padding: $livingstyleguide--gap-width;
44
+ width: $livingstyleguide--width;
45
+ @include box-sizing(border-box);
46
+ @include border-top-radius($livingstyleguide--border-radius);
47
+
48
+ .livingstyleguide--layout-example & {
49
+ margin: 0 auto;
50
+ width: 100%;
51
+ @include border-radius(0);
52
+ }
53
+ }
54
+
55
+ .livingstyleguide--layout-example {
56
+ @extend #{$livingstyleguide--layout-selector} !optional;
57
+ padding: $livingstyleguide--gap-width;
58
+ }
@@ -0,0 +1,4 @@
1
+ .livingstyleguide {
2
+ background: $livingstyleguide--background-color;
3
+ color: $livingstyleguide--color;
4
+ }
@@ -0,0 +1,6 @@
1
+ ~~~ html
2
+ ***
3
+ <p>Block example</p>
4
+ ***
5
+ ~~~
6
+
@@ -0,0 +1,4 @@
1
+ ~~~ html
2
+ <img class="inline ***example***">
3
+ ~~~
4
+
@@ -0,0 +1,6 @@
1
+ ~~~ css
2
+ .my-class {
3
+ color: red;
4
+ }
5
+ ~~~
6
+
@@ -0,0 +1,5 @@
1
+ ~~~ example
2
+ <img class="inline ***example***">
3
+ <img class="inline ***ex-1*** ***ex-2***">
4
+ ~~~
5
+
@@ -0,0 +1,4 @@
1
+ ~~~ example
2
+ <button class="button">Test</button>
3
+ ~~~
4
+
@@ -0,0 +1 @@
1
+ {{font-example:16px Courier}}
@@ -0,0 +1,4 @@
1
+ ~~~ layout-example
2
+ <button class="button">Test</button>
3
+ ~~~
4
+
@@ -0,0 +1,13 @@
1
+ # Hello World
2
+
3
+ Lorem ipsum **dolor** sit amet, `<consectetur> adipiscing` elit. Sed a pulvinar turpis.
4
+
5
+ * Lorem
6
+ * Ipsum
7
+ * Dolor
8
+
9
+ ## More Lorem
10
+
11
+ 1. Lorem
12
+ 2. Ipsum
13
+ 3. Dolor
@@ -0,0 +1 @@
1
+ {{variables:variables/other-colors}}
@@ -0,0 +1,2 @@
1
+ $blue: blue
2
+ $green: green
@@ -0,0 +1,2 @@
1
+ $my-wonderful_red: red;
2
+ $blue : "blue";
@@ -0,0 +1,2 @@
1
+ $blue: blue
2
+ $green: green
@@ -0,0 +1,107 @@
1
+ require 'test_helper'
2
+ require 'tilt'
3
+
4
+ class MarkdownTest < Test::Unit::TestCase
5
+
6
+ def render(file)
7
+ template = Tilt.new(file)
8
+ template.render
9
+ end
10
+
11
+ def assert_markdown(expected, file)
12
+ expected = expected.gsub(/\s+/m, ' ').gsub(/([\$\(\)\[\]])/) { |s| "\\#{s}" }.strip
13
+ given = render(File.join(%W(test fixtures markdown #{file})))
14
+ given = given.gsub(/\s+/m, ' ').strip
15
+ assert_match /#{expected}/, given
16
+ end
17
+
18
+ def test_examples
19
+ assert_markdown <<-HTML, 'example.md'
20
+ <div class="livingstyleguide--example">
21
+ <button class="button">Test</button>
22
+ </div>
23
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">.+button.+Test.+button.+</code></pre>
24
+ HTML
25
+ end
26
+
27
+ def test_layout_examples
28
+ assert_markdown <<-HTML, 'layout-example.md'
29
+ <div class="livingstyleguide--layout-example">
30
+ <button class="button">Test</button>
31
+ </div>
32
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">.+button.+Test.+button.+</code></pre>
33
+ HTML
34
+ end
35
+
36
+ def test_text
37
+ assert_markdown <<-HTML, 'text.md'
38
+ <h2 class="livingstyleguide--headline">Hello World</h2>
39
+ <p class="livingstyleguide--paragraph">Lorem ipsum <strong>dolor</strong> sit amet,
40
+ <code class="livingstyleguide--code-span livingstyleguide--code">&lt;consectetur&gt; adipiscing</code> elit.
41
+ Sed a pulvinar turpis.</p>
42
+ <ul class="livingstyleguide--unordered-list">
43
+ <li class="livingstyleguide--unordered-list-item">Lorem</li>
44
+ <li class="livingstyleguide--unordered-list-item">Ipsum</li>
45
+ <li class="livingstyleguide--unordered-list-item">Dolor</li>
46
+ </ul>
47
+ <h3 class="livingstyleguide--sub-headline">More Lorem</h3>
48
+ <ol class="livingstyleguide--ordered-list">
49
+ <li class="livingstyleguide--ordered-list-item">Lorem</li>
50
+ <li class="livingstyleguide--ordered-list-item">Ipsum</li>
51
+ <li class="livingstyleguide--ordered-list-item">Dolor</li>
52
+ </ol>
53
+ HTML
54
+ end
55
+
56
+ def test_code
57
+ assert_markdown <<-HTML, 'code.md'
58
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><b><i>.my-class</i></b> {
59
+ <b>color:</b> <b>red</b>;
60
+ }</code></pre>
61
+ HTML
62
+ end
63
+
64
+ def test_code_with_highlight
65
+ assert_markdown <<-HTML, 'code-with-highlight.md'
66
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">.+<strong class="livingstyleguide--code-highlight">example</strong>.+</code></pre>
67
+ HTML
68
+ end
69
+
70
+ def test_code_with_highlight_block
71
+ assert_markdown <<-HTML, 'code-with-highlight-block.md'
72
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code"><strong class="livingstyleguide--code-highlight-block">.+Block example.+</strong></code></pre>
73
+ HTML
74
+ end
75
+
76
+ def test_example_with_highlight
77
+ assert_markdown <<-HTML, 'example-with-highlight.md'
78
+ <div class="livingstyleguide--example">
79
+ <img class="inline example">
80
+ <img class="inline ex-1 ex-2">
81
+ </div>
82
+ <pre class="livingstyleguide--code-block"><code class="livingstyleguide--code">.+<strong class="livingstyleguide--code-highlight">example</strong>.+
83
+ <strong class="livingstyleguide--code-highlight">ex-1</strong> <strong class="livingstyleguide--code-highlight">ex-2</strong>.+</code></pre>
84
+ HTML
85
+ end
86
+
87
+ def test_variables
88
+ assert_markdown <<-HTML, 'variables.md'
89
+ <ul class="livingstyleguide--color-swatches">
90
+ <li class="livingstyleguide--color-swatch $blue">$blue</li>
91
+ <li class="livingstyleguide--color-swatch $green">$green</li>
92
+ </ul>
93
+ HTML
94
+ end
95
+
96
+ def test_font_example
97
+ assert_markdown <<-HTML, 'font-example.md'
98
+ <div class="livingstyleguide--font-example" style="font: 16px Courier">
99
+ ABCDEFGHIJKLMNOPQRSTUVWXYZ<br>
100
+ abcdefghijklmnopqrstuvwxyz<br>
101
+ 0123456789<br>
102
+ !&/()$=@;:,.
103
+ </div>
104
+ HTML
105
+ end
106
+
107
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+ require 'fileutils'
3
+ require 'compass'
4
+ require 'compass/logger'
5
+ require 'sass/plugin'
6
+
7
+ class VariablesImporterTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ Compass.configure_sass_plugin!
11
+ end
12
+
13
+ def render(scss)
14
+ scss = %Q(@import "compass"; #{scss})
15
+ options = Compass.sass_engine_options
16
+ options[:line_comments] = false
17
+ options[:style] = :expanded
18
+ options[:syntax] = :scss
19
+ options[:compass] ||= {}
20
+ options[:compass][:logger] ||= Compass::NullLogger.new
21
+ css = Sass::Engine.new(scss, options).render
22
+ format_css(css)
23
+ end
24
+
25
+ def format_css(css)
26
+ css.gsub! %Q(@charset "UTF-8";), ''
27
+ css.gsub! %r(\n), "\n "
28
+ css.gsub! %r( +$), ''
29
+ css.gsub! %r(\n\n+), "\n"
30
+ css.strip!
31
+ %Q( #{css}\n)
32
+ end
33
+
34
+ def test_output_of_variables
35
+ css = render <<-SCSS
36
+ $livingstyleguide--color: black;
37
+ %livingstyleguide--code {
38
+ test: code;
39
+ }
40
+ %livingstyleguide--color-swatch {
41
+ test: color;
42
+ }
43
+ @import "variables/colors";
44
+ @import "variables:variables/colors";
45
+ SCSS
46
+
47
+ assert_equal <<-CSS, css
48
+ .\\$my-wonderful_red:after, .\\$blue:after {
49
+ test: code;
50
+ }
51
+ .\\$my-wonderful_red {
52
+ test: color;
53
+ }
54
+ .\\$my-wonderful_red:before {
55
+ background: red;
56
+ }
57
+ .\\$my-wonderful_red:after {
58
+ content: "red";
59
+ }
60
+ .\\$blue:after {
61
+ content: "blue";
62
+ }
63
+ CSS
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ require 'compass'
2
+ require 'livingstyleguide'
3
+ require 'test/unit'
4
+
5
+ Compass.configuration.add_import_path File.join(%w(test fixtures stylesheets))
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class SassExtensionsTest < Test::Unit::TestCase
4
+ def test_list_variables_for_file
5
+ assert_equal 'my-wonderful_red blue', evaluate(%Q(list-variables("variables/colors.scss")))
6
+ end
7
+
8
+ def test_list_variables_for_scss_files_without_extension
9
+ assert_equal 'my-wonderful_red blue', evaluate(%Q(list-variables("variables/colors")))
10
+ end
11
+
12
+ def test_list_variables_for_sass_files_without_extension
13
+ assert_equal 'blue green', evaluate(%Q(list-variables("variables/other-colors")))
14
+ end
15
+
16
+ def test_list_variables_for_files_starting_with_underscore
17
+ assert_equal 'blue green', evaluate(%Q(list-variables("variables/more-other-colors")))
18
+ end
19
+
20
+ def test_list_variables_for_directories
21
+ assert_equal 'blue green my-wonderful_red', evaluate(%Q(list-variables("variables/*")))
22
+ end
23
+
24
+ protected
25
+ def evaluate(value)
26
+ Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livingstyleguide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,88 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minisyntax
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: middleman
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.9
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.9
46
+ - !ruby/object:Gem::Dependency
47
+ name: compass
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sass
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: redcarpet
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
14
94
  description: Living Style Guide
15
95
  email:
16
96
  - nico@hagenburger.net
@@ -24,8 +104,34 @@ files:
24
104
  - README.md
25
105
  - Rakefile
26
106
  - lib/livingstyleguide.rb
107
+ - lib/livingstyleguide/markdown_extensions.rb
108
+ - lib/livingstyleguide/sass_extensions.rb
109
+ - lib/livingstyleguide/sass_extensions/functions.rb
110
+ - lib/livingstyleguide/variables_importer.rb
111
+ - lib/livingstyleguide/variables_importer/content.erb
27
112
  - lib/livingstyleguide/version.rb
28
113
  - livingstyleguide.gemspec
114
+ - stylesheets/_livingstyleguide.scss
115
+ - stylesheets/livingstyleguide/_code.scss
116
+ - stylesheets/livingstyleguide/_color-swatches.scss
117
+ - stylesheets/livingstyleguide/_content.scss
118
+ - stylesheets/livingstyleguide/_layout.scss
119
+ - test/fixtures/markdown/code-with-highlight-block.md
120
+ - test/fixtures/markdown/code-with-highlight.md
121
+ - test/fixtures/markdown/code.md
122
+ - test/fixtures/markdown/example-with-highlight.md
123
+ - test/fixtures/markdown/example.md
124
+ - test/fixtures/markdown/font-example.md
125
+ - test/fixtures/markdown/layout-example.md
126
+ - test/fixtures/markdown/text.md
127
+ - test/fixtures/markdown/variables.md
128
+ - test/fixtures/stylesheets/variables/_more-other-colors.sass
129
+ - test/fixtures/stylesheets/variables/colors.scss
130
+ - test/fixtures/stylesheets/variables/other-colors.sass
131
+ - test/integration/markdown_test.rb
132
+ - test/integration/variables_test.rb
133
+ - test/test_helper.rb
134
+ - test/unit/sass_extensions_test.rb
29
135
  homepage: ''
30
136
  licenses: []
31
137
  post_install_message:
@@ -50,4 +156,21 @@ rubygems_version: 1.8.23
50
156
  signing_key:
51
157
  specification_version: 3
52
158
  summary: Living Style Guide
53
- test_files: []
159
+ test_files:
160
+ - test/fixtures/markdown/code-with-highlight-block.md
161
+ - test/fixtures/markdown/code-with-highlight.md
162
+ - test/fixtures/markdown/code.md
163
+ - test/fixtures/markdown/example-with-highlight.md
164
+ - test/fixtures/markdown/example.md
165
+ - test/fixtures/markdown/font-example.md
166
+ - test/fixtures/markdown/layout-example.md
167
+ - test/fixtures/markdown/text.md
168
+ - test/fixtures/markdown/variables.md
169
+ - test/fixtures/stylesheets/variables/_more-other-colors.sass
170
+ - test/fixtures/stylesheets/variables/colors.scss
171
+ - test/fixtures/stylesheets/variables/other-colors.sass
172
+ - test/integration/markdown_test.rb
173
+ - test/integration/variables_test.rb
174
+ - test/test_helper.rb
175
+ - test/unit/sass_extensions_test.rb
176
+ has_rdoc: