guidelines 0.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,5 @@
1
+ *_local
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1,12 @@
1
+ rvm use --create --install ruby-1.8.7@styleguides
2
+
3
+ if [[ -s "./styleguides.gems" ]]; then
4
+ if ! rvm gemset import styleguides.gems ; then
5
+ echo "ERROR: Unable to bootstrap the gems" >&2
6
+ fi
7
+ fi
8
+
9
+ # Bundle is available, non-custom config.
10
+ if command -v bundle >/dev/null && ! grep -q BUNDLE_FROZEN .bundle/config 2>/dev/null ; then
11
+ bundle install
12
+ fi
data/.wiprc ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bash
2
+
3
+ [[ -s ".wiprc_fn" ]] && source ".wiprc_fn"
4
+ [[ -s ".wiprc_local" ]] && source ".wiprc_local"
5
+
6
+ mode="$1"
7
+
8
+ fn_check=`type -t $mode`
9
+ if [ "function" == "$fn_check" ] ; then
10
+ eval $mode
11
+ else
12
+ echo "default mode"
13
+ fi
data/.wiprc_fn ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # project bootstrap steps go here
4
+ # bootstrap() {
5
+ # }
6
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guidelines.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ guidelines
2
+ ==============================================================================
3
+
4
+ more to come, but it's basically (for now) a Rails engine for providing your
5
+ application with style guide(line)s against which to build your views.
6
+
7
+ ...in which "view" is defined as:
8
+
9
+ * Rails templates
10
+ * Rails view-related controller logic (e.g., rendering html or json)
11
+ * DOM produced
12
+ * CSS presentation
13
+ * JS behavior
14
+ * Images/fonts/etc.
15
+
16
+
17
+ Requirements
18
+ ------------------------------------------------------------------------------
19
+
20
+ * Rails
21
+ * nokogiri
22
+ * The ability to consider a "view" as incorporating all of the components
23
+ in the definition above and a desire to apply the same degree of
24
+ convention and attention-to-detail to views as to models/controllers/etc.
25
+
26
+
27
+ Installation
28
+ ------------------------------------------------------------------------------
29
+
30
+ gem install guidelines
31
+
32
+
33
+ Usage
34
+ ------------------------------------------------------------------------------
35
+
36
+ Add examples to `app/views/guidelines`, in which nested folders are fine.
37
+
38
+ e.g.,
39
+
40
+ # app/views/guidelines/users/show.html.erb
41
+ <%= guideline_for('users#show') do |guideline| %>
42
+ <%= guideline.example do |example| -%>
43
+ <style type="text/css" media="screen">
44
+ /*
45
+ apply page-/example-specific styles here. should be few, as we're
46
+ really testing that things look good based on our app-wide styles.
47
+ */
48
+
49
+ <%= example.selector %> > h1 {
50
+ font-weight : bold;
51
+ }
52
+ </style>
53
+
54
+ <article class="user" id="user_1">
55
+ <h1>user one</h1>
56
+ </article>
57
+ <%- end -%>
58
+ <%- end -%>
59
+
60
+
61
+ TODO
62
+ ------------------------------------------------------------------------------
63
+
64
+ plenty
65
+
66
+
67
+ Contributors
68
+ ------------------------------------------------------------------------------
69
+
70
+ * Corey Innis <http://github.com/coreyti>
71
+ Author
72
+
73
+ Acknowledgments
74
+ ------------------------------------------------------------------------------
75
+
76
+ * The IfWeRanTheWorld team <http://ifwerantheworld.com/>
77
+ for inspiring an exploration into better integration of design and
78
+ development processes (which this project aims to address... over time).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,25 @@
1
+ class GuidelinesController < ApplicationController
2
+ caches_page :index, :show
3
+
4
+ def index
5
+ render(:index, :locals => { :list => list })
6
+ end
7
+
8
+ def show
9
+ render(item)
10
+ end
11
+
12
+ private
13
+
14
+ def basepath
15
+ @basepath ||= Rails.root.join('app', 'views', 'guidelines')
16
+ end
17
+
18
+ def item
19
+ @item ||= "guidelines/#{params[:id].to_s.downcase}"
20
+ end
21
+
22
+ def list
23
+ @list ||= Dir.glob(File.join(basepath, "**", "*.html.*")).map { |fullpath| fullpath.sub(/#{basepath}\//, '').sub(/\.html.+$/, '') }
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ module GuidelinesHelper
2
+ def guideline_for(name, *args, &proc)
3
+ raise ArgumentError, "Missing block" unless block_given?
4
+
5
+ # options = args.extract_options!
6
+ raw(GuidelinesHelper::Builder.new(name, self, proc).to_s)
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ module GuidelinesHelper
2
+ class Builder
3
+ attr_reader :name, :template, :examples
4
+
5
+ def initialize(name, template, proc)
6
+ @name, @template, @proc = name, template, proc
7
+ @examples = []
8
+
9
+ proc.call(self)
10
+ end
11
+
12
+ def to_s
13
+ @examples.join("\n")
14
+ end
15
+
16
+ def example(&block)
17
+ @examples << decorate(template.capture(GuidelinesHelper::Example.new(example_id), &block)) ; nil
18
+ end
19
+
20
+ private
21
+
22
+ def decorate(html)
23
+ fragment = Nokogiri::HTML::DocumentFragment.parse(html)
24
+ fragment.css('*').each do |node|
25
+ node.set_attribute('data-guideline-example', example_id)
26
+ end
27
+
28
+ fragment.to_html
29
+ end
30
+
31
+ def example_id
32
+ (@examples.length + 1).to_s
33
+ end
34
+
35
+ def safe_name
36
+ name.gsub(/[#\/]/, '_')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ module GuidelinesHelper
2
+ class Example
3
+ attr_reader :example_id
4
+
5
+ def initialize(example_id)
6
+ @example_id = example_id
7
+ end
8
+
9
+ def selector
10
+ "[data-guideline-example='#{example_id}']"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ <h1><%= t('.heading') %></h1>
2
+
3
+ <ul>
4
+ <%- list.each do |item| -%>
5
+ <li><%= link_to(item, guideline_path(item)) %></li>
6
+ <%- end -%>
7
+ </ul>
@@ -0,0 +1,4 @@
1
+ en:
2
+ guidelines:
3
+ index:
4
+ heading: 'Guidelines'
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ constraints(:id => /(\w|[\/_-])+/) do
3
+ resources :guidelines, :only => [:index, :show]
4
+ end
5
+ end
data/guidelines.gems ADDED
@@ -0,0 +1,2 @@
1
+ bundler -v 1.0.10
2
+ wip -v 0.2.0
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guidelines/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guidelines"
7
+ s.version = Guidelines::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Corey Innis"]
10
+ s.email = ["corey@coolerator.net"]
11
+ s.homepage = ""
12
+ s.summary = %q{Adds guidelines to a Rails application.}
13
+ s.description = %q{To use guidelines in your application, simply add views in app/views/guidelines (nested paths are allowed).}
14
+
15
+ s.rubyforge_project = "guidelines"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
data/lib/guidelines.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'nokogiri'
2
+ require 'guidelines/rails'
3
+
4
+ module Guidelines
5
+
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ require 'guidelines/rails/engine'
2
+
3
+ module Guidelines
4
+ module Rails
5
+
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Guidelines
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Guidelines
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guidelines
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Corey Innis
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-06 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: To use guidelines in your application, simply add views in app/views/guidelines (nested paths are allowed).
23
+ email:
24
+ - corey@coolerator.net
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - .rvmrc
34
+ - .wiprc
35
+ - .wiprc_fn
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - app/controllers/guidelines_controller.rb
40
+ - app/helpers/guidelines_helper.rb
41
+ - app/helpers/guidelines_helper/builder.rb
42
+ - app/helpers/guidelines_helper/example.rb
43
+ - app/views/guidelines/index.html.erb
44
+ - config/locales/en.yml
45
+ - config/routes.rb
46
+ - guidelines.gems
47
+ - guidelines.gemspec
48
+ - lib/guidelines.rb
49
+ - lib/guidelines/rails.rb
50
+ - lib/guidelines/rails/engine.rb
51
+ - lib/guidelines/version.rb
52
+ has_rdoc: true
53
+ homepage: ""
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: guidelines
82
+ rubygems_version: 1.6.1
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Adds guidelines to a Rails application.
86
+ test_files: []
87
+