kss-rails-alan 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # 1.0
2
+
3
+ * Initial release
4
+
5
+ # 1.0.1
6
+
7
+ * Added kss/application layout to the KSS::ApplicationController
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,58 @@
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 which will copy over some initial templates for you to base your styleguide definitions off of. There may be some extra changes to the layouts that you need to do, but that is dependent on how crazy your application is.
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 will allow people to create styleguides for every site they work on with little to no additional effort.
49
+
50
+ ## Note on Patches/Pull Requests
51
+
52
+ - Fork the project.
53
+ - Make your feature addition or bug fix.
54
+ - 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)
55
+ - Send me a pull request. Bonus points for topic branches.
56
+
57
+ ## Copyright
58
+ Copyright © 2011 Garrett Bjerkhoel. See [MIT-LICENSE](http://github.com/dewski/kss-rails/blob/master/MIT-LICENSE) for details.
data/Rakefile ADDED
@@ -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, active, visited.
5
+ #
6
+ # Example:
7
+ #
8
+ # a:hover{ color:blue; }
9
+ # => a.pseudo-class-hover{ color:blue; }
10
+ class KssStateGenerator
11
+ constructor: ->
12
+ pseudos = /(\:hover|\:disabled|\:active|\:visited)/g
13
+
14
+ try
15
+ for stylesheet in document.styleSheets
16
+ idxs = []
17
+ for rule, idx in stylesheet.cssRules
18
+ if (rule.type == CSSRule.STYLE_RULE) && pseudos.test(rule.selectorText)
19
+ replaceRule = (matched, stuff) ->
20
+ return ".pseudo-class-" + matched.replace(':', '')
21
+ @insertRule(rule.cssText.replace(pseudos, replaceRule))
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
+ .kss-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
+ #kss_wrapper{
47
+ padding-left:200px;
48
+ padding-right: 25px;
49
+ }
50
+
51
+ nav.kss-nav{
52
+ float:left;
53
+ margin-left:-200px;
54
+ width:160px;
55
+ }
56
+ nav.kss-nav ul{
57
+ margin-left:10px;
58
+ }
59
+ nav.kss-nav>li{
60
+ list-style-type:none;
61
+ margin:10px 0;
62
+ }
63
+ nav.kss-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,12 @@
1
+ module Kss
2
+ class ApplicationController < ::ApplicationController
3
+ layout 'kss/application'
4
+
5
+ private
6
+
7
+ def styleguide
8
+ @styleguide ||= Kss::Parser.new(File.expand_path('app/assets/stylesheets', Rails.root))
9
+ end
10
+ helper_method :styleguide
11
+ end
12
+ 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.gsub('$modifier_class', modifier.class_name).html_safe %>
20
+ </div>
21
+ <% end %>
22
+ </div>
data/config/routes.rb ADDED
@@ -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 = ['Alan Hogan']
4
+ gem.email = ['gem@alanhogan.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 (forked from Garrett Bjerkhoel).}
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-alan'
13
+ gem.require_paths = ['lib']
14
+ gem.version = '1.0.1'
15
+
16
+ gem.add_dependency 'kss-alan'
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 class="kss-header">
12
+ KSS Styleguide Example
13
+ </header>
14
+
15
+ <div id="kss_wrapper">
16
+ <nav role="main">
17
+ <ul class="kss-nav">
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>
data/lib/kss/engine.rb ADDED
@@ -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
data/lib/kss-rails.rb ADDED
@@ -0,0 +1 @@
1
+ require 'kss/engine'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kss-rails-alan
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alan Hogan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: kss-alan
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: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
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.0
46
+ description: Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.
47
+ email:
48
+ - gem@alanhogan.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - CHANGELOG.md
55
+ - Gemfile
56
+ - MIT-LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - app/assets/javascripts/kss.coffee
60
+ - app/assets/stylesheets/kss.css.scss
61
+ - app/controllers/kss/application_controller.rb
62
+ - app/controllers/kss/home_controller.rb
63
+ - app/helpers/kss/application_helper.rb
64
+ - app/views/kss/home/index.html.erb
65
+ - app/views/kss/shared/_styleguide_block.erb
66
+ - config/routes.rb
67
+ - kss-rails-alan.gemspec
68
+ - lib/generators/kss/install_generator.rb
69
+ - lib/generators/templates/application.html.erb
70
+ - lib/generators/templates/index.html.erb
71
+ - lib/generators/templates/styleguide.html.erb
72
+ - lib/kss-rails.rb
73
+ - lib/kss/engine.rb
74
+ homepage: https://github.com/dewski/kss-rails
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.24
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Rails 3 engine to provide a living styleguide from Kyle Neath's KSS (forked
98
+ from Garrett Bjerkhoel).
99
+ test_files: []