Class: Fdlint::Helper::CodeType

Inherits:
Object
  • Object
show all
Defined in:
lib/fdlint/helper/code_type.rb

Class Method Summary collapse

Class Method Details

.guess(text, filename = nil) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/fdlint/helper/code_type.rb', line 8

def guess(text, filename=nil)
  if filename && !filename.empty?
    guess_by_name filename
  else
    guess_by_content text
  end
end

.guess_by_content(text) ⇒ Object



27
28
29
30
31
# File 'lib/fdlint/helper/code_type.rb', line 27

def guess_by_content(text)
  return :html  if html? text
  return :css   if css? text
  :js #TODO: support more code syntaxes
end

.guess_by_name(filename) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/fdlint/helper/code_type.rb', line 16

def guess_by_name( filename )
  case File.extname( filename )
  when /\.css$/i
    :css
  when /\.js$/i
    :js
  else
    :html #TODO: support more suffix
  end
end

.scope(filename) ⇒ Object



37
38
39
# File 'lib/fdlint/helper/code_type.rb', line 37

def scope(filename)
  filename =~ /[\\\/]lib[\\\/]/ ? 'lib' : 'page'
end

.style_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/fdlint/helper/code_type.rb', line 33

def style_file?(filename)
  File.extname( filename ) =~ /(css|js|html?)$/i
end