public
Description: Ruby on Rails TextMate bundle [Learn it with PeepCode - http://peepcode.com/products/textmate-for-rails-2]
Homepage: http://groups.google.com/group/rubyonrails-textmate
Clone URL: git://github.com/drnic/ruby-on-rails-tmbundle.git
Search Repo:
Click here to lend your support to: ruby-on-rails-tmbundle and make a donation at www.pledgie.com !
Improved Haml and Sass support
lawrencepit (author)
Mon Mar 03 14:26:03 -0800 2008
commit  ec33f5ac385790d8ddce5e596cffdad9024468e4
tree    90379776ea1b22390e29b9ce162b5c96dd28d354
parent  0dc00971cdaaf8bc0eff91aea3bc245cc2c929d0
...
72
73
74
 
75
76
77
...
72
73
74
75
76
77
78
0
@@ -72,6 +72,7 @@ Added so far:
0
     * Added generator_test
0
     * Removed unnecessary misc_test
0
     * script/clean_bundle_file_names - rename non-os-agnostic file names [Charles Roper]
0
+ * Haml support [Lawrence Pit]
0
 
0
 For thoughts and patches, email drnicwilliams@gmail.com
0
 
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@
0
   <key>output</key>
0
   <string>showAsTooltip</string>
0
   <key>scope</key>
0
- <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.helper, meta.rails.functional_test, source.js, source.css, source.yaml, meta.rails.model, meta.rails.unit_test</string>
0
+ <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.helper, meta.rails.functional_test, source.js, source.css, source.yaml, meta.rails.model, meta.rails.unit_test, text.haml</string>
0
   <key>uuid</key>
0
   <string>9453F0B3-B946-445F-BDB0-B01DE70732FC</string>
0
 </dict>
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@
0
   <key>output</key>
0
   <string>showAsTooltip</string>
0
   <key>scope</key>
0
- <string>source.ruby.rails, text.html.ruby, source.ruby.rails.embedded.html</string>
0
+ <string>source.ruby.rails, text.html.ruby, source.ruby.rails.embedded.html, text.haml</string>
0
   <key>uuid</key>
0
   <string>09BB96F2-75FD-48A7-8314-B5B56B09B477</string>
0
 </dict>
...
1
2
 
3
4
5
...
16
17
18
19
 
20
21
22
...
1
 
2
3
4
5
...
16
17
18
 
19
20
21
22
0
@@ -1,5 +1,5 @@
0
 <?xml version="1.0" encoding="UTF-8"?>
0
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
0
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
0
 <plist version="1.0">
0
 <dict>
0
   <key>beforeRunningCommand</key>
0
@@ -16,7 +16,7 @@
0
   <key>output</key>
0
   <string>showAsTooltip</string>
0
   <key>scope</key>
0
- <string>source.ruby.rails, text.html.ruby, source.ruby.rails.embedded.html, source.yaml</string>
0
+ <string>source.ruby.rails, text.html.ruby, source.ruby.rails.embedded.html, source.yaml, text.haml, source.css, source.js</string>
0
   <key>uuid</key>
0
   <string>0CCC8443-40F3-4BAB-9440-D737562B5F45</string>
0
 </dict>
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@
0
   <key>output</key>
0
   <string>showAsTooltip</string>
0
   <key>scope</key>
0
- <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.controller, meta.rails.model, meta.rails.unit_test, meta.rails.functional_test</string>
0
+ <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.controller, meta.rails.model, meta.rails.unit_test, meta.rails.functional_test, text.haml</string>
0
   <key>uuid</key>
0
   <string>51C9C27A-D931-49F9-B6D8-C0E7ABEC992D</string>
0
 </dict>
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@
0
   <key>output</key>
0
   <string>showAsTooltip</string>
0
   <key>scope</key>
0
- <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.controller, meta.rails.helper</string>
0
+ <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.controller, meta.rails.helper, text.haml</string>
0
   <key>uuid</key>
0
   <string>B078346F-61D8-4E75-9427-80720FBC67F7</string>
0
 </dict>
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@
0
   <key>output</key>
0
   <string>showAsTooltip</string>
0
   <key>scope</key>
0
- <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.helper, meta.rails.unit_test, source.js, source.css, source.yaml, meta.rails.controller, meta.rails.functional_test</string>
0
+ <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.helper, meta.rails.unit_test, source.js, source.css, source.yaml, meta.rails.controller, meta.rails.functional_test, text.haml</string>
0
   <key>uuid</key>
0
   <string>C7151BF3-7068-4344-9B09-86F3BF4A9C63</string>
0
 </dict>
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@
0
   <key>output</key>
0
   <string>showAsTooltip</string>
0
   <key>scope</key>
0
- <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.controller, meta.rails.helper</string>
0
+ <string>text.html.ruby, source.ruby.rails.embedded.html, meta.rails.controller, meta.rails.helper, text.haml</string>
0
   <key>uuid</key>
0
   <string>B207BBD4-D6AA-41E9-9530-27210F2D7B66</string>
0
 </dict>
...
19
20
21
22
 
23
24
25
...
19
20
21
 
22
23
24
25
0
@@ -19,7 +19,7 @@
0
   <key>output</key>
0
   <string>replaceSelectedText</string>
0
   <key>scope</key>
0
- <string>source.ruby.rails, text.html.ruby</string>
0
+ <string>source.ruby.rails, text.html.ruby, text.haml</string>
0
   <key>uuid</key>
0
   <string>1DD8A214-1C97-45BA-ADEE-8F888DDE8570</string>
0
 </dict>
...
157
158
159
160
 
161
162
163
...
186
187
188
189
190
191
 
 
192
193
194
...
223
224
225
226
 
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
 
 
 
 
 
 
 
 
 
245
246
247
...
299
300
301
302
 
 
 
 
 
303
304
305
306
 
 
307
308
309
310
311
 
312
313
314
315
316
317
318
319
320
321
...
157
158
159
 
160
161
162
163
...
186
187
188
 
 
 
189
190
191
192
193
...
222
223
224
 
225
226
227
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
230
231
232
233
234
235
236
237
238
239
240
...
292
293
294
 
295
296
297
298
299
300
301
 
 
302
303
304
305
306
307
 
308
309
310
311
312
313
 
 
314
315
316
0
@@ -157,7 +157,7 @@ class RailsPath
0
       when %r{/test/functional/(.+\.(rb))$} then :functional_test
0
       when %r{/test/unit/(.+\.(rb))$} then :unit_test
0
       when %r{/public/javascripts/(.+\.(js))$} then :javascript
0
- when %r{/public/stylesheets/(.+\.(css))$} then :stylesheet
0
+ when %r{/public/stylesheets/(?:sass/)?(.+\.(css|sass))$} then :stylesheet
0
       else nil
0
       end
0
     # Store the tail (modules + file) after the regexp
0
@@ -186,9 +186,8 @@ class RailsPath
0
   end
0
 
0
   def modules
0
- return nil if tail.nil?
0
- case file_type
0
- when :view
0
+ return nil if tail.nil?
0
+ if file_type == :view
0
       tail.split('/').slice(0...-2)
0
     else
0
       tail.split('/').slice(0...-1)
0
@@ -223,25 +222,19 @@ class RailsPath
0
     end
0
     controller_names
0
   end
0
-
0
+
0
   def default_extension_for(type, view_format = nil)
0
     case type
0
     when :javascript then ENV['RAILS_JS_EXT'] || '.js'
0
- when :stylesheet then ENV['RAILS_CSS_EXT'] || '.css'
0
- when :view then
0
- begin
0
- if ENV['RAILS_VIEW_EXT']
0
- view_format ? ".#{view_format}#{ENV['RAILS_VIEW_EXT']}" : ENV['RAILS_VIEW_EXT']
0
- else
0
- if view_format.nil?
0
- view_format = :html
0
- end
0
- case view_format.to_sym
0
- when :xml then '.xml.builder'
0
- when :js then '.js.rjs'
0
- else ".#{view_format}.erb"
0
- end
0
- end
0
+ when :stylesheet then ENV['RAILS_CSS_EXT'] || (wants_haml ? '.sass' : '.css')
0
+ when :view then
0
+ view_format = :html if view_format.nil?
0
+ case view_format.to_sym
0
+ when :xml then '.xml.builder'
0
+ when :js then '.js.rjs'
0
+ else
0
+ rails_view_ext = ENV['RAILS_VIEW_EXT'] || (wants_haml ? '.haml' : '.erb')
0
+ ".#{view_format}#{rails_view_ext}"
0
       end
0
     when :fixture then '.yml'
0
     else '.rb'
0
@@ -299,23 +292,25 @@ class RailsPath
0
     return {:extension => extension, :content_type => content_type, :file_name => file_name}
0
   end
0
 
0
- def self.stubs
0
+ def wants_haml
0
+ @wants_html ||= File.file?(File.join(rails_root, "vendor/plugins/haml/", "init.rb"))
0
+ end
0
+
0
+ def stubs
0
     { :controller => 'app/controllers',
0
       :model => 'app/models',
0
- :helper => '/app/helpers/',
0
- :view => '/app/views/',
0
+ :helper => 'app/helpers/',
0
+ :view => 'app/views/',
0
       :config => 'config',
0
       :lib => 'lib',
0
       :log => 'log',
0
       :javascript => 'public/javascripts',
0
- :stylesheet => 'public/stylesheets',
0
+ :stylesheet => wants_haml ? 'public/stylesheets/sass' : 'public/stylesheets',
0
       :functional_test => 'test/functional',
0
       :unit_test => 'test/unit',
0
       :fixture => 'test/fixtures'}
0
   end
0
 
0
- def stubs; self.class.stubs end
0
-
0
   def ==(other)
0
     other = other.filepath if other.respond_to?(:filepath)
0
     @filepath == other
...
9
10
11
12
13
14
 
 
 
 
15
16
17
...
9
10
11
 
 
 
12
13
14
15
16
17
18
0
@@ -9,9 +9,10 @@ class PostsController < ApplicationController
0
 
0
   def index
0
     respond_to do |wants|
0
- wants.html { }
0
- wants.js { }
0
- wants.css { }
0
+ wants.html { }
0
+ wants.xml { }
0
+ wants.js { }
0
+ wants.wacky { }
0
     end
0
     respond_to do |format|
0
       format.html { }
...
3
4
5
6
7
8
9
10
11
 
 
 
12
13
14
15
16
17
18
 
19
20
21
...
95
96
97
98
99
 
 
100
101
102
...
229
230
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
233
...
3
4
5
 
 
 
 
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
...
94
95
96
 
 
97
98
99
100
101
...
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
0
@@ -3,19 +3,18 @@ require File.dirname(__FILE__) + '/test_helper'
0
 require 'text_mate_mock'
0
 require 'rails/rails_path'
0
 
0
-TextMate.line_number = '1'
0
-TextMate.column_number = '1'
0
-TextMate.project_directory = File.expand_path(File.dirname(__FILE__) + '/app_fixtures')
0
-
0
 class RailsPathTest < Test::Unit::TestCase
0
   def setup
0
+ TextMate.line_number = '1'
0
+ TextMate.column_number = '1'
0
+ TextMate.project_directory = File.expand_path(File.dirname(__FILE__) + '/app_fixtures')
0
     @rp_controller = RailsPath.new(FIXTURE_PATH + '/app/controllers/user_controller.rb')
0
     @rp_controller_with_module = RailsPath.new(FIXTURE_PATH + '/app/controllers/admin/base_controller.rb')
0
     @rp_view = RailsPath.new(FIXTURE_PATH + '/app/views/user/new.rhtml')
0
     @rp_view_with_module = RailsPath.new(FIXTURE_PATH + '/app/views/admin/base/action.rhtml')
0
     @rp_fixture = RailsPath.new(FIXTURE_PATH + '/test/fixtures/users.yml')
0
     @rp_fixture_spec = RailsPath.new(FIXTURE_PATH + '/spec/fixtures/users.yml')
0
- @rp_wacky = RailsPath.new(FIXTURE_PATH + '/wacky/users.yml')
0
+ @rp_wacky = RailsPath.new(FIXTURE_PATH + '/wacky/users.yml')
0
   end
0
 
0
   def test_rails_root
0
@@ -95,8 +94,8 @@ class RailsPathTest < Test::Unit::TestCase
0
 
0
   def test_respond_to_format
0
     current_file = RailsPath.new(FIXTURE_PATH + '/app/controllers/posts_controller.rb')
0
- TextMate.line_number = '13'
0
- assert_equal [12, 'js'], current_file.respond_to_format
0
+ TextMate.line_number = '14'
0
+ assert_equal [13, 'js'], current_file.respond_to_format
0
   end
0
 
0
   def test_rails_path_for
0
@@ -229,4 +228,62 @@ class RailsPathTest < Test::Unit::TestCase
0
     assert_equal(:model, RailsPath.new(FIXTURE_PATH + '/app/views/notifier/forgot_password.html.erb').best_match)
0
     assert_equal(:controller, RailsPath.new(FIXTURE_PATH + '/app/views/books/new.haml').best_match)
0
   end
0
+
0
+ def test_wants_haml
0
+ begin
0
+ assert_equal false, @rp_view.wants_haml
0
+ haml_fixture_path = File.expand_path(File.dirname(__FILE__) + '/fixtures')
0
+ TextMate.project_directory = haml_fixture_path
0
+ assert_equal true, RailsPath.new(haml_fixture_path + '/app/views/posts/index.html.haml').wants_haml
0
+ ensure
0
+ TextMate.project_directory = File.expand_path(File.dirname(__FILE__) + '/app_fixtures')
0
+ end
0
+ end
0
+
0
+ def test_haml
0
+ begin
0
+ haml_fixture_path = File.expand_path(File.dirname(__FILE__) + '/fixtures')
0
+ TextMate.project_directory = haml_fixture_path
0
+
0
+ assert_equal [], RailsPath.new(haml_fixture_path + '/public/stylesheets/sass/posts.sass').modules
0
+ assert_equal ["admin"], RailsPath.new(haml_fixture_path + '/public/stylesheets/sass/admin/posts.sass').modules
0
+
0
+ # Going from controller to view
0
+ current_file = RailsPath.new(haml_fixture_path + '/app/controllers/posts_controller.rb')
0
+ TextMate.line_number = '2'
0
+ assert_equal RailsPath.new(haml_fixture_path + '/app/views/posts/new.html.haml'), current_file.rails_path_for(:view)
0
+
0
+ current_file = RailsPath.new(haml_fixture_path + '/app/controllers/posts_controller.rb')
0
+ TextMate.line_number = '12'
0
+ assert_equal RailsPath.new(haml_fixture_path + '/app/views/posts/index.html.haml'), current_file.rails_path_for(:view)
0
+
0
+ current_file = RailsPath.new(haml_fixture_path + '/app/controllers/posts_controller.rb')
0
+ TextMate.line_number = '13'
0
+ assert_equal RailsPath.new(haml_fixture_path + '/app/views/posts/index.xml.builder'), current_file.rails_path_for(:view)
0
+
0
+ current_file = RailsPath.new(haml_fixture_path + '/app/controllers/posts_controller.rb')
0
+ TextMate.line_number = '14'
0
+ assert_equal RailsPath.new(haml_fixture_path + '/app/views/posts/index.js.rjs'), current_file.rails_path_for(:view)
0
+
0
+ current_file = RailsPath.new(haml_fixture_path + '/app/controllers/posts_controller.rb')
0
+ TextMate.line_number = '15'
0
+ assert_equal RailsPath.new(haml_fixture_path + '/app/views/posts/index.wacky.haml'), current_file.rails_path_for(:view)
0
+
0
+ # Going from view to controller
0
+ current_file = RailsPath.new(haml_fixture_path + '/app/views/posts/index.html.haml')
0
+ assert_equal RailsPath.new(haml_fixture_path + '/app/controllers/posts_controller.rb'), current_file.rails_path_for(:controller)
0
+
0
+ # Going from view to stylesheet
0
+ current_file = RailsPath.new(haml_fixture_path + '/app/views/posts/index.html.haml')
0
+ assert_equal RailsPath.new(haml_fixture_path + '/public/stylesheets/sass/posts.sass'), current_file.rails_path_for(:stylesheet)
0
+
0
+ # Going from stylesheet to helper
0
+ current_file = RailsPath.new(haml_fixture_path + '/public/stylesheets/sass/posts.sass')
0
+ assert_equal RailsPath.new(haml_fixture_path + '/app/helpers/posts_helper.rb'), current_file.rails_path_for(:helper)
0
+
0
+ ensure
0
+ TextMate.project_directory = File.expand_path(File.dirname(__FILE__) + '/app_fixtures')
0
+ end
0
+ end
0
+
0
 end
0
\ No newline at end of file
...
831
832
833
 
834
835
836
...
831
832
833
834
835
836
837
0
@@ -831,6 +831,7 @@
0
     <string>D54FBDED-5481-4CC7-B75F-66465A499882</string>
0
     <string>87EF33FE-E918-11DC-A399-00112475D960</string>
0
     <string>C0FD2646-E924-11DC-A399-00112475D960</string>
0
+ <string>ADD9E242-E926-11DC-A399-00112475D960</string>
0
   </array>
0
   <key>uuid</key>
0
   <string>467A60E0-6227-11D9-BFB1-000D93589AF6</string>

Comments

    No one has commented yet.