Module: Docks::Languages
- Defined in:
- lib/docks/languages.rb,
lib/docks/languages/css_language.rb,
lib/docks/languages/erb_language.rb,
lib/docks/languages/base_language.rb,
lib/docks/languages/haml_language.rb,
lib/docks/languages/html_language.rb,
lib/docks/languages/json_language.rb,
lib/docks/languages/less_language.rb,
lib/docks/languages/sass_language.rb,
lib/docks/languages/slim_language.rb,
lib/docks/languages/yaml_language.rb,
lib/docks/languages/stylus_language.rb,
lib/docks/languages/markdown_language.rb,
lib/docks/languages/javascript_language.rb,
lib/docks/languages/coffeescript_language.rb,
lib/docks/languages/common_types/markup_language.rb
Defined Under Namespace
Modules: Common
Classes: Base, CSS, CoffeeScript, ERB, HTML, Haml, JSON, JavaScript, Less, Markdown, Sass, Slim, Stylus, YAML
Class Method Summary
collapse
Class Method Details
.<<(language) ⇒ Object
35
36
37
|
# File 'lib/docks/languages.rb', line 35
def self.<<(language)
register(language)
end
|
.extension_for_file(file) ⇒ Object
73
74
75
|
# File 'lib/docks/languages.rb', line 73
def self.extension_for_file(file)
file.to_s.split(".").last
end
|
.extensions ⇒ Object
39
40
41
|
# File 'lib/docks/languages.rb', line 39
def self.extensions
@extensions.values.inject([]) { |all, all_of_type| all.concat(all_of_type.to_a) }
end
|
.file_type(file) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/docks/languages.rb', line 55
def self.file_type(file)
extension = extension_for_file(file)
type = nil
@extensions.each do |extensions_type, the_extensions|
if the_extensions.include?(extension)
type = extensions_type
break
end
end
type
end
|
.language_for(file) ⇒ Object
15
16
17
18
|
# File 'lib/docks/languages.rb', line 15
def self.language_for(file)
language = @languages[extension_for_file(file)]
language.nil? ? nil : language.instance
end
|
.most_common_markup_language ⇒ Object
48
49
50
51
52
53
|
# File 'lib/docks/languages.rb', line 48
def self.most_common_markup_language
markup_files = Grouper.source_files_of_type(Types::Languages::MARKUP)
return if markup_files.empty?
most_common = markup_files.map { |file| extension_for_file(file) }.group_by { |ext| ext }.values.max_by(&:size).first
language_for(most_common)
end
|
.register(language) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/docks/languages.rb', line 24
def self.register(language)
Array(language.extensions).each do |extension|
@extensions[language.type].add(extension)
@languages[extension] = language
end
Array(language.symbol_sources).each do |source|
SymbolSources.register(source)
end
end
|
.register_bundled_languages ⇒ Object
20
21
22
|
# File 'lib/docks/languages.rb', line 20
def self.register_bundled_languages
bundled_languages.each { |language| register(language) }
end
|
.supported_file?(file) ⇒ Boolean
69
70
71
|
# File 'lib/docks/languages.rb', line 69
def self.supported_file?(file)
extensions.include?(extension_for_file(file))
end
|