stylin 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 (111) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +21 -0
  3. data/app/assets/javascripts/stylin/application.js +4 -0
  4. data/app/assets/javascripts/stylin/highlight.pack.js +1 -0
  5. data/app/assets/javascripts/stylin/kss.js +54 -0
  6. data/app/assets/javascripts/stylin/styleguides.js +2 -0
  7. data/app/assets/stylesheets/stylin/_header.scss +12 -0
  8. data/app/assets/stylesheets/stylin/_navigation.css.scss +12 -0
  9. data/app/assets/stylesheets/stylin/application.css.scss +5 -0
  10. data/app/assets/stylesheets/stylin/highlight/arta.css +160 -0
  11. data/app/assets/stylesheets/stylin/highlight/ascetic.css +50 -0
  12. data/app/assets/stylesheets/stylin/highlight/brown_paper.css +105 -0
  13. data/app/assets/stylesheets/stylin/highlight/dark.css +105 -0
  14. data/app/assets/stylesheets/stylin/highlight/default.css +153 -0
  15. data/app/assets/stylesheets/stylin/highlight/docco.css +132 -0
  16. data/app/assets/stylesheets/stylin/highlight/far.css +113 -0
  17. data/app/assets/stylesheets/stylin/highlight/foundation.css +133 -0
  18. data/app/assets/stylesheets/stylin/highlight/github.css +125 -0
  19. data/app/assets/stylesheets/stylin/highlight/googlecode.css +147 -0
  20. data/app/assets/stylesheets/stylin/highlight/idea.css +122 -0
  21. data/app/assets/stylesheets/stylin/highlight/ir_black.css +105 -0
  22. data/app/assets/stylesheets/stylin/highlight/magula.css +123 -0
  23. data/app/assets/stylesheets/stylin/highlight/mono-blue.css +62 -0
  24. data/app/assets/stylesheets/stylin/highlight/monokai.css +127 -0
  25. data/app/assets/stylesheets/stylin/highlight/monokai_sublime.css +149 -0
  26. data/app/assets/stylesheets/stylin/highlight/obsidian.css +154 -0
  27. data/app/assets/stylesheets/stylin/highlight/pojoaque.css +106 -0
  28. data/app/assets/stylesheets/stylin/highlight/railscasts.css +182 -0
  29. data/app/assets/stylesheets/stylin/highlight/rainbow.css +112 -0
  30. data/app/assets/stylesheets/stylin/highlight/school_book.css +113 -0
  31. data/app/assets/stylesheets/stylin/highlight/solarized_dark.css +107 -0
  32. data/app/assets/stylesheets/stylin/highlight/solarized_light.css +107 -0
  33. data/app/assets/stylesheets/stylin/highlight/sunburst.css +160 -0
  34. data/app/assets/stylesheets/stylin/highlight/tomorrow-night-blue.css +93 -0
  35. data/app/assets/stylesheets/stylin/highlight/tomorrow-night-bright.css +92 -0
  36. data/app/assets/stylesheets/stylin/highlight/tomorrow-night-eighties.css +92 -0
  37. data/app/assets/stylesheets/stylin/highlight/tomorrow-night.css +93 -0
  38. data/app/assets/stylesheets/stylin/highlight/tomorrow.css +90 -0
  39. data/app/assets/stylesheets/stylin/highlight/vs.css +89 -0
  40. data/app/assets/stylesheets/stylin/highlight/xcode.css +158 -0
  41. data/app/assets/stylesheets/stylin/highlight/zenburn.css +117 -0
  42. data/app/assets/stylesheets/stylin/styleguides.css.scss +106 -0
  43. data/app/controllers/stylin/application_controller.rb +11 -0
  44. data/app/controllers/stylin/styleguides_controller.rb +13 -0
  45. data/app/helpers/stylin/application_helper.rb +4 -0
  46. data/app/helpers/stylin/navigation_helper.rb +50 -0
  47. data/app/helpers/stylin/styleguides_helper.rb +29 -0
  48. data/app/models/styleguide.rb +69 -0
  49. data/app/views/layouts/stylin/_navigation.html.erb +3 -0
  50. data/app/views/layouts/stylin/application.html.erb +26 -0
  51. data/app/views/stylin/styleguides/_section.html.erb +31 -0
  52. data/app/views/stylin/styleguides/index.html.erb +5 -0
  53. data/app/views/stylin/styleguides/show.html.erb +3 -0
  54. data/config/routes.rb +5 -0
  55. data/lib/generators/stylin/install_generator.rb +12 -0
  56. data/lib/generators/stylin/views_generator.rb +10 -0
  57. data/lib/generators/templates/stylin.yml +7 -0
  58. data/lib/generators/templates/views/layouts/stylin/_navigation.html.erb +3 -0
  59. data/lib/generators/templates/views/layouts/stylin/application.html.erb +23 -0
  60. data/lib/generators/templates/views/stylin/styleguides/_section.html.erb +30 -0
  61. data/lib/generators/templates/views/stylin/styleguides/index.html.erb +5 -0
  62. data/lib/generators/templates/views/stylin/styleguides/show.html.erb +3 -0
  63. data/lib/stylin.rb +8 -0
  64. data/lib/stylin/engine.rb +37 -0
  65. data/lib/stylin/version.rb +3 -0
  66. data/lib/tasks/stylin_tasks.rake +12 -0
  67. data/spec/dummy/README.rdoc +28 -0
  68. data/spec/dummy/Rakefile +6 -0
  69. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  70. data/spec/dummy/app/assets/stylesheets/application.css.scss +1 -0
  71. data/spec/dummy/app/assets/stylesheets/buttons.css +51 -0
  72. data/spec/dummy/app/assets/stylesheets/forms.css +51 -0
  73. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  74. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  75. data/spec/dummy/app/styleguides/buttons.html +1 -0
  76. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  77. data/spec/dummy/bin/bundle +3 -0
  78. data/spec/dummy/bin/rails +4 -0
  79. data/spec/dummy/bin/rake +4 -0
  80. data/spec/dummy/config.ru +4 -0
  81. data/spec/dummy/config/application.rb +23 -0
  82. data/spec/dummy/config/boot.rb +5 -0
  83. data/spec/dummy/config/database.yml +25 -0
  84. data/spec/dummy/config/environment.rb +5 -0
  85. data/spec/dummy/config/environments/development.rb +29 -0
  86. data/spec/dummy/config/environments/production.rb +80 -0
  87. data/spec/dummy/config/environments/test.rb +36 -0
  88. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  89. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  90. data/spec/dummy/config/initializers/inflections.rb +16 -0
  91. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  92. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  93. data/spec/dummy/config/initializers/session_store.rb +3 -0
  94. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  95. data/spec/dummy/config/locales/en.yml +23 -0
  96. data/spec/dummy/config/routes.rb +3 -0
  97. data/spec/dummy/config/stylin.yml +3 -0
  98. data/spec/dummy/db/development.sqlite3 +0 -0
  99. data/spec/dummy/db/production.sqlite3 +0 -0
  100. data/spec/dummy/db/schema.rb +16 -0
  101. data/spec/dummy/db/test.sqlite3 +0 -0
  102. data/spec/dummy/log/development.log +4143 -0
  103. data/spec/dummy/log/production.log +4 -0
  104. data/spec/dummy/log/test.log +380 -0
  105. data/spec/dummy/public/404.html +58 -0
  106. data/spec/dummy/public/422.html +58 -0
  107. data/spec/dummy/public/500.html +57 -0
  108. data/spec/dummy/public/favicon.ico +0 -0
  109. data/spec/models/styleguide_spec.rb +55 -0
  110. data/spec/spec_helper.rb +22 -0
  111. metadata +327 -0
