styleus 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/README.rdoc +5 -0
  2. data/app/assets/stylesheets/styleus.css +13 -2
  3. data/app/assets/stylesheets/styleus/core.css.scss +0 -0
  4. data/app/assets/stylesheets/styleus/default_dimensions.css.scss.erb +10 -0
  5. data/app/assets/stylesheets/styleus/themes/base.css.scss +11 -0
  6. data/app/assets/stylesheets/{coderay.css.scss → styleus/themes/base/coderay.css.scss} +5 -5
  7. data/app/assets/stylesheets/styleus/themes/base/components/_article.css.scss +56 -0
  8. data/app/assets/stylesheets/styleus/{components → themes/base/components}/_representation_helpers.css.scss +0 -0
  9. data/app/assets/stylesheets/styleus/themes/base/layout/main.css.scss +15 -0
  10. data/app/assets/stylesheets/styleus/themes/base/settings/_colors.css.scss +7 -0
  11. data/app/controllers/components_controller.rb +29 -0
  12. data/app/helpers/styleus_helper.rb +20 -14
  13. data/app/models/styleus/base.rb +36 -0
  14. data/app/models/styleus/component.rb +5 -0
  15. data/app/models/styleus/view_component.rb +24 -0
  16. data/app/views/layouts/_styleus.html.erb +8 -2
  17. data/app/views/layouts/_styleus_context.html.erb +1 -0
  18. data/config/initializers/01_styleus_config.rb +8 -0
  19. data/config/initializers/02_init_container_routes.rb +1 -0
  20. data/config/routes.rb +7 -0
  21. data/lib/styleus.rb +1 -0
  22. data/lib/styleus/engine.rb +17 -4
  23. data/lib/styleus/spacable.rb +14 -0
  24. data/lib/styleus/version.rb +1 -1
  25. metadata +18 -11
  26. data/app/assets/stylesheets/styleus/_defaults.css.scss +0 -6
  27. data/app/assets/stylesheets/styleus/components/_mq_presenter.css.scss +0 -49
  28. data/app/assets/stylesheets/styleus/main.css.scss +0 -8
  29. data/app/assets/stylesheets/styleus/settings/_colors.css.scss +0 -2
  30. data/app/models/base.rb +0 -31
  31. data/app/models/component.rb +0 -3
  32. data/app/models/component_list.rb +0 -15
data/README.rdoc CHANGED
@@ -10,4 +10,9 @@ of component lists with a simple anchor link menu.
10
10
  The representations are done via partials
11
11
  for each component with a _plain and a _sample file.
12
12
 
13
+ === Conventions
14
+ * classes used by styleus are prefixed with __styleus
15
+ * classes are used only for css styles in styleus context
16
+ * javascripts are applied via data-* attributes
17
+
13
18
  This project uses MIT-LICENSE.
@@ -1,4 +1,15 @@
1
1
  /*
2
- *= require coderay
3
- *= require styleus/main
2
+ * # Including styles responsible for a clean representation
3
+ * # of foreign app styles.
4
+ *= require styleus/core
5
+ *
6
+ * # Styleus code highlighting is based on coderay so we
7
+ * # include a basic coderay styling, adjusted for our
8
+ * # base style.
9
+ *= require styleus/themes/base/coderay
10
+ *
11
+ * # Requiring a basic theme for the styleus layout frame
12
+ * # TODO (fh): think about moving this "decision" to the app.
13
+ *= require styleus/default_dimensions
14
+ *= require styleus/themes/base
4
15
  */
