Class: Docks::Languages::JavaScript

Inherits:
Base
  • Object
show all
Defined in:
lib/docks/languages/javascript_language.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#load_stub, #renderer

Class Method Details

.extensionsObject



10
# File 'lib/docks/languages/javascript_language.rb', line 10

def self.extensions; %w(js) end

.symbol_sourcesObject



11
# File 'lib/docks/languages/javascript_language.rb', line 11

def self.symbol_sources; [SymbolSources::JQuery, SymbolSources::MDN] end

.typeObject



9
# File 'lib/docks/languages/javascript_language.rb', line 9

def self.type; Docks::Types::Languages::SCRIPT end

Instance Method Details

#parserObject



13
# File 'lib/docks/languages/javascript_language.rb', line 13

def parser; Docks::Parsers::JavaScript.instance end

#signature_for(symbol) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/docks/languages/javascript_language.rb', line 15

def signature_for(symbol)
  return unless [Types::Symbol::MIXIN, Types::Symbol::FUNCTION, Types::Symbol::FACTORY, Types::Symbol::CLASS].include?(symbol.symbol_type)
  params = symbol.fetch(:params, []).map do |param|
    text = ""
    text << "[" if param.optional
    text << param.name
    text << " = #{param.default}" if param.default
    text << "]" if param.optional
    text
  end

  presentation = if symbol.respond_to?(:method?) && symbol.method?
    if symbol.static?
      "#{symbol.for}.#{symbol.name} = function"
    elsif symbol.belongs_to.instance_of?(Containers::Klass)
      "#{symbol.for}.prototype.#{symbol.name} = function"
    else
      "#{symbol.name}: function"
    end
  else
    "function #{symbol.name}"
  end

  "#{presentation}(#{params.join(", ")}) { /* ... */ }"
end