1- if ! exists (' *RailsDetect' ) || ! RailsDetect ()
2- finish
3- endif
1+ hi def link rubyEntity rubyMacro
2+ hi def link rubyEntities rubyMacro
3+ hi def link rubyExceptionHandler rubyMacro
4+ hi def link rubyValidation rubyMacro
5+ hi def link rubyCallback rubyMacro
6+ hi def link rubyRakeMacro rubyMacro
7+ hi def link rubyTestMacro rubyMacro
8+ hi def link rubyMacro Macro
9+ hi def link rubyRoute rubyControl
10+ hi def link rubySchema rubyControl
11+ hi def link rubyResponse rubyControl
12+ hi def link rubyUrlHelper rubyHelper
13+ hi def link rubyViewHelper rubyHelper
14+ hi def link rubyTestHelper rubyHelper
15+ hi def link rubyUserAssertion rubyAssertion
16+ hi def link rubyAssertion rubyException
17+ hi def link rubyTestAction rubyControl
18+ hi def link rubyHelper Function
419
5- syn keyword rubyAttribute class_attribute
6- syn keyword rubyAttribute attr_internal attr_internal_accessor attr_internal_reader attr_internal_writer
7- syn keyword rubyAttribute cattr_accessor cattr_reader cattr_writer mattr_accessor mattr_reader mattr_writer
8- syn keyword rubyAttribute thread_cattr_accessor thread_cattr_reader thread_cattr_writer thread_mattr_accessor thread_mattr_reader thread_mattr_writer
9- syn keyword rubyMacro alias_attribute concern concerning delegate delegate_missing_to with_options
20+ let s: has_app = exists (' *RailsDetect' ) && RailsDetect ()
21+ let s: path = tr (expand (' %:p' ), ' \' , ' /' )
1022
11- if rails#buffer (). type_name ( ' channel ' , ' controller ' , ' helper ' , ' job ' , ' mailer ' , ' model ' , ' view ' )
23+ if s: path = ~# ' \v/app/%(channels|controllers|helpers|jobs|mailers|models)/.*\.rb$\|/app/views/ '
1224 syn keyword rubyHelper logger
1325endif
1426
15- if rails#buffer (). type_name ( ' model-observer ' )
27+ if s: path = ~# ' /app/models/.*_observer\.rb$ '
1628 syn keyword rubyMacro observe
1729
18- elseif rails#buffer (). type_name ( ' model ' )
30+ elseif s: path = ~# ' /app/models/.*\.rb$ '
1931 syn keyword rubyMacro accepts_nested_attributes_for attr_readonly attribute enum serialize store store_accessor
2032 syn keyword rubyMacro default_scope scope
2133 syn keyword rubyEntity belongs_to has_one composed_of
@@ -31,13 +43,13 @@ elseif rails#buffer().type_name('model')
3143 syn keyword rubyMacro validate has_secure_password has_secure_token
3244endif
3345
34- if rails#buffer (). type_name ( ' job ' )
46+ if s: path = ~# ' /app/jobs/.*\.rb$ '
3547 syn keyword rubyMacro queue_as
3648 syn keyword rubyExceptionHandler rescue_from retry_on discard_on
3749 syn keyword rubyCallback before_enqueue around_enqueue after_enqueue before_perform around_perform after_perform
3850endif
3951
40- if rails#buffer (). type_name ( ' helper ' , ' view ' )
52+ if s: path = ~# ' /app/helpers/.*_helper\.rb$\|/app/views/ '
4153 syn keyword rubyViewHelper
4254 \ action_name asset_pack_path asset_path asset_url atom_feed audio_path audio_tag audio_url auto_discovery_link_tag
4355 \ button_tag button_to
@@ -63,27 +75,27 @@ if rails#buffer().type_name('helper','view')
6375 syn match rubyViewHelper ' \< select\>\% (\s *{\|\s *do\>\|\s *(\=\s *&\)\@ !'
6476 syn match rubyViewHelper ' \<\% (content_for\w\@ !?\=\| current_page?\) '
6577 syn match rubyViewHelper ' \.\@ <!\<\( h\| html_escape\| u\| url_encode\)\> '
66- if rails#buffer (). type_name ( ' view-partial ' )
78+ if s: path = ~# ' _[^\/]*$ '
6779 syn keyword rubyViewHelper local_assigns
6880 endif
6981endif
7082
71- if rails#buffer (). type_name ( ' controller ' )
83+ if s: path = ~# ' /app/controllers/.*\.rb$ '
7284 syn keyword rubyHelper params request response session headers cookies flash
7385 syn keyword rubyMacro protect_from_forgery
7486 syn match rubyMacro ' \< respond_to\>\z e[( ] *[:*]'
7587 syn match rubyResponse ' \< respond_to\>\z e[( ] *\% ([&{]\| do\>\) '
7688 syn keyword rubyResponse render head redirect_to redirect_back respond_with send_data send_file
7789endif
7890
79- if rails#buffer (). type_name ( ' controller ' , ' mailer ' )
91+ if s: path = ~# ' /app/controllers/.*\.rb$\|/app/mailers/.*\.rb$\|/app/models/.*_mailer\.rb$ '
8092 syn keyword rubyHelper render_to_string
8193 syn keyword rubyCallback before_action append_before_action prepend_before_action after_action append_after_action prepend_after_action around_action append_around_action prepend_around_action skip_before_action skip_after_action skip_action
8294 syn keyword rubyMacro helper helper_attr helper_method layout
8395 syn keyword rubyExceptionHandler rescue_from
8496endif
8597
86- if rails#buffer (). type_name ( ' mailer ' )
98+ if s: path = ~# ' /app/mailers/.*\.rb$\|/app/models/.*_mailer\.rb$ '
8799 syn keyword rubyResponse mail render
88100 syn match rubyResponse " \< headers\> "
89101 syn match rubyHelper " \< headers\[\@ ="
@@ -92,16 +104,16 @@ if rails#buffer().type_name('mailer')
92104 syn keyword rubyMacro register_interceptor register_interceptors register_observer register_observers
93105endif
94106
95- if rails#buffer (). type_name ( ' model-concern ' , ' controller-concern ' )
107+ if s: path = ~# ' /app/\w\+/concerns/.*\.rb$ '
96108 syn keyword rubyMacro included class_methods
97109endif
98110
99- if rails#buffer (). type_name ( ' controller ' , ' helper ' , ' mailer ' , ' view ' ) ||
100- \ rails#buffer ().type_name (' test-controller' , ' test-integration' , ' test-system' , ' spec-request' , ' spec-feature' , ' cucumber' )
111+ if s: path = ~# ' \v/app/%(controllers|helpers|mailers).*\.rb$|/app/views/ ' ||
112+ \ s: has_app && rails#buffer ().type_name (' test-controller' , ' test-integration' , ' test-system' , ' spec-request' , ' spec-feature' , ' cucumber' )
101113 syn keyword rubyUrlHelper url_for polymorphic_path polymorphic_url edit_polymorphic_path edit_polymorphic_url new_polymorphic_path new_polymorphic_url
102114endif
103115
104- if rails#buffer (). type_name ( ' db-migration ' , ' db- schema' )
116+ if s: path = ~# ' /db/migrate/.*\.rb$\|/db/ schema\.rb$ '
105117 syn keyword rubySchema create_table change_table drop_table rename_table create_join_table drop_join_table
106118 syn keyword rubySchema add_column rename_column change_column change_column_default change_column_null remove_column remove_columns
107119 syn keyword rubySchema add_foreign_key remove_foreign_key
@@ -112,11 +124,11 @@ if rails#buffer().type_name('db-migration','db-schema')
112124 syn keyword rubySchema execute transaction
113125endif
114126
115- if rails#buffer (). type_name ( ' task ' )
127+ if s: path = ~# ' \.rake$\|/Rakefile[^/]*$ '
116128 syn match rubyRakeMacro ' ^\s *\z s\% (task\| file\| namespace\| desc\)\>\% (\s *=\)\@ !'
117129endif
118130
119- if rails#buffer (). type_name ( ' config- routes' )
131+ if s: path = ~# ' / config/ routes\>.*\.rb$ '
120132 syn keyword rubyRoute resource resources collection member new nested shallow
121133 syn keyword rubyRoute match get put patch post delete root mount
122134 syn keyword rubyRoute scope controller namespace constraints defaults
@@ -125,14 +137,39 @@ if rails#buffer().type_name('config-routes')
125137 syn keyword rubyHelper redirect
126138endif
127139
140+ if s: path = ~# ' /test\%(/\|/.*/\)test_[^\/]*\.rb$\|/test/.*_test\.rb$\|/features/step_definitions/.*\.rb$'
141+ syn keyword rubyAssertion refute refute_empty refute_equal refute_in_delta refute_in_epsilon refute_includes refute_instance_of refute_kind_of refute_match refute_nil refute_operator refute_predicate refute_respond_to refute_same
142+ syn keyword rubyAssertion assert assert_block assert_equal assert_includes assert_in_delta assert_instance_of assert_kind_of assert_match assert_nil assert_no_match assert_not assert_not_equal assert_not_includes assert_not_nil assert_not_same assert_nothing_raised assert_nothing_thrown assert_operator assert_raise assert_respond_to assert_same assert_send assert_throws
143+ syn keyword rubyAssertion flunk
144+ endif
145+
146+ if s: path = ~# ' /spec/.*_spec\.rb$'
147+ syn match rubyTestHelper ' \< subject\> '
148+ syn match rubyTestMacro ' \<\% (let\| given\)\> !\= '
149+ syn match rubyTestMacro ' \< subject\> !\=\z e\s *\% ([({&:]\| do\>\) '
150+ syn keyword rubyTestMacro before after around background setup teardown
151+ syn keyword rubyTestMacro context describe feature shared_context shared_examples shared_examples_for containedin =rubyKeywordAsMethod
152+ syn keyword rubyTestMacro it example specify scenario include_examples include_context it_should_behave_like it_behaves_like
153+ syn keyword rubyComment xcontext xdescribe xfeature containedin =rubyKeywordAsMethod
154+ syn keyword rubyComment xit xexample xspecify xscenario
155+ endif
156+ if s: path = ~# ' /spec/.*_spec\.rb$\|/features/step_definitions/.*\.rb$'
157+ syn keyword rubyAssertion pending skip expect is_expected expect_any_instance_of allow allow_any_instance_of
158+ syn keyword rubyTestHelper described_class
159+ syn keyword rubyTestHelper double instance_double class_double object_double
160+ syn keyword rubyTestHelper spy instance_spy class_spy object_spy
161+ syn keyword rubyTestAction stub_const hide_const
162+ endif
163+
164+ if ! s: has_app
165+ finish
166+ endif
167+
128168if rails#buffer ().type_name (' test' )
129169 if ! empty (rails#app ().user_assertions ())
130170 exe " syn keyword rubyUserAssertion " .join (rails#app ().user_assertions ())
131171 endif
132172 syn keyword rubyTestMacro test setup teardown
133- syn keyword rubyAssertion refute refute_empty refute_equal refute_in_delta refute_in_epsilon refute_includes refute_instance_of refute_kind_of refute_match refute_nil refute_operator refute_predicate refute_respond_to refute_same
134- syn keyword rubyAssertion assert assert_block assert_equal assert_includes assert_in_delta assert_instance_of assert_kind_of assert_match assert_nil assert_no_match assert_not assert_not_equal assert_not_includes assert_not_nil assert_not_same assert_nothing_raised assert_nothing_thrown assert_operator assert_raise assert_respond_to assert_same assert_send assert_throws
135- syn keyword rubyAssertion flunk
136173 syn keyword rubyAssertion assert_difference assert_no_difference
137174 syn keyword rubyTestAction travel travel_to travel_back
138175endif
@@ -152,23 +189,6 @@ if rails#buffer().type_name('test-system')
152189 syn keyword rubyAssertion refute_button refute_checked_field refute_content refute_css refute_current_path refute_field refute_link refute_select refute_selector refute_table refute_text refute_title refute_unchecked_field refute_xpath
153190endif
154191
155- if rails#buffer ().type_name (' spec' )
156- syn match rubyTestHelper ' \< subject\> '
157- syn match rubyTestMacro ' \<\% (let\| given\)\> !\= '
158- syn match rubyTestMacro ' \< subject\> !\=\z e\s *\% ([({&:]\| do\>\) '
159- syn keyword rubyTestMacro before after around background setup teardown
160- syn keyword rubyTestMacro context describe feature shared_context shared_examples shared_examples_for containedin =rubyKeywordAsMethod
161- syn keyword rubyTestMacro it example specify scenario include_examples include_context it_should_behave_like it_behaves_like
162- syn keyword rubyComment xcontext xdescribe xfeature containedin =rubyKeywordAsMethod
163- syn keyword rubyComment xit xexample xspecify xscenario
164- endif
165- if rails#buffer ().type_name (' spec' , ' cucumber' )
166- syn keyword rubyAssertion pending skip expect is_expected expect_any_instance_of allow allow_any_instance_of
167- syn keyword rubyTestHelper described_class
168- syn keyword rubyTestHelper double instance_double class_double object_double
169- syn keyword rubyTestHelper spy instance_spy class_spy object_spy
170- syn keyword rubyTestAction stub_const hide_const
171- endif
172192if rails#buffer ().type_name (' spec-controller' )
173193 syn keyword rubyTestMacro render_views
174194 syn keyword rubyTestHelper assigns
@@ -202,6 +222,12 @@ if rails#buffer().type_name('test-system', 'spec-feature', 'cucumber')
202222 syn keyword rubyTestAction attach_file check choose click_button click_link click_link_or_button click_on fill_in select uncheck unselect
203223endif
204224
225+ syn keyword rubyAttribute class_attribute
226+ syn keyword rubyAttribute attr_internal attr_internal_accessor attr_internal_reader attr_internal_writer
227+ syn keyword rubyAttribute cattr_accessor cattr_reader cattr_writer mattr_accessor mattr_reader mattr_writer
228+ syn keyword rubyAttribute thread_cattr_accessor thread_cattr_reader thread_cattr_writer thread_mattr_accessor thread_mattr_reader thread_mattr_writer
229+ syn keyword rubyMacro alias_attribute concern concerning delegate delegate_missing_to with_options
230+
205231let s: keywords = split (join (filter (rails#buffer ().projected (' keywords' ),
206232 \ ' type(v:val) == type("")' ), ' ' ))
207233let s: special = filter (copy (s: keywords ), ' v:val =~# '' ^\h\k*[?!]$'' ' )
@@ -213,22 +239,3 @@ endif
213239if ! empty (s: regular )
214240 exe ' syn keyword' s: group join (s: regular , ' ' )
215241endif
216-
217- hi def link rubyEntity rubyMacro
218- hi def link rubyEntities rubyMacro
219- hi def link rubyExceptionHandler rubyMacro
220- hi def link rubyValidation rubyMacro
221- hi def link rubyCallback rubyMacro
222- hi def link rubyRakeMacro rubyMacro
223- hi def link rubyTestMacro rubyMacro
224- hi def link rubyMacro Macro
225- hi def link rubyRoute rubyControl
226- hi def link rubySchema rubyControl
227- hi def link rubyResponse rubyControl
228- hi def link rubyUrlHelper rubyHelper
229- hi def link rubyViewHelper rubyHelper
230- hi def link rubyTestHelper rubyHelper
231- hi def link rubyUserAssertion rubyAssertion
232- hi def link rubyAssertion rubyException
233- hi def link rubyTestAction rubyControl
234- hi def link rubyHelper Function
0 commit comments