Sha256: a6dc052964068193509af4f557c1c9b6b3eea44b5dbe1afeeacec732739c3508

Contents?: true

Size: 1.76 KB

Versions: 34

Compression:

Stored size: 1.76 KB

Contents

module Redcar
  class StripTrailingSpaces
    def self.enabled?
      Redcar::StripTrailingSpaces.storage['enabled']
    end

    def self.enabled=(bool)
      Redcar::StripTrailingSpaces.storage['enabled'] = bool
    end

    def self.strip_blank_lines?
      Redcar::StripTrailingSpaces.storage['strip_blank_lines']
    end

    def self.strip_blank_lines=(bool)
      Redcar::StripTrailingSpaces.storage['strip_blank_lines'] = bool
    end

    def self.storage
      @storage ||= begin
        storage = Plugin::Storage.new('strip_trailing_spaces_plugin')
        storage.set_default('enabled', false)
        storage.set_default('strip_blank_lines', false)
        storage
      end
    end

    def self.menus
      Menu::Builder.build do
        sub_menu "Plugins" do
          sub_menu "Strip Trailing Spaces", :priority => 195 do
            item "Enabled", :command => ToggleStripTrailingSpaces, :type => :check, :active => StripTrailingSpaces.enabled?
            item "Strip Blank Lines", :command => ToggleStripBlankLines, :type => :check, :active => StripTrailingSpaces.strip_blank_lines?
          end
        end
      end
    end

    def self.before_save(doc)
      if (doc.mirror.is_a?(Redcar::Project::FileMirror) && StripTrailingSpaces.enabled?)
        regex         = /[\t ]*$/ if StripTrailingSpaces.strip_blank_lines?
        regex       ||= /([^\s]+)[\t ]+$/
        doc.text = doc.get_all_text.gsub(regex, "\\1")
      end
    end

    class ToggleStripTrailingSpaces < Redcar::Command
      def execute
        StripTrailingSpaces.enabled = !StripTrailingSpaces.enabled?
      end
    end

    class ToggleStripBlankLines < Redcar::Command
      def execute
        StripTrailingSpaces.strip_blank_lines = !StripTrailingSpaces.strip_blank_lines?
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
redcar-0.12.1 plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-0.12 plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.27dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.26dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.25dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.24dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.23dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.22dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.21dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.20dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.19dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.18dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.17dev plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.16dev-java plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.15dev-java plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.14dev-java plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.13dev-java plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.12dev-java plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.11dev-java plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb
redcar-dev-0.12.10dev-java plugins/strip_trailing_spaces/lib/strip_trailing_spaces.rb