File without changes
@@ -0,0 +1,10 @@
1
+ <% if Rails.configuration.styleus.use_default_dimensions %>
2
+ /* The maximum screen width should give all components
3
+ displayed in this guide enought space to unfold. */
4
+ $maximum_screen_width: <%= Rails.configuration.styleus.maximum_screen_size || 1680 %>px;
5
+
6
+ /* limiting the page width to a configurable maximum */
7
+ .__styleus_wrapper { width: 100%; }
8
+ <% end %>
9
+
10
+
@@ -0,0 +1,11 @@
1
+ @import url(http://fonts.googleapis.com/css?family=Oleo+Script:700);
2
+ @import url(http://fonts.googleapis.com/css?family=Didact+Gothic);
3
+
4
+ @import "compass";
5
+ @import "compass/reset";
6
+ @import "compass/css3";
7
+
8
+ @import 'base/settings/colors';
9
+ @import 'base/layout/main';
10
+
11
+ @import 'base/components/article';
@@ -1,8 +1,8 @@
1
1
  .CodeRay {
2
- background-color: #232323;
3
- border: 1px solid black;
2
+
3
+ background-color: #2B2B2B;
4
4
  font-family: 'Courier New', 'Terminal', monospace;
5
- color: #E6E0DB;
5
+ color: #fff;
6
6
  padding: 3px 5px;
7
7
  overflow: auto;
8
8
  font-size: 14px;
@@ -12,7 +12,7 @@
12
12
  padding: 0px;
13
13
  }
14
14
 
15
- .tag { color: #E7BE69; }
16
- .string { color: #A5C261; }
15
+ .tag, .attribute-name { color: #E8BF6A; }
16
+ .string, .content { color: #A5C261; }
17
17
  .comment { color: #BC9458; }
18
18
  }
@@ -0,0 +1,56 @@
1
+ @mixin component {
2
+ overflow: hidden;
3
+ position: relative;
4
+ top: 0; left: 0;
5
+ }
6
+
7
+ @mixin ambient-font {
8
+ font-family: 'Didact Gothic';
9
+ color: $soft-text;
10
+ }
11
+
12
+ @mixin ambient-headline {
13
+ @include ambient-font;
14
+ font-size: 1.2em;
15
+ font-weight: bold;
16
+ }
17
+
18
+ @mixin article-side-padding {
19
+ @include box-sizing(border-box);
20
+ padding-left: 1em;
21
+ padding-right: 1em;
22
+ }
23
+
24
+ .__sg_article {
25
+ @include border-radius(3px);
26
+ @include box-shadow(0 2px 3px 0 #cdcdcd);
27
+ @include component;
28
+ background: $content_background;
29
+ margin-bottom: 1em;
30
+ min-height: 3em;
31
+ padding-top: 1em;
32
+
33
+ > h3 {
34
+ @include ambient-headline;
35
+ @include article-side-padding;
36
+ margin-bottom: 0.5em;
37
+ text-align: right;
38
+ }
39
+
40
+ .__sg_component, .CodeRay, .__code_note {
41
+ @include article-side-padding;
42
+ }
43
+
44
+ .__code_note {
45
+ @include ambient-font;
46
+ text-align: right;
47
+ margin-top: 0.5em;
48
+ margin-bottom: 0.3em;
49
+ }
50
+
51
+ .CodeRay {
52
+ @include border-radius(0 0 3px 3px);
53
+ padding-top: 1em;
54
+ padding-bottom: 1em;
55
+ }
56
+ }
@@ -0,0 +1,15 @@
1
+ body { background: $main_background; }
2
+
3
+ .__styleus_wrapper {
4
+ @include box-sizing(border-box);
5
+ padding: 3em 1em 1em 4em;
6
+
7
+ header {
8
+ h1 {
9
+ font-size: 5em;
10
+ font-family: "Oleo Script";
11
+ margin-bottom: 0.2em;
12
+ color: #332717;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,7 @@
1
+ $main_background: #e8e6df;
2
+ $content_background: #fff;
3
+ $soft_content_background: #ece8d6;
4
+
5
+ // soft text is used for example in articles,
6
+ // to provide an ambient headline.
7
+ $soft_text: #999388;
@@ -0,0 +1,29 @@
1
+ class ComponentsController < ApplicationController
2
+ layout 'components'
3
+
4
+ def index
5
+ render_for_components
6
+ end
7
+
8
+ def show
9
+ render_for_components
10
+ end
11
+
12
+ private
13
+
14
+ def render_for_components
15
+ if components?
16
+ render "components/#{components}/#{params[:action]}"
17
+ else
18
+ render
19
+ end
20
+ end
21
+
22
+ def components
23
+ params[:components]
24
+ end
25
+
26
+ def components?
27
+ !!params[:components]
28
+ end
29
+ end
@@ -1,17 +1,16 @@
1
1
  module StyleusHelper
2
2
  def styleus(comp_list = [])
3
- component_list = ComponentList.from_hashes(comp_list)
3
+ @components = Styleus::ViewComponent.from_hashes(comp_list)
4
4
 
5
- component_listing = component_list.components.map do |component|
5
+ @component_list = @components.map do |component|
6
6
  wrap_component component
7
7
  end
8
8
 
9
- component_menu(component_list).concat(component_listing.join.html_safe)
9
+ component_menu.concat(_joined_component_list)
10
10
  end
11
11
 
12
+
12
13
  def wrap_component(component)
13
- # add component to linked list menu
14
- #menu.push({ id: component.id, headline: component.headline }) if menu
15
14
  _styleus_article_wrap(headline: component.headline, anchor_id: component.id) do
16
15
  styleus_partials(component.partial_path)
17
16
  end
@@ -23,24 +22,23 @@ module StyleusHelper
23
22
  end
24
23
 
25
24
  plain_template = _coderay_highlight_wrap("#{partial_path}.html.erb") do
26
- render partial: "#{partial_path}_plain"
25
+ render partial: "#{partial_path}"
27
26
  end
28
27
 
29
28
  sample_template.concat(plain_template)
30
29
  end
31
30
 
32
- def component_menu(component_list)
31
+ def component_menu
32
+ return if @components.empty?
33
33
  content_tag 'nav' do
34
34
  content_tag 'ul' do
35
- content_tag_for(:li, component_list.components) do |component|
35
+ content_tag_for(:li, @components) do |component|
36
36
  link_to component.headline, anchor: component.id
37
37
  end
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
-
43
-
44
42
  def _styleus_article_wrap(options = { }, &block)
45
43
  captured_block = capture(&block)
46
44
 
@@ -55,18 +53,26 @@ module StyleusHelper
55
53
 
56
54
  def _styleus_representation_wrap(options = { }, &block)
57
55
  captured_block = capture(&block)
58
- classes = '__sg_component'.concat(" #{options[:class].to_s}")
56
+
57
+ classes = '__sg_component'.concat(" #{options[:class].to_s}")
59
58
  content_tag('section', class: classes) do
60
- captured_block.to_s.html_safe
59
+ render layout: 'layouts/styleus_context' do
60
+ captured_block.to_s.html_safe
61
+ end
61
62
  end
62
63
  end
63
64
 
64
65
  def _coderay_highlight_wrap(note = nil, &block)
65
- captured_block = capture(&block)
66
- code_block = CodeRay.scan(captured_block.to_s, :html)
66
+ captured_block = capture(&block)
67
+ code_block = CodeRay.scan(captured_block.to_s, :html)
68
+
67
69
  note_tag = note ? content_tag('p', note, class: '__code_note') : ''
68
70
 
69
71
  highlighted_code = "#{note_tag}#{code_block.div(:css => :class)}"
70
72
  highlighted_code.html_safe
71
73
  end
74
+
75
+ def _joined_component_list
76
+ @component_list.join.html_safe
77
+ end
72
78
  end
@@ -0,0 +1,36 @@
1
+ module Styleus
2
+ # Provides a basic model, with attribute and
3
+ # naming capabilities.
4
+ # TODO: replace with ActiveModel::Model or something like that
5
+ class Base
6
+ extend ActiveModel::Naming
7
+ include ActiveModel::AttributeMethods
8
+ include ActiveModel::Serialization
9
+
10
+ def initialize(attributes)
11
+ @attributes = attributes
12
+ end
13
+
14
+ def id
15
+ nil
16
+ end
17
+
18
+ # as implemented as in ActiveRecord
19
+ def to_key
20
+ key = self.id
21
+ [key] if key
22
+ end
23
+
24
+ private
25
+
26
+ def attribute(attr)
27
+ @attributes[attr.to_sym]
28
+ end
29
+
30
+ class << self
31
+ def with_attributes(*attribute_names)
32
+ define_attribute_methods attribute_names.map(&:to_s)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Styleus
2
+ class Component
3
+ include Styleus::Spacable
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ module Styleus
2
+ class ViewComponent < Styleus::Base
3
+ with_attributes :headline, :partial_path
4
+
5
+ # id is used as anchor id in the anchor menu,
6
+ # so it has to be a uid.
7
+ # TODO: make sure the uid-ness :)
8
+ def id
9
+ headline.underscore
10
+ end
11
+
12
+ class << self
13
+ def components
14
+ @components ||= []
15
+ end
16
+
17
+ def from_hashes(hashes)
18
+ components.clear
19
+ hashes.each { |comp_hash| components << new(comp_hash) }
20
+ components
21
+ end
22
+ end
23
+ end
24
+ end
@@ -7,8 +7,14 @@
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
10
- <div class="__sg_wrapper">
10
+ <!-- class __styleus is the styleus context class,
11
+ providing a minimal css setting. -->
12
+ <section class="__styleus_wrapper">
13
+ <header>
14
+ <h1>Component Guide</h1>
15
+ </header>
16
+
11
17
  <%= yield :components %>
12
- </div>
18
+ </section>
13
19
  </body>
14
20
  </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,8 @@
1
+ Rails.application.config.before_configuration do |app|
2
+ # initialize styleus configuration
3
+ app.config.styleus = Styleus::Engine::Configuration.new unless app.config.respond_to? :styleus
4
+
5
+ # some defaults
6
+ app.config.styleus.maximum_screen_size = 1680
7
+ app.config.styleus.use_default_dimensions = true
8
+ end
@@ -0,0 +1 @@
1
+ Styleus::COMPONENT_SPACES = Styleus::Component.spaces || []
data/config/routes.rb CHANGED
@@ -1,2 +1,9 @@
1
1
  Rails.application.routes.draw do
2
+ resources :components, only: [:index] do
3
+ collection do
4
+ Styleus::COMPONENT_SPACES.each do |c|
5
+ resources c, only: [:index, :show], controller: :components, components: c.to_s
6
+ end
7
+ end
8
+ end
2
9
  end
data/lib/styleus.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "styleus/engine"
2
+ require "styleus/spacable"
2
3
 
3
4
  module Styleus
4
5
  end
@@ -1,9 +1,22 @@
1
+ require 'ostruct'
2
+
1
3
  module Styleus
2
4
  class Engine < ::Rails::Engine
3
- initializer 'styleus.assets.precompile' do |app|
4
- # All assets required by templates provided by this engine
5
- # must be added here for precompilation.
6
- app.config.assets.precompile += ['styleus.css', 'coderay.css']
5
+ initializer 'config.assets.precompile' do |app|
6
+ # # All assets required by templates provided by this engine
7
+ # # must be added here for precompilation.
8
+ app.config.assets.precompile += ['styleus.css']
9
+ end
10
+
11
+
12
+ class Configuration < OpenStruct
13
+ def to_s
14
+ instance_variable_get(:@table).to_s
15
+ end
16
+
17
+ def inspect
18
+ to_s
19
+ end
7
20
  end
8
21
  end
9
22
  end
@@ -0,0 +1,14 @@
1
+ module Styleus
2
+ module Spacable
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def spaces(*collection)
7
+ @spaces ||= []
8
+ return @spaces if collection.empty?
9
+ @spaces.concat(collection).uniq! if collection.respond_to? :to_ary
10
+ @spaces
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Styleus
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: styleus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-20 00:00:00.000000000 Z
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -67,21 +67,28 @@ executables: []
67
67
  extensions: []
68
68
  extra_rdoc_files: []
69
69
  files:
70
- - app/assets/stylesheets/coderay.css.scss
71
- - app/assets/stylesheets/styleus/_defaults.css.scss
72
- - app/assets/stylesheets/styleus/components/_mq_presenter.css.scss
73
- - app/assets/stylesheets/styleus/components/_representation_helpers.css.scss
74
- - app/assets/stylesheets/styleus/main.css.scss
75
- - app/assets/stylesheets/styleus/settings/_colors.css.scss
70
+ - app/assets/stylesheets/styleus/core.css.scss
71
+ - app/assets/stylesheets/styleus/default_dimensions.css.scss.erb
72
+ - app/assets/stylesheets/styleus/themes/base/coderay.css.scss
73
+ - app/assets/stylesheets/styleus/themes/base/components/_article.css.scss
74
+ - app/assets/stylesheets/styleus/themes/base/components/_representation_helpers.css.scss
75
+ - app/assets/stylesheets/styleus/themes/base/layout/main.css.scss
76
+ - app/assets/stylesheets/styleus/themes/base/settings/_colors.css.scss
77
+ - app/assets/stylesheets/styleus/themes/base.css.scss
76
78
  - app/assets/stylesheets/styleus.css
79
+ - app/controllers/components_controller.rb
77
80
  - app/helpers/styleus_helper.rb
78
- - app/models/base.rb
79
- - app/models/component.rb
80
- - app/models/component_list.rb
81
+ - app/models/styleus/base.rb
82
+ - app/models/styleus/component.rb
83
+ - app/models/styleus/view_component.rb
81
84
  - app/views/layouts/_styleus.html.erb
85
+ - app/views/layouts/_styleus_context.html.erb
82
86
  - app/views/styleus/_screen_size_viewer.html.erb
87
+ - config/initializers/01_styleus_config.rb
88
+ - config/initializers/02_init_container_routes.rb
83
89
  - config/routes.rb
84
90
  - lib/styleus/engine.rb
91
+ - lib/styleus/spacable.rb
85
92
  - lib/styleus/version.rb
86
93
  - lib/styleus.rb
87
94
  - MIT-LICENSE
@@ -1,6 +0,0 @@
1
- $styleguide_width: 1800px;
2
-
3
- .__sg_wrapper {
4
- padding: 0 2em;
5
- width: $styleguide_width;
6
- }
@@ -1,49 +0,0 @@
1
- $spacing_width: 3px;
2
-
3
- $first_col_width: 1024px;
4
- $second_col_width: 1480px - $first_col_width - $spacing_width;
5
- $third_col_width: $styleguide_width - $second_col_width - $first_col_width - 2*$spacing_width;
6
-
7
- @mixin __mq_font_styles {
8
- text-align: center;
9
- font-size: 0.8em;
10
- font-weight: bold;
11
- color: #333;
12
- padding-top: 0.2em;
13
- }
14
-
15
- @mixin __mq_step_markers {
16
- border: 3px solid red;
17
- border-bottom: none;
18
- margin-left: $spacing_width;
19
-
20
- &:first-child { margin-left: 0; }
21
-
22
- // < 1024px
23
- &.one { width: $first_col_width; border-color: #a1ff2c; }
24
- //1025px <> 1480px
25
- &.two { width: $second_col_width; border-color: #50c7ff; }
26
- // > 1480px
27
- &.three { width: $third_col_width; border-color: #e43b37; }
28
- }
29
-
30
- .__mq_presenter {
31
- height: 5em;
32
-
33
- .__mq_screen_size_list {
34
- height: 3em;
35
- padding: 1em 0;
36
- overflow: hidden;
37
- position: fixed;
38
- background: #fff;
39
- border-bottom: 1px solid #ccc;
40
- width: $styleguide_width;
41
- }
42
-
43
- .__mq_step {
44
- @include box-sizing(border-box);
45
- float: left;
46
- @include __mq_font_styles;
47
- @include __mq_step_markers;
48
- }
49
- }
@@ -1,8 +0,0 @@
1
- @import "compass";
2
- @import "compass/css3";
3
-
4
-
5
- @import './settings/colors';
6
- @import './defaults';
7
- @import './components/representation_helpers';
8
- @import './components/mq_presenter';
@@ -1,2 +0,0 @@
1
- $soft_highlight: #cdcdcd;
2
- $strong_highlight: #adadad;
data/app/models/base.rb DELETED
@@ -1,31 +0,0 @@
1
- class Base
2
- extend ActiveModel::Naming
3
- include ActiveModel::AttributeMethods
4
- include ActiveModel::Serialization
5
-
6
- def initialize(attributes)
7
- @attributes = attributes
8
- end
9
-
10
- def id
11
- @id ||= rand(99999999)
12
- end
13
-
14
- # as implemented as in ActiveRecord
15
- def to_key
16
- key = self.id
17
- [key] if key
18
- end
19
-
20
- private
21
-
22
- def attribute(attr)
23
- @attributes[attr.to_sym]
24
- end
25
-
26
- class << self
27
- def with_attributes(*attribute_names)
28
- define_attribute_methods attribute_names.map(&:to_s)
29
- end
30
- end
31
- end
@@ -1,3 +0,0 @@
1
- class Component < Base
2
- with_attributes :headline, :partial_path
3
- end
@@ -1,15 +0,0 @@
1
- class ComponentList
2
-
3
- def components
4
- @components ||= []
5
- end
6
-
7
- class << self
8
- def from_hashes(hashes)
9
- @component_list = ComponentList.new
10
- hashes.each { |comp_hash| @component_list.components << Component.new(comp_hash)}
11
- @component_list
12
- end
13
- end
14
-
15
- end