%YAML 1.2 --- name: Ruby on Rails file_extensions: - rxml - builder scope: source.ruby.rails contexts: main: - include: early-expressions - include: late-expressions - include: 'scope:source.ruby#expressions' embedded-expressions: - include: early-expressions # This is placed here to prevent the lookaheads from causing infinite recursion - include: scope:source.ruby - include: late-expressions early-expressions: # Uses negative lookahead to filter out symbols - match: | (?x) \b ( before_(filter|action) | skip_before_(filter|action) | skip_after_(filter|action) | after_(filter|action) | around_(filter|action) | filter | filter_parameter_logging | layout | require_dependency | render | render_action | render_text | render_file | render_template | render_nothing | render_component | render_without_layout | rescue_from | url_for | redirect_to | redirect_to_path | redirect_to_url | respond_to | helper | helper_method | model | observer | serialize | scaffold | verify | hide_action | append_view_path | prepend_view_path | view_paths ) (?![?!:]) \b scope: support.function.actionpack.rails # Uses negative lookahead to filter out symbols - match: | (?x) \b ( named_scope | default_scope | scope | after_create | after_destroy | after_save | after_update | after_validation | after_validation_on_create | after_validation_on_update | after_rollback | after_(create_|destroy_|update_)?commit | before_create | before_destroy | before_save | before_update | before_validation | before_validation_on_create | before_validation_on_update | composed_of | belongs_to | has_one | has_many | has_and_belongs_to_many | validate | validate_on_create | validates_numericality_of | validate_on_update | validates_acceptance_of | validates_associated | validates_confirmation_of | validates_each | validates_format_of | validates_inclusion_of | validates_exclusion_of | validates_length_of | validates_presence_of | validates_size_of | validates_uniqueness_of | validates | attr_protected | attr_accessible | attr_readonly ) (?![?!:]) \b scope: support.function.activerecord.rails - match: | (?x) \b ( alias_method_chain | alias_attribute | delegate | cattr_accessor | mattr_accessor | class_attribute | returning ) \b scope: support.function.activesupport.rails # These expressions match the leading whitespace to properly match the correct # "end", but it also means they'll match before the main Ruby syntax will late-expressions: # Uses lookahead to match classes with the ControllerTest suffix - match: '(^\s*)(?=class\s+(([.[:alnum:]_:]+ControllerTest(\s*<\s*[.[:alnum:]_:]+)?)))' push: - meta_scope: meta.functional_test.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions # Uses lookahead to match classes with the Controller suffix - match: '(^\s*)(?=class\s+(([.[:alnum:]_:]+Controller\b(\s*<\s*[.[:alnum:]_:]+)?)|(<<\s*[.[:alnum:]_:]+)))(?!.+\bend\b)' push: - meta_scope: meta.controller.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions # Uses lookahead to match modules with the Helper suffix - match: '(^\s*)(?=module\s+((([[:upper:]]\w*::)*)[[:upper:]]\w*)Helper\b)' push: - meta_scope: meta.helper.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions # Uses lookahead to match classes that inherit from ActionMailer::Base - match: '(^\s*)(?=class\s+(([.[:alnum:]_:]+(\s*<\s*ActionMailer::Base\b))))' push: - meta_scope: meta.mailer.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions # Uses lookahead to match classes that (may) inherit from ActiveRecord::Base - match: (^\s*)(?=class\s+.+ActiveRecord::Base\b) push: - meta_scope: meta.model.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions # Uses lookahead to match classes that (may) inherit from ActiveRecord::Migration - match: (^\s*)(?=class\s+.+ActiveRecord::Migration\b) push: - meta_scope: meta.migration.rails - match: ^\1(?=end)\b pop: true - match: (^\s*)(?=change_table)\b push: - meta_content_scope: meta.migration.change_table.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions - match: (^\s*)(?=create_table)\b push: - meta_content_scope: meta.migration.create_table.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions - include: embedded-expressions # Uses lookahead to match classes with the Test suffix - match: '(^\s*)(?=class\s+(?![.[:alnum:]_:]+ControllerTest)(([.[:alnum:]_:]+Test(\s*<\s*[.[:alnum:]_:]+)?)|(<<\s*[.[:alnum:]_:]+)))' push: - meta_scope: meta.unit_test.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions - match: (^\s*)ActionController::Routing::Routes push: - meta_scope: meta.routes.rails - match: ^\1(?=end)\b pop: true - include: embedded-expressions