shway 3.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 (43) hide show
  1. data/CHANGELOG +11 -0
  2. data/Manifest +41 -0
  3. data/README +14 -0
  4. data/Rakefile +47 -0
  5. data/init.rb +2 -0
  6. data/install.rb +0 -0
  7. data/install_files/javascripts/iepngfix.htc +193 -0
  8. data/install_files/javascripts/iepngfix_tilebg.js +155 -0
  9. data/install_files/stylesheets/reset.css +47 -0
  10. data/install_files/templates/example_presenter.rb +12 -0
  11. data/install_files/templates/example_stylesheet.css.rb +20 -0
  12. data/lib/rubygems/commands/shway_init_command.rb +112 -0
  13. data/lib/rubygems_plugin.rb +3 -0
  14. data/lib/shway/controllers/shway_controller.rb +22 -0
  15. data/lib/shway/css/css_helper.rb +221 -0
  16. data/lib/shway/css/css_parser.rb +155 -0
  17. data/lib/shway/css/css_styles.rb +368 -0
  18. data/lib/shway/extensions/routing_extensions.rb +22 -0
  19. data/lib/shway/helpers/html_helper.rb +54 -0
  20. data/lib/shway/helpers/shway_controller_helper.rb +51 -0
  21. data/lib/shway/helpers/shway_helper.rb +187 -0
  22. data/lib/shway/presenters/shway_model_presenter.rb +10 -0
  23. data/lib/shway/presenters/shway_presenter.rb +184 -0
  24. data/lib/shway/test/shway_test_helper.rb +78 -0
  25. data/lib/shway.rb +129 -0
  26. data/shway.gemspec +31 -0
  27. data/templates/css.html.erb +3 -0
  28. data/templates/css.rhtml +3 -0
  29. data/test/shway_core/css_config_test.rb +186 -0
  30. data/test/shway_core/css_helper_test.rb +655 -0
  31. data/test/shway_core/css_parser_test.rb +219 -0
  32. data/test/shway_core/html_helper_test.rb +32 -0
  33. data/test/shway_core/shway_controller_test.rb +44 -0
  34. data/test/shway_core/shway_core_test_helper.rb +45 -0
  35. data/test/shway_core/shway_helper_test.rb +280 -0
  36. data/test/shway_core/shway_presenter_test.rb +173 -0
  37. data/test/shway_core/shway_routes_test.rb +31 -0
  38. data/test/shway_core/views/mock_foos/_list_header.html.erb +1 -0
  39. data/test/shway_core/views/mock_foos/_list_item.html.erb +5 -0
  40. data/test/shway_core/views/model_list/list_for_action.html.erb +1 -0
  41. data/test/shway_core/views/model_list/list_item_for_action.html.erb +1 -0
  42. data/test/shway_core/views/shway_helper_test.html.erb +24 -0
  43. metadata +123 -0
