Module: SublimeDSL::Tools

Defined in:
lib/sublime_dsl/tools.rb,
lib/sublime_dsl/tools/xml.rb,
lib/sublime_dsl/tools/console.rb,
lib/sublime_dsl/tools/helpers.rb,
lib/sublime_dsl/tools/blank_slate.rb,
lib/sublime_dsl/tools/regexp_wannabe.rb,
lib/sublime_dsl/tools/stable_inspect.rb,
lib/sublime_dsl/tools/value_equality.rb

Defined Under Namespace

Modules: Helpers, StableInspect, ValueEquality, XML Classes: BlankSlate, Console, Node, RegexpWannabe

Constant Summary collapse

FORBIDDEN_CHARS_MAP =

Replacement for characters forbidden in Windows file names.

{
  '<' => '˂',  # \u02C2 - modifier letter left arrowhead
  '>' => '˃',  # \u02C3 - modifier letter right arrowhead
  ':' => '˸',  # \u02F8 - modifier letter raised colon
  '"' => 'ʺ',  # \u02BA - double prime
  '/' => '',  # \u2215 - division slash
  '|' => '¦',  # \u00A6 - broken bar
  '?' => 'ʔ',  # \u0294 - latin letter glottal stop
  '*' => '',  # \u2736 - six pointed black star
  '\\' => 'ʅ'  # \u0285 - latin small letter squat reversed esh
}
FORBIDDEN_RE =

Regexp matching characters forbidden in Windows file names.

/[#{FORBIDDEN_CHARS_MAP.keys.map { |s| '\\' << s }.join}]/

Class Method Summary collapse

Class Method Details

.filename(text) ⇒ Object

Returns an OS-compatible file name for text.

Maps forbidden characters in Windows file names to something visually close (even on OSX and Linux):

<>:"/|?*\  =>  ˂˃˸ʺ∕¦ʔ✶ʅ

– TODO: allow the user to control this (with a config file).



60
61
62
# File 'lib/sublime_dsl/tools.rb', line 60

def self.filename(text)
  text.gsub(FORBIDDEN_RE, FORBIDDEN_CHARS_MAP)
end

.osObject

Returns the running OS: :Windows, :OSX or :Linux.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sublime_dsl/tools.rb', line 24

def self.os
  @os ||=
    case RbConfig::CONFIG['host_os']
    when /mswin|mingw/
      :Windows
    when /darwin/
      :OSX
    else
      :Linux
    end
end

.zip(dir, archive) ⇒ Object

Zips the content of dir into file archive.



16
17
18
19
20
21
# File 'lib/sublime_dsl/tools.rb', line 16

def self.zip(dir, archive)
  dir = dir + '/' unless dir.end_with?('/')
  Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
    Dir["#{dir}**/*"].each { |f| zipfile.add(f.sub(dir, ''), f) }
  end
end