effective_style_guide 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +366 -0
  4. data/Rakefile +20 -0
  5. data/app/controllers/effective/style_guide_controller.rb +19 -0
  6. data/app/models/effective/access_denied.rb +17 -0
  7. data/app/models/effective/datatables/style_guide.rb +44 -0
  8. data/app/models/effective/style_guide.rb +28 -0
  9. data/app/views/effective/style_guide/_alerts.html.haml +14 -0
  10. data/app/views/effective/style_guide/_breadcrumbs.html.haml +12 -0
  11. data/app/views/effective/style_guide/_buttons.html.haml +52 -0
  12. data/app/views/effective/style_guide/_effective_datatable.html.haml +5 -0
  13. data/app/views/effective/style_guide/_form_horizontal.html.haml +38 -0
  14. data/app/views/effective/style_guide/_form_inline.html.haml +16 -0
  15. data/app/views/effective/style_guide/_form_vertical.html.haml +36 -0
  16. data/app/views/effective/style_guide/_jumbotron.html.haml +5 -0
  17. data/app/views/effective/style_guide/_labels.html.haml +37 -0
  18. data/app/views/effective/style_guide/_list_groups.html.haml +23 -0
  19. data/app/views/effective/style_guide/_modals.html.haml +69 -0
  20. data/app/views/effective/style_guide/_navs.html.haml +33 -0
  21. data/app/views/effective/style_guide/_pagination.html.haml +38 -0
  22. data/app/views/effective/style_guide/_panels.html.haml +36 -0
  23. data/app/views/effective/style_guide/_progress_bars.html.haml +30 -0
  24. data/app/views/effective/style_guide/_tables.html.haml +15 -0
  25. data/app/views/effective/style_guide/_thumbnails.html.haml +17 -0
  26. data/app/views/effective/style_guide/_typography.html.haml +20 -0
  27. data/app/views/effective/style_guide/_wells.html.haml +3 -0
  28. data/app/views/effective/style_guide/show.html.haml +88 -0
  29. data/config/routes.rb +11 -0
  30. data/lib/effective_style_guide/engine.rb +11 -0
  31. data/lib/effective_style_guide/version.rb +3 -0
  32. data/lib/effective_style_guide.rb +20 -0
  33. data/lib/generators/effective_style_guide/install_generator.rb +16 -0
  34. data/lib/generators/templates/README +1 -0
  35. data/lib/generators/templates/effective_style_guide.rb +26 -0
  36. metadata +136 -0
