gkss-rails 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.
@@ -0,0 +1,127 @@
1
+ # # Nkss: Helpers
2
+ # A bunch of helpers you can use in your styleguides.
3
+
4
+ module StyleguideHelper
5
+
6
+ # ### kss_block
7
+ # Documents a styleguide block.
8
+ #
9
+ # Some options you can specify:
10
+ #
11
+ # * `background` - The background color. Can be *clear*, *white*, *black*,
12
+ # *light*, or *dark*.
13
+ #
14
+ # * `align` - Text alignment. Can be *left*, *right*, or *center*.
15
+ #
16
+ # * `width` - (Optional) width for the inner area. Specify this for
17
+ # documenting long things.
18
+ #
19
+ # Example:
20
+ #
21
+ # = kss_block '1.1' do
22
+ # %div.foo
23
+ # Put markup here!
24
+ #
25
+ # Example with options:
26
+ #
27
+ # = kss_block '1.1', background: 'dark' do
28
+ #
29
+ def kss_block(section_id, options={}, &block)
30
+ section = @styleguide.section(section_id)
31
+
32
+ raise "Section '#{section_id}' not found." unless section.filename
33
+
34
+ example_html = capture(&block)
35
+
36
+ defaults = { background: 'light', align: 'left', code: 'true' }
37
+ options = defaults.merge(options)
38
+
39
+ bg = "bg-#{options[:background]}"
40
+ align = "align-#{options[:align]}"
41
+ classes = [bg, align]
42
+
43
+ inner_style = ''
44
+ inner_style = "width: #{options[:width]}px; margin: 0 auto" if options[:width]
45
+
46
+ render \
47
+ partial: 'styleguides/block',
48
+ locals: {
49
+ canvas_class: classes.join(' '),
50
+ code_block: block,
51
+ html: example_html,
52
+ section: section,
53
+ modifiers: (section.modifiers rescue Array.new),
54
+ options: options,
55
+ inner_style: inner_style,
56
+ }
57
+ end
58
+
59
+ # ### kss_specimen
60
+ # Renders a type specimen. This is great for demoing fonts.
61
+ # Use it like so:
62
+ #
63
+ # = kss_block '2.1' do
64
+ # .proxima-nova
65
+ # = kss_specimen
66
+ #
67
+ # This gets you a `<div class='sg-specimen'>` block which has already been
68
+ # styled to showcase different sizes of the given font.
69
+
70
+ def kss_specimen
71
+ render partial: 'styleguides/specimen'
72
+ end
73
+
74
+ # ### kss_swatch
75
+ # Renders a type specimen. This is great for demoing colors.
76
+ #
77
+ # = kss_block '2.1' do
78
+ # = kss_swatch 'red', '#ff3322', description: 'for error text'
79
+
80
+ def kss_swatch(name, color, options={})
81
+ render partial: 'styleguides/swatch', locals: {
82
+ name: name,
83
+ identifier: name,
84
+ color: color,
85
+ dark: options[:dark],
86
+ description: options[:description]
87
+ }
88
+ end
89
+
90
+ # ### lorem
91
+ # Convenient lorem ipsum helper.
92
+ #
93
+ # Yeah, well, you'll need this for a lot of styleguide sections. Use it like
94
+ # so:
95
+ #
96
+ # %p= lorem.paragraph
97
+ # %li= lorem.sentence
98
+ #
99
+ def lorem
100
+ require 'ffaker'
101
+
102
+ Faker::Lorem
103
+ end
104
+
105
+ # ### kss_markdown
106
+ # Markdownify some text.
107
+
108
+ def kss_markdown(text)
109
+ text.gsub!(/^\s*\-*=*\s*\n*/, '') # Strip '----' lines
110
+ lines = text.split("\n")
111
+
112
+ # Transform the first line
113
+ if lines.length > 0
114
+ lines[0].gsub!(/^#*\s*/, '## ') # "Hello" => "## Hello"
115
+ lines[0].gsub!(/\((.*?)\):?$/, '`\1`') # "Hey (code):" => "Hey `code`"
116
+ end
117
+
118
+ text = lines.join("\n")
119
+
120
+ # Markdownify
121
+ require 'bluecloth'
122
+ str = BlueCloth.new(text).to_html
123
+ str = str.html_safe if str.respond_to?(:html_safe)
124
+ str
125
+ end
126
+
127
+ end
@@ -0,0 +1,144 @@
1
+ -# # Templates: Styleguide page template
2
+ -# This formats your styleguides.
3
+ -#
4
+ -# It puts things into `:body` and `:head`, and calls the `layouts/styleguide`
5
+ -# layout, which you should have in your app.
6
+ -#
7
+ -# Don't like me? Just copy me into your
8
+ -# `app/views/layouts/styleguide_page.html.haml` and customize me.
9
+
10
+ !!! 5
11
+ %html
12
+ %head
13
+ %meta{charset: 'utf-8'}
14
+ %title Styleguides
15
+ = stylesheet_link_tag styleguide_include_js
16
+ = javascript_include_tag 'prettify'
17
+ = javascript_include_tag 'jquery-1.8.0.min'
18
+ = stylesheet_link_tag 'styleguide'
19
+ = stylesheet_link_tag 'prettify'
20
+
21
+ %body
22
+ %button.sg-toggle-sidebar
23
+
24
+ %aside.sg-toc
25
+ %h1
26
+ %strong= styleguide_title
27
+ %small Style guide
28
+
29
+ %ul
30
+ - styleguide_sections.each do |id, name|
31
+ %li
32
+ - href = @single_page ? "##{id}" : id
33
+ - klass = @single_page ? "" : (id == @section ? 'active' : '')
34
+ %a{class: klass, href: href}
35
+ %span.sg-number= "#{id}"
36
+ %span.sg-name= name
37
+
38
+ %section.sg-body
39
+ = yield
40
+
41
+ :javascript
42
+ // Pretty printer script
43
+ (function() {
44
+ var pretty = false;
45
+ $('.sg-view-code').on('click', function expand() {
46
+ if (!pretty) {
47
+ prettyPrint();
48
+ pretty = true;
49
+ }
50
+
51
+ var $block = $(this).closest('.sg-example');
52
+ $block.find('.sg-html').toggleClass('sg-expanded');
53
+ $block.find('.sg-view-code').toggleClass('sg-expanded');
54
+ });
55
+ })();
56
+
57
+ // Sidebar toggler script
58
+ (function() {
59
+ $('.sg-toggle-sidebar').on('click', function() {
60
+ $('body').toggleClass('sg-full');
61
+ });
62
+ })();
63
+
64
+ (function() {
65
+ });
66
+
67
+ // Scrollspy script
68
+ (function() {
69
+ $.fn.scrollagent = function(options, callback) {
70
+ // Account for $.scrollspy(function)
71
+ if (typeof callback === 'undefined') {
72
+ callback = options;
73
+ options = {};
74
+ }
75
+
76
+ var $sections = $(this);
77
+ var $parent = options.parent || $(window);
78
+
79
+ // Find the top offsets of each section
80
+ var offsets = [];
81
+ $sections.each(function(i) {
82
+ offsets.push({
83
+ top: $(this).offset().top,
84
+ id: $(this).attr('id'),
85
+ index: i,
86
+ el: this
87
+ });
88
+ });
89
+
90
+ // State
91
+ var current = null;
92
+ var height = null;
93
+ var range = null;
94
+
95
+ // Save the height. Do this only whenever the window is resized so we don't
96
+ // recalculate often.
97
+ $(window).on('resize', function onresize() {
98
+ height = $parent.height();
99
+ range = $(document).height();
100
+ });
101
+
102
+ // Find the current active section every scroll tick.
103
+ $parent.on('scroll', function() {
104
+ var y = $parent.scrollTop();
105
+ y += height * (0.3 + 0.7 * Math.pow(y/range, 2));
106
+
107
+ var latest = null;
108
+
109
+ for (var i in offsets) {
110
+ if (offsets.hasOwnProperty(i)) {
111
+ var offset = offsets[i];
112
+ if (offset.top < y) latest = offset;
113
+ }
114
+ }
115
+
116
+ if (latest && (!current || (latest.index !== current.index))) {
117
+ callback.call($sections,
118
+ latest ? latest.id : null,
119
+ current ? current.id : null,
120
+ latest ? latest.el : null,
121
+ current ? current.el : null);
122
+ current = latest;
123
+ }
124
+ });
125
+
126
+ $(window).trigger('resize');
127
+ $parent.trigger('scroll');
128
+
129
+ return this;
130
+ };
131
+
132
+ var $sections = $('.sg-page-title');
133
+
134
+ $sections.scrollagent(function(cid, pid) {
135
+ if (pid) {
136
+ $(".sg-toc [href='#"+pid+"']").removeClass('active');
137
+ }
138
+ if (cid) {
139
+ $(".sg-toc [href='#"+cid+"']").addClass('active');
140
+ }
141
+ });
142
+
143
+ })();
144
+
@@ -0,0 +1,36 @@
1
+ -# # Templates: Block partial
2
+
3
+ -# This is the partial invoked when you use the `kss_guide` helper.
4
+ -# Don't like me? Just copy me into `app/views/styleguides/_block.html.haml` in
5
+ -# your app.
6
+
7
+ %section.sg-example{id: section.section}
8
+ %h3
9
+ %a{href: "##{section.section}"}= section.section
10
+
11
+ %button.sg-button.sg-view-code HTML
12
+
13
+ .sg-description
14
+ %span.sg-filename= section.filename
15
+ != kss_markdown(h(section.description)).html_safe
16
+
17
+ - if section.modifiers.any?
18
+ %ul.sg-modifiers
19
+ - modifiers.each do |modifier|
20
+ %li
21
+ %strong= modifier.name
22
+ = "-"
23
+ = modifier.description
24
+
25
+ .sg-canvases
26
+ .sg-canvas{class: canvas_class}
27
+ %div{style: inner_style}!= html
28
+
29
+ - modifiers.each do |modifier|
30
+ .sg-modifier.sg-canvas{class: canvas_class}
31
+ %span.sg-modifier-name= modifier.name
32
+ %div{style: inner_style}= capture modifier.name, &code_block
33
+
34
+ .sg-html
35
+ %pre.prettyprint.lang-html!= h(html.gsub('', ''))
36
+
@@ -0,0 +1,8 @@
1
+ .sg-specimen
2
+ .sg-drop Ag
3
+ %h3= ('a'..'z').to_a.map { |c| c.upcase + c.downcase }.join(" ")
4
+ %p.sg-small= lorem.sentence
5
+ %p
6
+ %strong= lorem.sentence
7
+ = 2.times.map { lorem.paragraph }.join ' '
8
+ %p= 2.times.map { lorem.paragraph }.join ' '
@@ -0,0 +1,9 @@
1
+ .sg-swatch{class: ('sg-dark' if dark)}
2
+ .sg-text{style: "color: #{color}"}
3
+ = color
4
+
5
+ .sg-background{style: "background: #{color}"}
6
+ %strong= identifier
7
+
8
+ - if description
9
+ %small= description
@@ -0,0 +1,6 @@
1
+ - @sections.each do |id, title|
2
+ - @section = id.to_i
3
+ %h2.sg-page-title{id: id}
4
+ %strong= id
5
+ = title
6
+ = render file: "styleguides/#{@section}"
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Gkss::Engine.routes.draw do
2
+ root :to => 'styleguides#all'
3
+ get ':section' => 'styleguides#show'
4
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Gkss
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+ desc 'Gkss Rails Install'
7
+
8
+ def install_steps
9
+ copy_file '1.html.haml', 'app/views/styleguides/1.html.haml'
10
+ copy_file 'styleguides.yml', 'config/styleguides.yml'
11
+
12
+ route "mount Gkss::Engine => '/gkss' if Rails.env.development?"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ -# This is an example markup for a KSS section.
2
+ -# The definition for `1.1` can be found in your app/assets/stylesheets/ folder.
3
+
4
+ = kss_block '1.1' do
5
+ %div.example
6
+ Example markup
@@ -0,0 +1,6 @@
1
+ title: "My Site"
2
+ root: "app/assets/stylesheets"
3
+ include_js: "application"
4
+ sections:
5
+ 1: Content
6
+ 2: Typography
@@ -0,0 +1,6 @@
1
+ module Gkss
2
+ class Engine < Rails::Engine
3
+ # Same as doing `mount Gkss::Engine => '/stylesheets', as: :gkss`
4
+ engine_name :gkss
5
+ end
6
+ end
data/lib/gkss/rails.rb ADDED
@@ -0,0 +1 @@
1
+ require File.expand_path('../../gkss', __FILE__)
@@ -0,0 +1,3 @@
1
+ module Gkss
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gkss.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Gkss
2
+ end
3
+
4
+ require File.expand_path('../gkss/version', __FILE__)
5
+ require File.expand_path('../gkss/engine', __FILE__)
6
+
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gkss-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - goshan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: kss
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
+ - !ruby/object:Gem::Dependency
42
+ name: ffaker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bluecloth
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: haml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A drop-in, easy-to-use, gorgeous-by-default Rails plugin you can put
84
+ into your projects so you can instantly have cute docspec.
85
+ email:
86
+ - goshan.hanqiu@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - Rakefile
93
+ - app/assets/javascripts/jquery-1.8.0.min.js
94
+ - app/assets/javascripts/prettify.js
95
+ - app/assets/stylesheets/prettify.css
96
+ - app/assets/stylesheets/styleguide.sass
97
+ - app/controllers/styleguides_controller.rb
98
+ - app/helpers/styleguide_helper.rb
99
+ - app/views/layouts/styleguide_page.html.haml
100
+ - app/views/styleguides/_block.html.haml
101
+ - app/views/styleguides/_specimen.html.haml
102
+ - app/views/styleguides/_swatch.html.haml
103
+ - app/views/styleguides/all.html.haml
104
+ - config/routes.rb
105
+ - lib/generators/gkss/install_generator.rb
106
+ - lib/generators/templates/1.html.haml
107
+ - lib/generators/templates/styleguides.yml
108
+ - lib/gkss.rb
109
+ - lib/gkss/engine.rb
110
+ - lib/gkss/rails.rb
111
+ - lib/gkss/version.rb
112
+ homepage: https://github.com/goshan/gkss-rails
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.5.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Living style guide based on https://github.com/nadarei/nkss-railspec.
136
+ test_files: []