@@ -0,0 +1,11 @@
1
+ module Stylin
2
+ class ApplicationController < ActionController::Base
3
+
4
+ private
5
+
6
+ helper_method :styleguide
7
+ def styleguide
8
+ @styleguide ||= Styleguide.new
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require_dependency "stylin/application_controller"
2
+
3
+ module Stylin
4
+ class StyleguidesController < ApplicationController
5
+ def index
6
+ end
7
+
8
+ def show
9
+ section_name = Styleguide.desluggify(params[:id])
10
+ @section = styleguide.find(section: section_name)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Stylin
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,50 @@
1
+ module Stylin
2
+ module NavigationHelper
3
+ def styleguide_navigation
4
+ content_for :styleguide_navigation do
5
+ if APP_CONFIG[:section_groupings]
6
+ custom_section_navigation
7
+ else
8
+ generic_section_navigation
9
+ end
10
+ end
11
+ end
12
+
13
+ def generic_section_navigation
14
+ elements = []
15
+
16
+ Styleguide.new.section_names.each do |section_name|
17
+ elements << section_link(section_name)
18
+ end
19
+
20
+ content_tag(:ul, elements.join("\n").html_safe)
21
+ end
22
+
23
+ def custom_section_navigation
24
+ elements = []
25
+
26
+ APP_CONFIG[:section_groupings].each do |section, description|
27
+ sections = Styleguide.new.find(section_group: section)
28
+
29
+ section_links = sections.map do |section|
30
+ section_link(section.section)
31
+ end
32
+
33
+ elements << content_tag(:li) do
34
+ "#{section} #{description}".html_safe +
35
+ content_tag(:ul, section_links.join("\n").html_safe)
36
+ end
37
+ end
38
+
39
+ content_tag(:ul, elements.join("\n").html_safe)
40
+ end
41
+
42
+ private
43
+
44
+ def section_link(section_name)
45
+ content_tag(:li,
46
+ link_to(section_name, styleguide_path(Styleguide.sluggify(section_name)) )
47
+ )
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ module Stylin
2
+ module StyleguidesHelper
3
+ def example_html(section)
4
+ return @example_html if @example_html
5
+
6
+ if File.exists? example_html_path(section.filename)
7
+ @example_html = File.read( example_html_path(section.filename) ).html_safe
8
+ else
9
+ @example_html = ""
10
+ end
11
+ end
12
+
13
+ def escaped_html(section)
14
+ # to_str below causes html_safe? => false
15
+ ERB::Util.html_escape example_html(section).to_str
16
+ end
17
+
18
+ private
19
+
20
+ def example_html_base_path
21
+ Stylin::APP_CONFIG[:html_styleguides_path]
22
+ end
23
+
24
+ def example_html_path(filename)
25
+ filename = filename.split(/(.*?)\.(.*)/).reject(&:blank?).first
26
+ File.join(example_html_base_path, "#{filename}.html")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,69 @@
1
+ class Styleguide
2
+ attr_reader :section_names, :styleguide
3
+
4
+ def initialize
5
+ @styleguide ||= Kss::Parser.new( Stylin::APP_CONFIG[:stylesheets_path] )
6
+ @section_names ||= styleguide.sections.map{|s| s[1].section}.sort
7
+ end
8
+
9
+
10
+ def find(conditions)
11
+ section = conditions.delete(:section)
12
+ section_group = conditions.delete(:section_group)
13
+
14
+ if section_group.present?
15
+ find_grouped_sections(section_group)
16
+ elsif section.present?
17
+ find_by_section(section)
18
+ end
19
+ end
20
+
21
+ def build_section_hierarchy
22
+
23
+ end
24
+
25
+ def self.sluggify(section)
26
+ numbers = section.split(' ')[0].split('.')
27
+ strings = section.split(' ')[1..-1]
28
+
29
+ "#{numbers.join('-')}-#{strings.join('-')}"
30
+ end
31
+
32
+ def self.desluggify(slug)
33
+ slug_parts = slug.split('-')
34
+ numbers = []
35
+ strings = []
36
+
37
+ slug_parts.each do |slug_part|
38
+ if is_integer?(slug_part)
39
+ numbers << slug_part
40
+ else
41
+ strings << slug_part
42
+ end
43
+ end
44
+
45
+ "#{numbers.join('.')} #{strings.join(' ')}"
46
+ end
47
+
48
+ private
49
+
50
+ def find_by_section(section)
51
+ styleguide.section(section)
52
+ end
53
+
54
+ def find_grouped_sections(section_group)
55
+ grouped_sections.select{|k,v| k.to_i == section_group}.values.flatten.map do |section_name|
56
+ find_by_section(section_name)
57
+ end
58
+ end
59
+
60
+ def grouped_sections
61
+ @grouped_sections ||= section_names.group_by do |x|
62
+ x.split('.')[0]
63
+ end
64
+ end
65
+
66
+ def self.is_integer?(string)
67
+ /\A[-+]?[0-9]+\Z/ === string
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ <div class="col-md-2 navigation">
2
+ <%= yield(:styleguide_navigation) %>
3
+ </div>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Stylin</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+
7
+ <%= stylesheet_link_tag asset_path("stylin/application"), media: "all" %>
8
+ <%= javascript_include_tag asset_path("stylin/application") %>
9
+
10
+ <%= stylesheet_link_tag asset_path("application"), media: "all" %>
11
+
12
+ <%= csrf_meta_tags %>
13
+ </head>
14
+ <body>
15
+ <div class="header">
16
+ <h1><%= Styleguide %></h1>
17
+ </div>
18
+
19
+ <div class="container">
20
+ <div class="row">
21
+ <%= render partial: "layouts/stylin/navigation" %>
22
+ <%= yield %>
23
+ </div>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,31 @@
1
+ <div class="col-md-10">
2
+ <div class="styleguide-example">
3
+ <h3><%= section.section %> <em><%= section.filename %></em></h3>
4
+ <div class="styleguide-description">
5
+ <p><%= simple_format(section.description) %></p>
6
+ <% if section.modifiers.any? %>
7
+ <ul class="styleguide-modifier">
8
+ <% section.modifiers.each do |modifier| %>
9
+ <li><strong><%= modifier.name %></strong> - <%= modifier.description %></li>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
13
+ </div>
14
+ <div class="styleguide-element styleguide-modifier">
15
+ <span class="styleguide-modifier-name">No modifier</span>
16
+ <%= example_html(section) %>
17
+ </div>
18
+ <% section.modifiers.each do |modifier| %>
19
+ <div class="styleguide-element styleguide-modifier">
20
+ <span class="styleguide-modifier-name"><%= modifier.name %></span>
21
+ <%= example_html(section).gsub('$modifier_class', " #{modifier.class_name}").html_safe %>
22
+ </div>
23
+ <% end %>
24
+ <div class="styleguide-html">
25
+ <pre class="styleguide-code"><code>
26
+ <%= escaped_html(section) %>
27
+ </code></pre>
28
+ </div>
29
+
30
+ </div>
31
+ </div>
@@ -0,0 +1,5 @@
1
+ <%= styleguide_navigation %>
2
+
3
+ <div class="col-md-8">
4
+ Welcome to the styleguide.
5
+ </div>
@@ -0,0 +1,3 @@
1
+ <%= styleguide_navigation %>
2
+
3
+ <%= render partial: "section", locals: {section: @section} %>
@@ -0,0 +1,5 @@
1
+ Stylin::Engine.routes.draw do
2
+ resources :styleguides, only: [:index, :show]
3
+
4
+ root to: "styleguides#index"
5
+ end
@@ -0,0 +1,12 @@
1
+ module Stylin
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../../templates", __FILE__)
4
+
5
+ desc "Installs Stylin ready for use."
6
+ def install
7
+ copy_file "stylin.yml", "config/stylin.yml"
8
+ empty_directory "app/styleguides"
9
+ route "mount Stylin::Engine => '/styleguides' if Rails.env.development?"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Stylin
2
+ class ViewsGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../../templates", __FILE__)
4
+
5
+ desc "Installs Stylin views for customization."
6
+ def views
7
+ directory "views", "app/views"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ #see README at http:github.com/criticaljuncture/stylin for configuration details
2
+
3
+ #stylesheets_path: app/assets/stylesheets
4
+ #html_styleguides_path: app/styleguides
5
+ #section_groupings:
6
+ # 1: Generic Elements
7
+ # 2: Forms
@@ -0,0 +1,3 @@
1
+ <div class="col-md-4 navigation">
2
+ <%= yield(:styleguide_navigation) %>
3
+ </div>
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Stylin</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+
7
+ <%= stylesheet_link_tag "stylin/application", media: "all" %>
8
+ <%= javascript_include_tag "stylin/application" %>
9
+ <%= csrf_meta_tags %>
10
+ </head>
11
+ <body>
12
+ <div class="header">
13
+ <h1><%= Styleguide %></h1>
14
+ </div>
15
+
16
+ <div class="container">
17
+ <div class="row">
18
+ <%= render partial: "layouts/stylin/navigation" %>
19
+ <%= yield %>
20
+ </div>
21
+ </div>
22
+ </body>
23
+ </html>
@@ -0,0 +1,30 @@
1
+ <div class="col-md-8">
2
+ <div class="styleguide-example">
3
+ <h3><%= section.section %> <em><%= section.filename %></em></h3>
4
+ <div class="styleguide-description">
5
+ <p><%= section.description %></p>
6
+ <% if section.modifiers.any? %>
7
+ <ul class="styleguide-modifier">
8
+ <% section.modifiers.each do |modifier| %>
9
+ <li><strong><%= modifier.name %></strong> - <%= modifier.description %></li>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
13
+ </div>
14
+ <div class="styleguide-element">
15
+ <%= example_html(section) %>
16
+ </div>
17
+ <% section.modifiers.each do |modifier| %>
18
+ <div class="styleguide-element styleguide-modifier">
19
+ <span class="styleguide-modifier-name"><%= modifier.name %></span>
20
+ <%= example_html(section).sub('$modifier_class', " #{modifier.class_name}").html_safe %>
21
+ </div>
22
+ <% end %>
23
+ <div class="styleguide-html">
24
+ <pre class="styleguide-code"><code>
25
+ <%= escaped_html(section) %>
26
+ </code></pre>
27
+ </div>
28
+
29
+ </div>
30
+ </div>
@@ -0,0 +1,5 @@
1
+ <%= styleguide_navigation(styleguide.section_names) %>
2
+
3
+ <div class="col-md-8">
4
+ Welcome to the styleguide.
5
+ </div>
@@ -0,0 +1,3 @@
1
+ <%= styleguide_navigation %>
2
+
3
+ <%= render partial: "section", locals: {section: @section} %>
@@ -0,0 +1,8 @@
1
+ require 'jquery-rails'
2
+ require 'sass-rails'
3
+ require 'bootstrap-sass'
4
+ require 'kss'
5
+ require "stylin/engine"
6
+
7
+ module Stylin
8
+ end
@@ -0,0 +1,37 @@
1
+ module Stylin
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Stylin
4
+
5
+ initializer "my_engine.load_app_root" do |app|
6
+ config = {
7
+ stylesheets_path: File.join('app', 'assets', 'stylesheets'),
8
+ html_styleguides_path: File.join('app', 'styleguides'),
9
+ section_groupings: nil
10
+ }
11
+
12
+ if File.exists?( File.expand_path(File.join('config', 'stylin.yml'), app.root) )
13
+ user_config = HashWithIndifferentAccess.new(
14
+ YAML.load(
15
+ File.read( File.expand_path(File.join('config', 'stylin.yml'), app.root) )
16
+ )
17
+ ).symbolize_keys
18
+ else
19
+ user_config = {}
20
+ end
21
+
22
+ Stylin::APP_CONFIG = config.merge( user_config )
23
+
24
+ Stylin::APP_CONFIG[:stylesheets_path] = File.expand_path(APP_CONFIG[:stylesheets_path], app.root)
25
+ Stylin::APP_CONFIG[:html_styleguides_path] = File.expand_path(APP_CONFIG[:html_styleguides_path], app.root)
26
+ end
27
+
28
+ config.generators do |g|
29
+ g.test_framework :rspec, :fixture => false
30
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
31
+ g.assets false
32
+ g.helper false
33
+ end
34
+
35
+ config.autoload_paths << File.expand_path("../lib/tasks/stylin_tasks.rake", __FILE__)
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Stylin
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ namespace :stylin do
2
+ namespace :development do
3
+ desc "Copy templates from view directories into template directory"
4
+ task :copy_templates_for_generator do
5
+ view_path = File.expand_path("../../../app/views", __FILE__)
6
+ template_path = File.expand_path("../../generators/templates/views", __FILE__)
7
+
8
+ FileUtils.rm_r(template_path)
9
+ FileUtils.cp_r(view_path, template_path)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.