kss-rails 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .DS_Store
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kss-server.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Garrett Bjerkhoel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ KSS Rails
2
+ =========
3
+
4
+ KSS Rails provides a Rails 3 engine for you to mount onto your existing Rails 3 application that will automatically parse your stylesheets that live within `app/assets/stylesheets` and give you a styleguide visible at whichever URL you choose.
5
+
6
+ Install the gem:
7
+
8
+ ```
9
+ gem install kss-rails
10
+ ```
11
+
12
+ Add it to the development group within the `Gemfile` and re-bundle:
13
+
14
+ ```ruby
15
+ group :development do
16
+ gem 'kss-rails'
17
+ end
18
+ ```
19
+
20
+ Run the install generator:
21
+
22
+ ```
23
+ rails generate kss:install
24
+ ```
25
+
26
+ The install generator will have already appended the route for KSS Rails for you at the '/kss' URL, but if you'd like to change that you can within your routes file.
27
+
28
+ ```ruby
29
+ Example::Application.routes.draw do
30
+ root :to => 'home#index'
31
+
32
+ mount Kss::Engine => '/kss' if Rails.env.development?
33
+ end
34
+ ```
35
+
36
+ That's it, restart your app and visit `http://yoururl/kss` (or whichever URL you choose).
37
+
38
+ Please visit the [KSS repo](https://github.com/kneath/kss) for further documentation and helpful tips.
39
+
40
+ ## Customizing
41
+
42
+ Out of the box KSS Rails has built in templates, stylesheets and javascripts that you can use without any customization just fine.
43
+
44
+ But if you're looking to add more layout styles or updating the templates, you can create your own copy within your application at any of the paths within the [app folder](https://github.com/dewski/kss-rails/tree/master/app).
45
+
46
+ ## Credits
47
+
48
+ All credit goes to Kyle Neath for creating the KSS gem and hopefully this allow people to create styleguides for every site they work on without much effort.
49
+
50
+ ## Note on Patches/Pull Requests
51
+
52
+ - Fork the project.
53
+ - Make your feature addition or bug fix.
54
+ - Add tests for it. This is important so I don't break it in a future version unintentionally.
55
+ - Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
56
+ - Send me a pull request. Bonus points for topic branches.
57
+
58
+ ## Copyright
59
+ Copyright © 2011 Garrett Bjerkhoel. See [MIT-LICENSE](http://github.com/dewski/kss-rails/blob/master/MIT-LICENSE) for details.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,39 @@
1
+ # This class scans your stylesheets for pseudo classes, then inserts a new CSS
2
+ # rule with the same properties, but named 'psuedo-class-{{name}}'.
3
+ #
4
+ # Supported pseudo classes: hover, disabled.
5
+ #
6
+ # Example:
7
+ #
8
+ # a:hover{ color:blue; }
9
+ # => a.pseudo-class-hover{ color:blue; }
10
+ class KssStateGenerator
11
+ constructor: ->
12
+ hover = /:hover/
13
+ disabled = /:disabled/
14
+ active = /:active/
15
+
16
+ try
17
+ for stylesheet in document.styleSheets
18
+ idxs = []
19
+ for rule, idx in stylesheet.cssRules
20
+ if rule.type is CSSRule.STYLE_RULE and (hover.test(rule.selectorText) or disabled.test(rule.selectorText) or active.test(rule.selectorText))
21
+ @insertRule(rule.cssText.replace(':', '.pseudo-class-'))
22
+
23
+ # Takes a given style and attaches it to the current page.
24
+ #
25
+ # rule - A CSS rule String (ex: ".test{ display:none; }").
26
+ #
27
+ # Returns nothing.
28
+ insertRule: (rule) ->
29
+ headEl = document.getElementsByTagName('head')[0]
30
+ styleEl = document.createElement('style')
31
+ styleEl.type = 'text/css'
32
+ if styleEl.styleSheet
33
+ styleEl.styleSheet.cssText = rule
34
+ else
35
+ styleEl.appendChild(document.createTextNode(rule))
36
+
37
+ headEl.appendChild(styleEl)
38
+
39
+ new KssStateGenerator
@@ -0,0 +1,142 @@
1
+ /*----------------------------------------------------------------------------
2
+ @group Global Reset
3
+ ----------------------------------------------------------------------------*/
4
+ * {
5
+ padding:0;
6
+ margin:0;
7
+ }
8
+ h1, h2, h3, h4, h5, h6, p, pre, blockquote, label, ul, ol, dl, fieldset, address { margin:1em 0; }
9
+ li, dd { margin-left:5%; }
10
+ fieldset { padding: .5em; }
11
+ select option{ padding:0 5px; }
12
+
13
+ .access{ display:none; } /* For accessibility related elements */
14
+ .clear{ clear:both; height:0px; font-size:0px; line-height:0px; overflow:hidden; }
15
+ a{ outline:none; }
16
+ a img{ border:none; }
17
+
18
+ .clearfix:after {
19
+ content: ".";
20
+ display: block;
21
+ height: 0;
22
+ clear: both;
23
+ visibility: hidden;
24
+ }
25
+ * html .clearfix {height: 1%;}
26
+ .clearfix {display:inline-block;}
27
+ .clearfix {display: block;}
28
+
29
+ /* @end */
30
+
31
+ body{
32
+ font-family:Helvetica, Arial, sans-serif;
33
+ font-size:14px;
34
+ }
35
+
36
+ header{
37
+ padding:10px;
38
+
39
+ font-size:16px;
40
+ color:#666;
41
+
42
+ background:#f1f1f1;
43
+ border-bottom:1px solid #ddd;
44
+ }
45
+
46
+ #wrapper{
47
+ padding-left:200px;
48
+ padding-right: 25px;
49
+ }
50
+
51
+ nav[role=main]{
52
+ float:left;
53
+ margin-left:-200px;
54
+ width:160px;
55
+ }
56
+ nav ul{
57
+ margin-left:10px;
58
+ }
59
+ nav li{
60
+ list-style-type:none;
61
+ margin:10px 0;
62
+ }
63
+ nav li a{
64
+ text-decoration:none;
65
+ color:#666;
66
+ }
67
+
68
+ /*----------------------------------------------------------------------------
69
+ @group Styleguide Styles
70
+ ----------------------------------------------------------------------------*/
71
+
72
+ h1.styleguide {
73
+ margin: 0 0 -5px 0;
74
+ font-size: 24px;
75
+ color: #000; }
76
+
77
+ .styleguide-example {
78
+ margin: 15px 0;
79
+ background: rgba(255, 255, 255, 0.5);
80
+ border: 1px solid #ddd;
81
+ box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); }
82
+ .styleguide-example > h3 {
83
+ margin: 0;
84
+ padding: 5px;
85
+ color: #fff;
86
+ font-size: 12px;
87
+ text-transform: uppercase;
88
+ background: #333;
89
+ border-top: 1px solid #000; }
90
+ .styleguide-example > h3 em {
91
+ float: right;
92
+ text-transform: none;
93
+ font-style: normal;
94
+ font-weight: normal;
95
+ color: #999; }
96
+ .styleguide-example .styleguide-description {
97
+ padding: 10px 5px;
98
+ background: #f1f1f1;
99
+ border-bottom: 1px solid #ddd; }
100
+ .styleguide-example .styleguide-description p:first-child {
101
+ margin-top: 0; }
102
+ .styleguide-example .styleguide-description p:last-child {
103
+ margin-bottom: 0; }
104
+ .styleguide-example .styleguide-element {
105
+ position: relative;
106
+ padding: 20px; }
107
+ .styleguide-example .styleguide-element + .styleguide-element {
108
+ margin-top: -5px;
109
+ padding-top: 15px;
110
+ border-top: 1px solid #eee; }
111
+ .styleguide-example .styleguide-element .styleguide-modifier-name {
112
+ display: block;
113
+ position: absolute;
114
+ top: 0;
115
+ right: 0;
116
+ padding: 5px 8px;
117
+ font-size: 11px;
118
+ color: #999;
119
+ background: #f9f9f9;
120
+ border: 1px solid #eee;
121
+ border-top: none; }
122
+ .styleguide-example .styleguide-html {
123
+ padding: 5px 10px;
124
+ background: #edf6f8;
125
+ border-top: 1px solid #dde7ea;
126
+ overflow: auto; }
127
+ .styleguide-example .styleguide-html .highlight {
128
+ background: none; }
129
+ .styleguide-example ul.styleguide-modifiers {
130
+ margin: 0 0 0 10px; }
131
+ .styleguide-example ul.styleguide-modifiers li {
132
+ list-style-type: none;
133
+ margin-left: 0; }
134
+ .styleguide-example ul.styleguide-modifiers li strong {
135
+ font-family: Monaco, monospace;
136
+ font-size: 12px;
137
+ font-weight: normal;
138
+ color: #222; }
139
+
140
+ /* @end */
141
+
142
+ //= require application
@@ -0,0 +1,10 @@
1
+ module Kss
2
+ class ApplicationController < ::ApplicationController
3
+ private
4
+
5
+ def styleguide
6
+ @styleguide ||= Kss::Parser.new(File.expand_path('app/assets/stylesheets', Rails.root))
7
+ end
8
+ helper_method :styleguide
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Kss
2
+ class HomeController < ApplicationController
3
+ def index
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ module Kss
2
+ module ApplicationHelper
3
+ # Generates a styleguide block. A little bit evil with @_out_buf, but
4
+ # if you're using something like Rails, you can write a much cleaner helper
5
+ # very easily.
6
+ def styleguide_block(section, &block)
7
+ raise ArgumentError, "Missing block" unless block_given?
8
+
9
+ @section = styleguide.section(section)
10
+ content = capture(&block)
11
+ render 'kss/shared/styleguide_block', :section => @section, :example_html => content
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Welcome!</h1>
2
+ <p>This is an example <a href="/styleguide">styleguide</a>. To customize this page, create a file at <code>app/views/kss/home/index.html.erb</code>.</p>
@@ -0,0 +1,22 @@
1
+ <div class="styleguide-example">
2
+ <h3><%= section.section %> <em><%= section.filename %></em></h3>
3
+ <div class="styleguide-description">
4
+ <p><%= section.description %></p>
5
+ <% if section.modifiers.any? %>
6
+ <ul class="styleguide-modifier">
7
+ <% section.modifiers.each do |modifier| %>
8
+ <li><strong><%= modifier.name %></strong> - <%= modifier.description %></li>
9
+ <% end %>
10
+ </ul>
11
+ <% end %>
12
+ </div>
13
+ <div class="styleguide-element">
14
+ <%= example_html.html_safe %>
15
+ </div>
16
+ <% section.modifiers.each do |modifier| %>
17
+ <div class="styleguide-element styleguide-modifier">
18
+ <span class="styleguide-modifier-name"><%= modifier.name %></span>
19
+ <%= example_html.sub('$modifier_class', " #{modifier.class_name}").html_safe %>
20
+ </div>
21
+ <% end %>
22
+ </div>
@@ -0,0 +1,5 @@
1
+ Kss::Engine.routes.draw do
2
+ get '/styleguide' => 'home#styleguide'
3
+
4
+ root :to => 'home#index'
5
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["Garrett Bjerkhoel"]
4
+ gem.email = ["me@garrettbjerkhoel.com"]
5
+ gem.description = %q{Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.}
6
+ gem.summary = %q{Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.}
7
+ gem.homepage = "https://github.com/dewski/kss-rails"
8
+
9
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
10
+ gem.files = `git ls-files`.split("\n")
11
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ gem.name = "kss-rails"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = '1.0'
15
+
16
+ gem.add_dependency 'kss'
17
+ gem.add_dependency 'rails', '>= 3.0.0'
18
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Kss
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+ desc "KSS Rails Install"
7
+
8
+ def install_steps
9
+ copy_file 'index.html.erb', 'app/views/kss/home/index.html.erb'
10
+ copy_file 'styleguide.html.erb', 'app/views/kss/home/styleguide.html.erb'
11
+ copy_file 'application.html.erb', 'app/views/layouts/kss/application.html.erb'
12
+ route "mount Kss::Engine => '/kss' if Rails.env.development?"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
5
+ <title>KSS Styleguide</title>
6
+ <%= stylesheet_link_tag 'kss' %>
7
+ <%= stylesheet_link_tag 'application' %>
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ </head>
10
+ <body>
11
+ <header>
12
+ KSS Styleguide Example
13
+ </header>
14
+
15
+ <div id="wrapper">
16
+ <nav role="main">
17
+ <ul>
18
+ <li><%= link_to 'Home', kss.root_path %></li>
19
+ <li><%= link_to 'Styleguide', kss.styleguide_path %></li>
20
+ </ul>
21
+ </nav>
22
+
23
+ <%= yield %>
24
+ </div><!-- /#wrapper -->
25
+
26
+ <%= javascript_include_tag 'kss' %>
27
+ </body>
28
+ </html>
@@ -0,0 +1,2 @@
1
+ <h1>Welcome!</h1>
2
+ <p>This is an example <a href="/styleguide">styleguide</a>. To customize this page, create a file at <code>app/views/kss/home/index.html.erb</code>.</p>
@@ -0,0 +1,12 @@
1
+ <%= styleguide_block '1.1' do -%>
2
+ <button class="$modifier_class">Example Button</button>
3
+ <% end -%>
4
+ <p>This block above was created with a simple template call:</p>
5
+ <pre><code>&lt;%= styleguide_block &#x27;1.1&#x27; do %&gt;
6
+ &lt;button class=&quot;$modifier_class&quot;&gt;Example Button&lt;/button&gt;
7
+ &lt;% end %&gt;</code></pre>
8
+ <p>
9
+ Take a look at the source code of this Rails engine for more details. The goal
10
+ is to remove the pain from creating a styleguide — document your CSS, have
11
+ example HTML in your templates and automate as much as possible.
12
+ </p>
@@ -0,0 +1 @@
1
+ require 'kss/engine'
@@ -0,0 +1,11 @@
1
+ require 'kss'
2
+
3
+ module Kss
4
+ class Engine < Rails::Engine
5
+ # Isolate
6
+ isolate_namespace Kss
7
+
8
+ # Used as default namespace for routes
9
+ engine_name :kss
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kss-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Garrett Bjerkhoel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: kss
16
+ requirement: &70218052170120 !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: *70218052170120
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70218052169000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70218052169000
36
+ description: Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.
37
+ email:
38
+ - me@garrettbjerkhoel.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - MIT-LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - app/assets/javascripts/kss.coffee
49
+ - app/assets/stylesheets/kss.css.scss
50
+ - app/controllers/kss/application_controller.rb
51
+ - app/controllers/kss/home_controller.rb
52
+ - app/helpers/kss/application_helper.rb
53
+ - app/views/kss/home/index.html.erb
54
+ - app/views/kss/shared/_styleguide_block.erb
55
+ - config/routes.rb
56
+ - kss-rails.gemspec
57
+ - lib/generators/kss/install_generator.rb
58
+ - lib/generators/templates/application.html.erb
59
+ - lib/generators/templates/index.html.erb
60
+ - lib/generators/templates/styleguide.html.erb
61
+ - lib/kss-rails.rb
62
+ - lib/kss/engine.rb
63
+ homepage: https://github.com/dewski/kss-rails
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.10
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.
87
+ test_files: []