@@ -0,0 +1,36 @@
1
+ = simple_form_for Effective::StyleGuide.new(), :url => '/' do |f|
2
+ = f.input :title, :hint => 'please enter a title (this is a standard text field)'
3
+ = f.input :email, :hint => 'please enter an email address (this is an email field)'
4
+ = f.input :password, :hint => 'please enter a password (this is a password field)'
5
+ - if defined?(EffectiveOrders)
6
+ = f.input :price, :as => :price, :hint => 'please enter a price (this is a price field from EffectiveOrders)'
7
+ = f.input :number, :hint => 'please enter a number (this is a number field)'
8
+ = f.input :range, :as => :range, :hint => 'please enter a number range (this is a range field)'
9
+ = f.input :category, :as => :select, :collection => 10.times.map { |x| "Category #{x}"}, :hint => 'please select a category (this is a select field)'
10
+ = f.input :drink, :as => :check_boxes, :wrapper => :vertical_inline_radio_and_checkboxes, :collection => ['Water', 'Tea', 'Coffee', 'Soda'], :hint => 'please select one or more drinks (this is a check_boxes :wrapper => :vertical_inline_radio_and_checkboxes field)'
11
+ = f.input :food, :as => :radio_buttons, :wrapper => :vertical_inline_radio_and_checkboxes, :collection => ['Pasta', 'Rice', 'Potato', 'Couscous'], :hint => 'please select one food (this is a radio_buttons :wrapper => :vertical_inline_radio_and_checkboxes field)'
12
+ = f.input :content, :hint => 'please enter a whole bunch of content (this is a textarea)'
13
+ = f.input :archived, :hint => 'please select true or false (this is a boolean field)'
14
+ = f.input :drink, :as => :check_boxes, :collection => ['Water', 'Tea', 'Coffee', 'Soda'], :hint => 'please select one or more drinks (this is a check_boxes field)'
15
+ = f.input :food, :as => :radio_buttons, :collection => ['Pasta', 'Rice', 'Potato', 'Couscous'], :hint => 'please select one food (this is a radio_buttons field)'
16
+ = f.button :submit
17
+
18
+ %hr
19
+ .inline-example Form Vertical Invalid State
20
+
21
+ = simple_form_for Effective::StyleGuide.new().tap { |s| s.valid? }, :url => '/' do |f|
22
+ = f.input :title, :hint => 'please enter a title (this is a standard text field)'
23
+ = f.input :email, :hint => 'please enter an email address (this is an email field)'
24
+ = f.input :password, :hint => 'please enter a password (this is a password field)'
25
+ - if defined?(EffectiveOrders)
26
+ = f.input :price, :as => :price, :hint => 'please enter a price (this is a price field from EffectiveOrders)'
27
+ = f.input :number, :hint => 'please enter a number (this is a number field)'
28
+ = f.input :range, :as => :range, :hint => 'please enter a number range (this is a range field)'
29
+ = f.input :category, :as => :select, :collection => 10.times.map { |x| "Category #{x}"}, :hint => 'please select a category (this is a select field)'
30
+ = f.input :drink, :as => :check_boxes, :wrapper => :vertical_inline_radio_and_checkboxes, :collection => ['Water', 'Tea', 'Coffee', 'Soda'], :hint => 'please select one or more drinks (this is a check_boxes :wrapper => :vertical_inline_radio_and_checkboxes field)'
31
+ = f.input :food, :as => :radio_buttons, :wrapper => :vertical_inline_radio_and_checkboxes, :collection => ['Pasta', 'Rice', 'Potato', 'Couscous'], :hint => 'please select one food (this is a radio_buttons :wrapper => :vertical_inline_radio_and_checkboxes field)'
32
+ = f.input :content, :hint => 'please enter a whole bunch of content (this is a textarea)'
33
+ = f.input :archived, :hint => 'please select true or false (this is a boolean field)'
34
+ = f.input :drink, :as => :check_boxes, :collection => ['Water', 'Tea', 'Coffee', 'Soda'], :hint => 'please select one or more drinks (this is a check_boxes field)'
35
+ = f.input :food, :as => :radio_buttons, :collection => ['Pasta', 'Rice', 'Potato', 'Couscous'], :hint => 'please select one food (this is a radio_buttons field)'
36
+ = f.button :submit
@@ -0,0 +1,5 @@
1
+ .jumbotron
2
+ %h1 Hello, world!
3
+ %p= Faker::Lorem.paragraph(3)
4
+ %p
5
+ %a.btn.btn-primary.btn-lg Learn More
@@ -0,0 +1,37 @@
1
+ - variations = ['Default', 'Primary', 'Success', 'Info', 'Warning', 'Danger']
2
+
3
+ %h1
4
+ Example heading
5
+ %span.label.label-default New
6
+
7
+ %h2
8
+ Example heading
9
+ %span.label.label-default New
10
+
11
+ %h3
12
+ Example heading
13
+ %span.label.label-default New
14
+
15
+ %h4
16
+ Example heading
17
+ %span.label.label-default New
18
+
19
+ %h5
20
+ Example heading
21
+ %span.label.label-default New
22
+
23
+ %h6
24
+ Example heading
25
+ %span.label.label-default New
26
+
27
+ %br
28
+
29
+ - variations.each do |variation|
30
+ %span.label{:class => "label-#{variation.downcase}"}= variation
31
+
32
+ %br
33
+ %br
34
+
35
+ %a{:href => '#'}
36
+ Inbox
37
+ %span.badge 42
@@ -0,0 +1,23 @@
1
+ %ul.list-group
2
+ - 4.times do
3
+ %li.list-group-item= Faker::Lorem.sentence(1)
4
+
5
+ %ul.list-group
6
+ - 4.times do
7
+ %li.list-group-item
8
+ %span.badge= [*1..20].sample
9
+ = Faker::Lorem.sentence(1)
10
+
11
+ %ul.list-group
12
+ - 4.times do |x|
13
+ %a.list-group-item{:href => '#', :class => ('active' if x == 0)}= Faker::Lorem.sentence(1)
14
+
15
+ %ul.list-group
16
+ - 4.times do |x|
17
+ %a.list-group-item{:href => '#', :class => ('disabled' if x == 0)}= Faker::Lorem.sentence(1)
18
+
19
+ .list-group
20
+ - 4.times do |x|
21
+ %a.list-group-item{:href => '#', :class => ('active' if x == 1)}
22
+ %h4.list-group-item-heading= Faker::Lorem.sentence(1)
23
+ %p.list-group-item-text= Faker::Lorem.sentence(3)
@@ -0,0 +1,69 @@
1
+ %button.btn.btn-primary{'data-toggle' => 'modal', 'data-target' => '#modalStandard'} Open Standard Modal
2
+
3
+ #modalStandard.modal.fade{:tabindex => -1, :role => 'dialog', 'aria-hidden' => true, 'arai-labelledby' => 'modalStandardLabel'}
4
+ .modal-dialog
5
+ .modal-content
6
+ .modal-header
7
+ %button.close{'data-dismiss' => 'modal'}
8
+ %span{'aria-hidden' => true} ×
9
+ %span.sr-only Close
10
+ %h4.modal-title{:id => 'modalStandardLabel'} Standard Modal Title
11
+ .modal-body
12
+ %h4 Text in a modal
13
+ %p= Faker::Lorem.paragraph(3)
14
+ %br
15
+
16
+ %h4 Tooltips in a standard modal
17
+ %p
18
+ This is a
19
+ %a{:href => '#', 'data-toggle' => 'tooltip', 'title' => 'This is a tooltip'} Link with Tooltip
20
+ %br
21
+
22
+ %h4 Overflowing text to show scroll behaviour
23
+ - 15.times do
24
+ %p= Faker::Lorem.paragraph(3)
25
+ %br
26
+
27
+ .modal-footer
28
+ %button.btn.btn-primary{:type => 'button'} Save Changes
29
+ %button.btn.btn-default{'data-dismiss' => 'modal'} Close
30
+
31
+
32
+ %button.btn.btn-primary{'data-toggle' => 'modal', 'data-target' => '#modalLarge'} Open Large Modal
33
+
34
+ #modalLarge.modal.fade{:tabindex => -1, :role => 'dialog', 'aria-hidden' => true, 'arai-labelledby' => 'modalLargeLabel'}
35
+ .modal-dialog.modal-lg
36
+ .modal-content
37
+ .modal-header
38
+ %button.close{'data-dismiss' => 'modal'}
39
+ %span{'aria-hidden' => true} ×
40
+ %span.sr-only Close
41
+ %h4.modal-title{:id => 'modalLargeLabel'} Large Modal Title
42
+ .modal-body
43
+ %h4 Text in a large modal
44
+ %p= Faker::Lorem.paragraph(3)
45
+ %br
46
+
47
+ .modal-footer
48
+ %button.btn.btn-primary{:type => 'button'} Save Changes
49
+ %button.btn.btn-default{'data-dismiss' => 'modal'} Close
50
+
51
+ %button.btn.btn-primary{'data-toggle' => 'modal', 'data-target' => '#modalSmall'} Open Small Modal
52
+
53
+ #modalSmall.modal.fade{:tabindex => -1, :role => 'dialog', 'aria-hidden' => true, 'arai-labelledby' => 'modalSmallLabel'}
54
+ .modal-dialog.modal-sm
55
+ .modal-content
56
+ .modal-header
57
+ %button.close{'data-dismiss' => 'modal'}
58
+ %span{'aria-hidden' => true} ×
59
+ %span.sr-only Close
60
+ %h4.modal-title{:id => 'modalSmallLabel'} Small Modal Title
61
+ .modal-body
62
+ %h4 Text in a small modal
63
+ %p= Faker::Lorem.paragraph(3)
64
+ %br
65
+
66
+ .modal-footer
67
+ %button.btn.btn-primary{:type => 'button'} Save Changes
68
+ %button.btn.btn-default{'data-dismiss' => 'modal'} Close
69
+
@@ -0,0 +1,33 @@
1
+ %p
2
+ %ul.nav.nav-tabs
3
+ %li.active= link_to 'First Item', '#'
4
+ %li= link_to 'Second Item', '#'
5
+ %li= link_to 'Third Item', '#'
6
+ %li.dropdown
7
+ %a.dropdown-toggle{'data-toggle' => 'dropdown', :href => '#'}
8
+ Dropdown
9
+ %span.caret
10
+ %ul.dropdown-menu{:role => 'menu'}
11
+ %li= link_to 'First', '#'
12
+ %li= link_to 'Second', '#'
13
+ %li= link_to 'Third', '#'
14
+ %li.divider
15
+ %li= link_to 'Separated', '#'
16
+
17
+ %br
18
+
19
+ %p
20
+ %ul.nav.nav-pills
21
+ %li= link_to 'First Item', '#'
22
+ %li= link_to 'Second Item', '#'
23
+ %li.active= link_to 'Third Item', '#'
24
+ %li.dropdown
25
+ %a.dropdown-toggle{'data-toggle' => 'dropdown', :href => '#'}
26
+ Dropdown
27
+ %span.caret
28
+ %ul.dropdown-menu{:role => 'menu'}
29
+ %li= link_to 'First', '#'
30
+ %li= link_to 'Second', '#'
31
+ %li= link_to 'Third', '#'
32
+ %li.divider
33
+ %li= link_to 'Separated', '#'
@@ -0,0 +1,38 @@
1
+ %ul.pagination
2
+ %li.disabled
3
+ %a{:href => '#'} «
4
+ - 1.upto(10).each do |x|
5
+ %li{:class => ('active' if x == 1)}
6
+ %a{:href => '#'}= x
7
+ %li
8
+ %a{:href => '#'} »
9
+
10
+ %ul.pagination.pagination-lg
11
+ %li
12
+ %a{:href => '#'} «
13
+ - 1.upto(10).each do |x|
14
+ %li
15
+ %a{:href => '#'}= x
16
+ %li
17
+ %a{:href => '#'} »
18
+
19
+ %ul.pagination.pagination-sm
20
+ %li
21
+ %a{:href => '#'} «
22
+ - 1.upto(10).each do |x|
23
+ %li
24
+ %a{:href => '#'}= x
25
+ %li
26
+ %a{:href => '#'} »
27
+
28
+ %ul.pager
29
+ %li
30
+ %a{:href => '#'} Previous
31
+ %li
32
+ %a{:href => '#'} Next
33
+
34
+ %ul.pager
35
+ %li.previous
36
+ %a{:href => '#'} ← Older
37
+ %li.next
38
+ %a{:href => '#'} Newer →
@@ -0,0 +1,36 @@
1
+ - variations = ['Default', 'Primary', 'Success', 'Info', 'Warning', 'Danger']
2
+
3
+ .panel.panel-default
4
+ .panel-body= Faker::Lorem.sentence(3)
5
+
6
+ - variations.each do |variation|
7
+ .panel{:class => "panel-#{variation.downcase}"}
8
+ .panel-heading= "#{variation} Panel"
9
+ .panel-body= Faker::Lorem.sentence(3)
10
+
11
+ .panel.panel-default
12
+ .panel-heading
13
+ %h3= Faker::Lorem.sentence(1)
14
+ .panel-body= Faker::Lorem.sentence(3)
15
+
16
+ .panel.panel-default
17
+ .panel-body= Faker::Lorem.sentence(3)
18
+ .panel-footer= Faker::Lorem.sentence(1)
19
+
20
+
21
+ .panel.panel-default
22
+ .panel-heading Table Panel (any non-bordered table will work here)
23
+ %table.table
24
+ %thead
25
+ %tr
26
+ %th #
27
+ %th First Name
28
+ %th Last Name
29
+ %th Email
30
+ %tbody
31
+ - 5.times do
32
+ %tr
33
+ %td= [*1..100].sample
34
+ %td= Faker::Name.first_name
35
+ %td= Faker::Name.last_name
36
+ %td= Faker::Internet.email
@@ -0,0 +1,30 @@
1
+ - variations = ['Default', 'Primary', 'Success', 'Info', 'Warning', 'Danger']
2
+
3
+ .progress
4
+ .progress-bar{:role => 'progressbar', 'aria-valuenow' => 40, 'aria-valuemin' => 0, 'aria-valuemax' => 100, :style => 'width: 40%'}
5
+ %span.sr-only 40% Complete
6
+
7
+ .progress
8
+ .progress-bar{:role => 'progressbar', 'aria-valuenow' => 60, 'aria-valuemin' => 0, 'aria-valuemax' => 100, :style => 'width: 60%'}
9
+ 60%
10
+
11
+ .progress
12
+ .progress-bar{:role => 'progressbar', 'aria-valuenow' => 0, 'aria-valuemin' => 0, 'aria-valuemax' => 100}
13
+ 0%
14
+
15
+ .progress
16
+ .progress-bar{:role => 'progressbar', 'aria-valuenow' => 2, 'aria-valuemin' => 0, 'aria-valuemax' => 100, :style => 'width: 2%'}
17
+ 2%
18
+
19
+ - variations.last(4).each_with_index do |variation, index|
20
+ .progress
21
+ .progress-bar{:class => "progress-bar-#{variation.downcase}", :role => 'progressbar', 'aria-valuenow' => (index+2)*20, 'aria-valuemin' => 0, 'aria-valuemax' => 100, :style => "width: #{(index+2)*20}%"}
22
+ = "#{(index+2)*20}%"
23
+
24
+ .progress
25
+ .progress-bar.progress-bar-striped.active{:role => 'progressbar', 'aria-valuenow' => 95, 'aria-valuemin' => 0, 'aria-valuemax' => 100, :style => "width: 95%"}
26
+
27
+ .progress
28
+ - variations.last(4).each_with_index do |variation, index|
29
+ .progress-bar{:class => "progress-bar-#{variation.downcase}", :role => 'progressbar', 'aria-valuenow' => (index+1)*20, 'aria-valuemin' => 0, 'aria-valuemax' => 100, :style => "width: 22%"}
30
+
@@ -0,0 +1,15 @@
1
+ - [nil, 'table-hover', 'table-striped', 'table-bordered', 'table-condensed'].each do |variation|
2
+ %table.table{:class => variation}
3
+ %thead
4
+ %tr
5
+ %th #
6
+ %th First Name
7
+ %th Last Name
8
+ %th Email
9
+ %tbody
10
+ - 5.times do
11
+ %tr
12
+ %td= [*1..100].sample
13
+ %td= Faker::Name.first_name
14
+ %td= Faker::Name.last_name
15
+ %td= Faker::Internet.email
@@ -0,0 +1,17 @@
1
+ .row
2
+ - 4.times do
3
+ .col-sm-3
4
+ %a.thumbnail{:href => '#'}
5
+ %img{:src => 'http://placekitten.com/171/180', :height => 180, :width => 171}
6
+
7
+ .row
8
+ - 3.times do
9
+ .col-sm-4
10
+ .thumbnail
11
+ %img{:src => 'http://placekitten.com/242/200', :height => 200, :width => 242}
12
+ .caption
13
+ %h3 Thumbnail Label
14
+ %p Cumque iste repellat rerum asperiores libero. Omnis quia et illo. Dignissimos ut quod debitis.
15
+ %p
16
+ %a.btn.btn-primary Save
17
+ %a.btn.btn-default Cancel
@@ -0,0 +1,20 @@
1
+ %h1 Heading 1
2
+ %h2 Heading 2
3
+ %h3 Heading 3
4
+ %h4 Heading 4
5
+ %h5 Heading 5
6
+ %h6 Heading 6
7
+ %p
8
+ = 'Paragraph text. '
9
+ = Faker::Lorem.paragraph(8)
10
+ %blockquote Blockquote text.
11
+ %p
12
+ %strong Strong
13
+ = '-'
14
+ %em Emphasis
15
+ = '-'
16
+ %u Underline
17
+ = '-'
18
+ %small Small
19
+ = '-'
20
+ %a{:href => '#'} Link
@@ -0,0 +1,3 @@
1
+ .well Look, I'm in a well!
2
+ .well.well-lg Look, I'm in a large well!
3
+ .well.well-sm Look, I'm in a small well!
@@ -0,0 +1,88 @@
1
+ .row.effective-style-guide
2
+ .col-sm-3
3
+ %nav
4
+ %ul.nav.nav-pills.nav-stacked
5
+ - @partials.each_with_index do |partial, index|
6
+ %li{:class => ('active' if index == 0)}
7
+ %a{:href => "##{partial.parameterize}"}= partial.titleize
8
+
9
+ .col-sm-9
10
+ - @partials.each do |partial|
11
+ %div.example{:id => "#{partial.parameterize}"}
12
+ %span.example= partial.titleize
13
+ = render :partial => partial
14
+
15
+ - 10.times do
16
+ %br
17
+
18
+ :javascript
19
+ var initStyleGuide = function() {
20
+ $('.effective-style-guide > div > nav').affix({
21
+ offset: { top: $('.effective-style-guide > div > nav').offset().top - 20 }
22
+ });
23
+
24
+ $('body').scrollspy({ target: '.effective-style-guide > div > nav', offset: 100 });
25
+
26
+ $('.effective-style-guide > div > nav > ul a').on('click', function(event) {
27
+ event.preventDefault();
28
+ target = $(event.currentTarget).attr('href')
29
+ if(target.length > 0) { $('html, body').scrollTop($(target).offset().top); }
30
+ });
31
+ };
32
+
33
+ $(document).ready(function() { initStyleGuide(); });
34
+ $(document).on('page:change', function() { initStyleGuide(); });
35
+
36
+ :css
37
+ .effective-style-guide nav {
38
+ display: inline-block;
39
+ }
40
+
41
+ .effective-style-guide .nav > li > a {
42
+ padding: 5px 10px;
43
+ }
44
+
45
+ .effective-style-guide .affix {
46
+ position: fixed;
47
+ top: 20px;
48
+ }
49
+
50
+ .effective-style-guide div.example {
51
+ background-color: #fff;
52
+ border-color: #ddd;
53
+ border-radius: 4px 4px 0 0;
54
+ border-width: 1px;
55
+ box-shadow: none;
56
+ margin-left: 0;
57
+ margin-right: 0;
58
+ margin-bottom: 30px;
59
+ border-style: solid;
60
+ padding: 45px 15px 15px;
61
+ position: relative;
62
+ }
63
+
64
+ .effective-style-guide span.example {
65
+ color: #959595;
66
+ font-size: 12px;
67
+ font-weight: 700;
68
+ left: 15px;
69
+ letter-spacing: 1px;
70
+ position: absolute;
71
+ text-transform: uppercase;
72
+ top: 15px;
73
+ }
74
+
75
+ .effective-style-guide .inline-example {
76
+ color: #959595;
77
+ font-size: 12px;
78
+ font-weight: 700;
79
+ letter-spacing: 1px;
80
+ text-transform: uppercase;
81
+ margin-bottom: 20px;
82
+ }
83
+
84
+ / .effective-style-guide .inline-radio-or-checkboxes > span {
85
+ / display: inline-block;
86
+ / margin: 0px 10px 0px 0px;
87
+ / }
88
+
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ Rails.application.routes.draw do
2
+ mount EffectiveStyleGuide::Engine => '/', :as => 'effective_style_guide'
3
+ end
4
+
5
+ EffectiveStyleGuide::Engine.routes.draw do
6
+ scope :module => 'effective' do
7
+ match '/styleguide', :to => 'style_guide#show', :via => [:get], :as => 'style_guide'
8
+ match '/style-guide', :to => 'style_guide#show', :via => [:get]
9
+ match '/style_guide', :to => 'style_guide#show', :via => [:get]
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module EffectiveStyleGuide
2
+ class Engine < ::Rails::Engine
3
+ engine_name 'effective_style_guide'
4
+
5
+ # Set up our default configuration options.
6
+ initializer "effective_style_guide.defaults", :before => :load_config_initializers do |app|
7
+ eval File.read("#{config.root}/lib/generators/templates/effective_style_guide.rb")
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module EffectiveStyleGuide
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,20 @@
1
+ require "effective_style_guide/engine"
2
+ require "effective_style_guide/version"
3
+
4
+ module EffectiveStyleGuide
5
+ # The following are all valid config keys
6
+ mattr_accessor :authorization_method
7
+ mattr_accessor :layout
8
+
9
+ def self.setup
10
+ yield self
11
+ end
12
+
13
+ def self.authorized?(controller, action, resource)
14
+ if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
15
+ raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
16
+ end
17
+ true
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ module EffectiveStyleGuide
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Creates an EffectiveStyleGuide initializer in your application."
5
+ source_root File.expand_path("../../templates", __FILE__)
6
+
7
+ def copy_initializer
8
+ template "effective_style_guide.rb", "config/initializers/effective_style_guide.rb"
9
+ end
10
+
11
+ def show_readme
12
+ readme "README" if behavior == :invoke
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ Thanks for using EffectiveStyleGuide
@@ -0,0 +1,26 @@
1
+ EffectiveStyleGuide.setup do |config|
2
+ # Authorization Method
3
+ #
4
+ # This method is called by all controller actions with the appropriate action and resource
5
+ # If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
6
+ #
7
+ # Use via Proc (and with CanCan):
8
+ # config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
9
+ #
10
+ # Use via custom method:
11
+ # config.authorization_method = :my_authorization_method
12
+ #
13
+ # And then in your application_controller.rb:
14
+ #
15
+ # def my_authorization_method(action, resource)
16
+ # current_user.is?(:admin)
17
+ # end
18
+ #
19
+ # Or disable the check completely:
20
+ # config.authorization_method = false
21
+ config.authorization_method = Proc.new { |controller, action, resource| true } # All users can see every screen
22
+
23
+ # Admin Screens Layout Settings
24
+ config.layout = 'application' # All EffectiveStyleGuide controllers will use this layout
25
+
26
+ end