data/CHANGELOG ADDED
@@ -0,0 +1,11 @@
1
+ ========================================
2
+ 2009-07-28 BRANCH v3.0
3
+ ----------------------------------------
4
+
5
+ SHWAY
6
+ -created 'shway' gem and took only what was needed from the plugins.
7
+ -this CHANGELOG is only partially populated. Once I test this out a bit I'll do a proper changelog.
8
+ -I am releasing the gem from the branch for now. I will merge it all to trunk once I am sure it all works properly.
9
+
10
+
11
+
data/Manifest ADDED
@@ -0,0 +1,41 @@
1
+ CHANGELOG
2
+ init.rb
3
+ install.rb
4
+ install_files/javascripts/iepngfix.htc
5
+ install_files/javascripts/iepngfix_tilebg.js
6
+ install_files/stylesheets/reset.css
7
+ install_files/templates/example_presenter.rb
8
+ install_files/templates/example_stylesheet.css.rb
9
+ lib/rubygems/commands/shway_init_command.rb
10
+ lib/rubygems_plugin.rb
11
+ lib/shway/controllers/shway_controller.rb
12
+ lib/shway/css/css_helper.rb
13
+ lib/shway/css/css_parser.rb
14
+ lib/shway/css/css_styles.rb
15
+ lib/shway/extensions/routing_extensions.rb
16
+ lib/shway/helpers/html_helper.rb
17
+ lib/shway/helpers/shway_controller_helper.rb
18
+ lib/shway/helpers/shway_helper.rb
19
+ lib/shway/presenters/shway_model_presenter.rb
20
+ lib/shway/presenters/shway_presenter.rb
21
+ lib/shway/test/shway_test_helper.rb
22
+ lib/shway.rb
23
+ Manifest
24
+ Rakefile
25
+ README
26
+ templates/css.html.erb
27
+ templates/css.rhtml
28
+ test/shway_core/css_config_test.rb
29
+ test/shway_core/css_helper_test.rb
30
+ test/shway_core/css_parser_test.rb
31
+ test/shway_core/html_helper_test.rb
32
+ test/shway_core/shway_controller_test.rb
33
+ test/shway_core/shway_core_test_helper.rb
34
+ test/shway_core/shway_helper_test.rb
35
+ test/shway_core/shway_presenter_test.rb
36
+ test/shway_core/shway_routes_test.rb
37
+ test/shway_core/views/mock_foos/_list_header.html.erb
38
+ test/shway_core/views/mock_foos/_list_item.html.erb
39
+ test/shway_core/views/model_list/list_for_action.html.erb
40
+ test/shway_core/views/model_list/list_item_for_action.html.erb
41
+ test/shway_core/views/shway_helper_test.html.erb
data/README ADDED
@@ -0,0 +1,14 @@
1
+ Shway
2
+ =============
3
+
4
+ shway is a Rails gem that provides powerful UI programming with dynamic css and presenters. Shway was developed by Ryan Owens.
5
+
6
+
7
+ == Install
8
+
9
+ gem install shway
10
+
11
+ == Usage
12
+
13
+ ...coming soon
14
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ #desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ #desc 'Test the simply_helpful plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ #desc 'Generate documentation for the simply_helpful plugin.'
16
+ #Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ # rdoc.rdoc_dir = 'rdoc'
18
+ # rdoc.title = 'SimplyHelpful'
19
+ # rdoc.options << '--line-numbers' << '--inline-source'
20
+ # rdoc.rdoc_files.include('README')
21
+ # rdoc.rdoc_files.include('lib/**/*.rb')
22
+ #end
23
+
24
+ desc 'Measures test coverage using rcov'
25
+ task :rcov do
26
+ rm_f "coverage"
27
+ rm_f "coverage.data"
28
+ project_name = ENV["PWD"].split(File::SEPARATOR)[-4]
29
+ rcov = %{rcov --rails --aggregate coverage.data --text-summary --exclude "#{File.join project_name, 'app'}|#{File.join project_name, 'lib'}|gems|rubygems" -Ilib}
30
+ system("#{rcov} --html #{Dir.glob('test/**/*_test.rb').join(' ')}")
31
+ system("open coverage/index.html") if PLATFORM['darwin']
32
+ end
33
+
34
+ require 'rubygems'
35
+ require 'echoe'
36
+
37
+ Echoe.new('shway', '3.0') do |p|
38
+ p.description = "Provides powerful UI programming with dynamic css and presenters.."
39
+ p.project = 'shway'
40
+ p.url = "http://rubyforge.org/projects/shway"
41
+ p.author = "Ryan Owens"
42
+ p.email = "ryan@infoether.com"
43
+ p.ignore_pattern = ["tmp/*", "script/*", "*_notes.txt"]
44
+ p.development_dependencies = []
45
+ end
46
+
47
+ # Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'shway'
2
+
data/install.rb ADDED
File without changes
@@ -0,0 +1,193 @@
1
+ <public:component>
2
+ <public:attach event="oncontentready"
3
+ onevent="IEPNGFix.process(element, 1)" />
4
+
5
+ <script type="text/javascript">
6
+
7
+ // IE5.5+ PNG Alpha Fix v2.0 Alpha 2
8
+ // (c) 2004-2008 Angus Turnbull http://www.twinhelix.com
9
+
10
+ // This is licensed under the GNU LGPL, version 2.1 or later.
11
+ // For details, see: http://creativecommons.org/licenses/LGPL/2.1/
12
+
13
+ if (!window.IEPNGFix) {
14
+ window.IEPNGFix = {};
15
+ }
16
+
17
+
18
+ // This must be a path to a blank image, relative to the HTML document(s).
19
+ // In production use I suggest '/images/blank.gif' or similar. That's all!
20
+ IEPNGFix.blankImg = '/images/blank.gif';
21
+
22
+
23
+ if (!IEPNGFix.data) {
24
+ IEPNGFix.data = {};
25
+ }
26
+
27
+
28
+ IEPNGFix.fix = function(elm, src, t) {
29
+ // Applies an image 'src' to an element 'elm' using the DirectX filter.
30
+ // If 'src' is null, filter is disabled.
31
+ // Disables the 'hook' to prevent infinite recursion on setting BG/src.
32
+ // 't' = type, where background tile = 0, background = 1, IMG SRC = 2.
33
+
34
+ var h = this.hook.enabled;
35
+ this.hook.enabled = 0;
36
+
37
+ var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
38
+ src = (src || '').replace(/\(/g, '%28').replace(/\)/g, '%29');
39
+
40
+ if (
41
+ src && !(/IMG|INPUT/.test(elm.nodeName) && (t != 2)) &&
42
+ elm.currentStyle.width == 'auto' && elm.currentStyle.height == 'auto'
43
+ ) {
44
+ elm.style.width = elm.offsetWidth + 'px';
45
+ elm.style.height = elm.clientHeight + 'px';
46
+ if (elm.currentStyle.display == 'inline') {
47
+ elm.style.display = 'inline-block';
48
+ }
49
+ }
50
+
51
+ if (t == 1) {
52
+ elm.style.backgroundImage = 'url("' + this.blankImg + '")';
53
+ }
54
+ if (t == 2) {
55
+ elm.src = this.blankImg;
56
+ }
57
+
58
+ if (elm.filters[f]) {
59
+ elm.filters[f].enabled = src ? true : false;
60
+ if (src) {
61
+ elm.filters[f].src = src;
62
+ }
63
+ } else if (src) {
64
+ elm.style.filter = 'progid:' + f + '(src="' + src +
65
+ '",sizingMethod="crop")';
66
+ }
67
+
68
+ this.hook.enabled = h;
69
+ };
70
+
71
+
72
+ IEPNGFix.process = function(elm, init) {
73
+ // Checks the onpropertychange event (on first 'init' run, a fake event)
74
+ // and calls the filter-applying-functions.
75
+
76
+ if (
77
+ !/MSIE (5\.5|6)/.test(navigator.userAgent) ||
78
+ typeof elm.filters == 'unknown'
79
+ ) {
80
+ return;
81
+ }
82
+ if (!this.data[elm.uniqueID]) {
83
+ this.data[elm.uniqueID] = {
84
+ className: ''
85
+ };
86
+ }
87
+ var data = this.data[elm.uniqueID],
88
+ evt = init ? { propertyName: 'src,backgroundImage' } : event,
89
+ isSrc = /src/.test(evt.propertyName),
90
+ isBg = /backgroundImage/.test(evt.propertyName),
91
+ isPos = /background(Pos|Rep)/.test(evt.propertyName),
92
+ isClass = !init && ((elm.className != data.className) &&
93
+ (elm.className || data.className));
94
+ if (!(isSrc || isBg || isPos || isClass)) {
95
+ return;
96
+ }
97
+ data.className = elm.className;
98
+ var blank = this.blankImg.match(/([^\/]+)$/)[1],
99
+ eS = elm.style,
100
+ eCS = elm.currentStyle;
101
+
102
+ // Required for Whatever:hover - erase set BG if className changes.
103
+ if (
104
+ isClass && (eS.backgroundImage.indexOf('url(') == -1 ||
105
+ eS.backgroundImage.indexOf(blank) > -1)
106
+ ) {
107
+ return setTimeout(function() {
108
+ eS.backgroundImage = '';
109
+ }, 0);
110
+ }
111
+
112
+ // Foregrounds.
113
+ if (isSrc && elm.src && { IMG: 1, INPUT: 1 }[elm.nodeName]) {
114
+ if ((/\.png/i).test(elm.src)) {
115
+ this.fix(elm, elm.src, 2);
116
+ } else if (elm.src.indexOf(blank) == -1) {
117
+ this.fix(elm, '');
118
+ }
119
+ }
120
+
121
+ // Backgrounds.
122
+ var bgSrc = eCS.backgroundImage || eS.backgroundImage;
123
+ if ((bgSrc + elm.src).indexOf(blank) == -1) {
124
+ var bgPNG = bgSrc.match(/url[("']+(.*\.png[^\)"']*)[\)"']/i);
125
+ if (bgPNG) {
126
+ if (this.tileBG && !{ IMG: 1, INPUT: 1 }[elm.nodeName]) {
127
+ this.tileBG(elm, bgPNG[1]);
128
+ this.fix(elm, '', 1);
129
+ } else {
130
+ if (data.tiles && data.tiles.src) {
131
+ this.tileBG(elm, '');
132
+ }
133
+ this.fix(elm, bgPNG[1], 1);
134
+ this.childFix(elm);
135
+ }
136
+ } else {
137
+ if (data.tiles && data.tiles.src) {
138
+ this.tileBG(elm, '');
139
+ }
140
+ this.fix(elm, '');
141
+ }
142
+ } else if ((isPos || isClass) && data.tiles && data.tiles.src) {
143
+ this.tileBG(elm, data.tiles.src);
144
+ }
145
+
146
+ if (init) {
147
+ this.hook.enabled = 1;
148
+ elm.attachEvent('onpropertychange', this.hook);
149
+ }
150
+ };
151
+
152
+
153
+ IEPNGFix.childFix = function(elm) {
154
+ // "hasLayout" fix for unclickable children inside PNG backgrounds.
155
+ var tags = [
156
+ 'a',
157
+ 'input',
158
+ 'select',
159
+ 'textarea',
160
+ 'button',
161
+ 'iframe',
162
+ 'object'
163
+ ],
164
+ t = tags.length,
165
+ tFix = [];
166
+ while (t--) {
167
+ var pFix = elm.all.tags(tags[t]),
168
+ e = pFix.length;
169
+ while (e--) {
170
+ tFix.push(pFix[e]);
171
+ }
172
+ }
173
+ t = tFix.length;
174
+ if (t && (/relative|absolute/i).test(elm.currentStyle.position)) {
175
+ alert('IEPNGFix: Unclickable children of element:' +
176
+ '\n\n<' + elm.nodeName + (id && ' id=' + id) + '>');
177
+ }
178
+ while (t--) {
179
+ if (!(/relative|absolute/i).test(tFix[t].currentStyle.position)) {
180
+ tFix[t].style.position = 'relative';
181
+ }
182
+ }
183
+ };
184
+
185
+
186
+ IEPNGFix.hook = function() {
187
+ if (IEPNGFix.hook.enabled) {
188
+ IEPNGFix.process(element, 0);
189
+ }
190
+ };
191
+
192
+ </script>
193
+ </public:component>
@@ -0,0 +1,155 @@
1
+ // IE5.5+ PNG Alpha Fix v2.0beta1: Background Tiling Support
2
+ // (c) 2008 Angus Turnbull http://www.twinhelix.com
3
+
4
+ // This is licensed under the GNU LGPL, version 2.1 or later.
5
+ // For details, see: http://creativecommons.org/licenses/LGPL/2.1/
6
+
7
+ if (!window.IEPNGFix) {
8
+ window.IEPNGFix = {};
9
+ }
10
+
11
+ IEPNGFix.tileBG = function(elm, pngSrc, ready) {
12
+ // Params: A reference to a DOM element, the PNG src file pathname, and a
13
+ // hidden "ready-to-run" passed when called back after image preloading.
14
+
15
+ var data = this.data[elm.uniqueID],
16
+ elmW = Math.max(elm.clientWidth, elm.scrollWidth),
17
+ elmH = Math.max(elm.clientHeight, elm.scrollHeight),
18
+ bgX = elm.currentStyle.backgroundPositionX,
19
+ bgY = elm.currentStyle.backgroundPositionY,
20
+ bgR = elm.currentStyle.backgroundRepeat;
21
+
22
+ // Cache of DIVs created per element, and image preloader/data.
23
+ if (!data.tiles) {
24
+ data.tiles = {
25
+ src: '',
26
+ cache: [],
27
+ img: new Image(),
28
+ old: {}
29
+ };
30
+ }
31
+ var tiles = data.tiles,
32
+ pngW = tiles.img.width,
33
+ pngH = tiles.img.height;
34
+
35
+ if (pngSrc) {
36
+ if (!ready && pngSrc != tiles.src) {
37
+ // New image? Preload it with a callback to detect dimensions.
38
+ tiles.img.onload = function() {
39
+ this.onload = null;
40
+ IEPNGFix.tileBG(elm, pngSrc, 1);
41
+ };
42
+ return tiles.img.src = pngSrc;
43
+ }
44
+ } else {
45
+ // No image?
46
+ if (tiles.src) ready = 1;
47
+ pngW = pngH = 0;
48
+ }
49
+ tiles.src = pngSrc;
50
+
51
+ if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&
52
+ bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {
53
+ return;
54
+ }
55
+
56
+ // Convert English and percentage positions to pixels.
57
+ var pos = {
58
+ top: '0%',
59
+ left: '0%',
60
+ center: '50%',
61
+ bottom: '100%',
62
+ right: '100%'
63
+ },
64
+ x,
65
+ y,
66
+ pc;
67
+ x = pos[bgX] || bgX;
68
+ y = pos[bgY] || bgY;
69
+ if (pc = x.match(/(\d+)%/)) {
70
+ x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));
71
+ }
72
+ if (pc = y.match(/(\d+)%/)) {
73
+ y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));
74
+ }
75
+ x = parseInt(x);
76
+ y = parseInt(y);
77
+
78
+ // Handle backgroundRepeat.
79
+ var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],
80
+ repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];
81
+ if (repeatX) {
82
+ x %= pngW;
83
+ if (x > 0) x -= pngW;
84
+ }
85
+ if (repeatY) {
86
+ y %= pngH;
87
+ if (y > 0) y -= pngH;
88
+ }
89
+
90
+ // Go!
91
+ this.hook.enabled = 0;
92
+ if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {
93
+ elm.style.position = 'relative';
94
+ }
95
+ var count = 0,
96
+ xPos,
97
+ maxX = repeatX ? elmW : x + 0.1,
98
+ yPos,
99
+ maxY = repeatY ? elmH : y + 0.1,
100
+ d,
101
+ s,
102
+ isNew;
103
+ if (pngW && pngH) {
104
+ for (xPos = x; xPos < maxX; xPos += pngW) {
105
+ for (yPos = y; yPos < maxY; yPos += pngH) {
106
+ isNew = 0;
107
+ if (!tiles.cache[count]) {
108
+ tiles.cache[count] = document.createElement('div');
109
+ isNew = 1;
110
+ }
111
+ var clipR = (xPos + pngW > elmW ? elmW - xPos : pngW),
112
+ clipB = (yPos + pngH > elmH ? elmH - yPos : pngH);
113
+ d = tiles.cache[count];
114
+ s = d.style;
115
+ s.behavior = 'none';
116
+ s.left = xPos + 'px';
117
+ s.top = yPos + 'px';
118
+ s.width = clipR + 'px';
119
+ s.height = clipB + 'px';
120
+ s.clip = 'rect(' +
121
+ (yPos < 0 ? 0 - yPos : 0) + 'px,' +
122
+ clipR + 'px,' +
123
+ clipB + 'px,' +
124
+ (xPos < 0 ? 0 - xPos : 0) + 'px)';
125
+ s.display = 'block';
126
+ if (isNew) {
127
+ s.position = 'absolute';
128
+ s.zIndex = -999;
129
+ if (elm.firstChild) {
130
+ elm.insertBefore(d, elm.firstChild);
131
+ } else {
132
+ elm.appendChild(d);
133
+ }
134
+ }
135
+ this.fix(d, pngSrc, 0);
136
+ count++;
137
+ }
138
+ }
139
+ }
140
+ while (count < tiles.cache.length) {
141
+ this.fix(tiles.cache[count], '', 0);
142
+ tiles.cache[count++].style.display = 'none';
143
+ }
144
+
145
+ this.hook.enabled = 1;
146
+
147
+ // Cache so updates are infrequent.
148
+ tiles.old = {
149
+ w: elmW,
150
+ h: elmH,
151
+ x: bgX,
152
+ y: bgY,
153
+ r: bgR
154
+ };
155
+ };
@@ -0,0 +1,47 @@
1
+ /* reset reload by Eric Meyer: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ */
2
+ html, body, div, span, applet, object, iframe,
3
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
4
+ a, abbr, acronym, address, big, cite, code,
5
+ del, dfn, em, font, img, ins, kbd, q, s, samp,
6
+ small, strike, strong, sub, sup, tt, var,
7
+ dl, dt, dd, ol, ul, li,
8
+ fieldset, form, label, legend,
9
+ table, caption, tbody, tfoot, thead, tr, th, td {
10
+ margin: 0;
11
+ padding: 0;
12
+ border: 0;
13
+ outline: 0;
14
+ font-weight: inherit;
15
+ font-style: inherit;
16
+ font-size: 100%;
17
+ font-family: inherit;
18
+ vertical-align: baseline;
19
+ }
20
+ /* remember to define focus styles! */
21
+ :focus {
22
+ outline: 0;
23
+ }
24
+ body {
25
+ line-height: 1;
26
+ color: black;
27
+ background: white;
28
+ }
29
+ ol, ul {
30
+ list-style: none;
31
+ }
32
+ /* tables still need 'cellspacing="0"' in the markup */
33
+ table {
34
+ border-collapse: separate;
35
+ border-spacing: 0;
36
+ }
37
+ caption, th, td {
38
+ text-align: left;
39
+ font-weight: normal;
40
+ }
41
+ blockquote:before, blockquote:after,
42
+ q:before, q:after {
43
+ content: "";
44
+ }
45
+ blockquote, q {
46
+ quotes: "" "";
47
+ }
@@ -0,0 +1,12 @@
1
+ class ApplicationPresenter < ShwayPresenter
2
+
3
+ #define renderers like this
4
+ renderer :default do
5
+ r div(:text => 'Application Presenter')
6
+ end
7
+
8
+ renderer :foo do
9
+ r div(:text => 'Foo')
10
+ end
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ Shway.define_styles do
2
+
3
+ #define values like this
4
+ # values :primary_background_color => '#fff6d8',
5
+ # :primary_border_color => :red
6
+
7
+ #define styles like this
8
+ # style :standard_body, {
9
+ # :background_color => :primary_background_color,
10
+ # :border => "1px solid #{get_css_value :primary_border_color}",
11
+ # }
12
+
13
+ #define selectors like this
14
+ # selector "html>body #foo", :standard_body
15
+ # selector "html>body #bar", {
16
+ # :background_color => :yellow,
17
+ # :border => '1px solid green',
18
+ # }
19
+
20
+ end
@@ -0,0 +1,112 @@
1
+ # require 'shellwords'
2
+
3
+ require 'rubygems/command'
4
+ require 'rubygems/dependency'
5
+ require 'rubygems/version_option'
6
+
7
+ require 'fileutils'
8
+
9
+ # InitCommand will initialize a Rails app with the proper files and directories.
10
+ class Gem::Commands::ShwayInitCommand < Gem::Command
11
+ include Gem::VersionOption
12
+
13
+ def initialize
14
+ super 'shway_init', "Initialize a Rails app with the proper files and directories for Shway. (must be in the rails app's root dir)",
15
+ :command => nil,
16
+ :version=> Gem::Requirement.default
17
+
18
+ # add_option('-l', '--latest',
19
+ # 'If there are multiple versions, open the latest') do |value, options|
20
+ # options[:latest] = true
21
+ # end
22
+
23
+ add_version_option
24
+ end
25
+
26
+ def execute
27
+ if is_rails_app?
28
+ init_shway
29
+ else
30
+ raise Gem::CommandLineError, "Could not initialize shway. Directory isn't a Rails app!"
31
+ end
32
+ end
33
+
34
+ def is_rails_app?
35
+ environment_path = File.join(Dir.getwd, 'config', 'environment.rb')
36
+ File.exists?(environment_path)
37
+ end
38
+
39
+ def init_shway
40
+ # init app
41
+
42
+ rails_root = Dir.getwd
43
+ shway_source_root_path = File.join(File.dirname(__FILE__), '..', '..', '..')
44
+ unless File.exists?(File.join(shway_source_root_path, 'Manifest'))
45
+ raise Gem::CommandLineError, "Could not initialize shway. Gem path appears to be incorrect: #{shway_source_root_path}"
46
+ end
47
+
48
+ app_path = File.join(rails_root, 'app')
49
+ app_presenters_path = File.join(app_path, 'presenters')
50
+ app_stylesheets_path = File.join(app_path, 'stylesheets')
51
+
52
+ mkdir app_path
53
+ mkdir app_presenters_path
54
+ mkdir app_stylesheets_path
55
+
56
+ public_root_path = File.join(rails_root, 'public')
57
+ public_images_path = File.join(public_root_path, 'images')
58
+ public_javascripts_path = File.join(public_root_path, 'javascripts')
59
+ public_javascripts_shway_path = File.join(public_javascripts_path, 'shway')
60
+ public_stylesheets_path = File.join(public_root_path, 'stylesheets')
61
+ public_stylesheets_shway_path = File.join(public_stylesheets_path, 'shway')
62
+
63
+ shway_source_install_files_path = File.join(shway_source_root_path, 'install_files')
64
+ shway_source_install_templates_path = File.join(shway_source_install_files_path, 'templates')
65
+ shway_source_install_javascripts_path = File.join(shway_source_install_files_path, 'javascripts')
66
+ shway_source_install_stylesheets_path = File.join(shway_source_install_files_path, 'stylesheets')
67
+
68
+ application_stylesheet = File.join(app_stylesheets_path, 'application.css.rb')
69
+ application_stylesheet_template = File.join(shway_source_install_templates_path, 'example_stylesheet.css.rb')
70
+ cp application_stylesheet_template, application_stylesheet
71
+
72
+ application_presenter = File.join(app_presenters_path, 'application_presenter.rb')
73
+ application_presenter_template = File.join(shway_source_install_templates_path, 'example_presenter.rb')
74
+ cp application_presenter_template, application_presenter
75
+
76
+ pngfix_js_src = File.join(shway_source_install_javascripts_path, 'iepngfix_tilebg.js')
77
+ pngfix_htc_src = File.join(shway_source_install_javascripts_path, 'iepngfix.htc')
78
+ pngfix_js_target = File.join(public_javascripts_shway_path, 'iepngfix_tilebg.js')
79
+ pngfix_htc_target = File.join(public_javascripts_shway_path, 'iepngfix.htc')
80
+
81
+ mkdir public_javascripts_shway_path
82
+ cp pngfix_js_src, pngfix_js_target
83
+ cp pngfix_htc_src, pngfix_htc_target
84
+
85
+ reset_css_src = File.join(shway_source_install_stylesheets_path, 'reset.css')
86
+ reset_css_target = File.join(public_stylesheets_shway_path, 'reset.css')
87
+
88
+ mkdir public_stylesheets_shway_path
89
+ cp reset_css_src, reset_css_target
90
+
91
+ say "shway successfully initialized."
92
+ end
93
+
94
+ def mkdir(path)
95
+ if File.exist? path
96
+ say "...already exists: #{path}"
97
+ else
98
+ FileUtils.mkdir path
99
+ say "...created: #{path}"
100
+ end
101
+ end
102
+
103
+ def cp(source, target)
104
+ if File.exist? target
105
+ say "...already exists: #{target}"
106
+ else
107
+ FileUtils.cp source, target
108
+ say "...created: #{target}"
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Gem::CommandManager.instance.register_command :shway_init
@@ -0,0 +1,22 @@
1
+ #this should maybe be ShwayCssController or PublicController or something eventually.
2
+ class ShwayController < ActionController::Base
3
+
4
+ #pretty sure this isn't necessary any more.
5
+ session :off
6
+
7
+ helper Shway::Css::CssHelper
8
+ helper Shway::Helpers::HtmlHelper
9
+ helper Shway::Helpers::ShwayControllerHelper
10
+ helper Shway::Helpers::ShwayHelper
11
+ include Shway::Css::CssHelper
12
+
13
+ def css
14
+ #GOTCHA I need to keep the flash vars so they don't get lost by the app/
15
+ flash.keep
16
+ css_name = params[:css].clone
17
+ Shway::Css::CssStyles.cache[css_name] = css_page_for_filename(params[:css]) unless Shway::Css::CssStyles.cache.has_key? css_name
18
+ render :text => Shway::Css::CssStyles.cache[css_name], :content_type => "text/css"
19
+ end
20
+
21
+ end
22
+