class Swift::Boiler::Parser

Constants

CAPITALIZED_NAME
LABEL_TYPE
NAME
PROPERTY_NAME_INDEX
PROPERTY_TYPE_INDEX
SHORTCUTS
TYPE
UNKNOWN_TYPE
VIEW_TYPE

Public Instance Methods

capitalize_name(name) click to toggle source
# File lib/swift/boiler/parser.rb, line 128
def capitalize_name(name)
  place_holder = name.dup
  first_letter = place_holder.slice!(0).capitalize
  first_letter + place_holder
end
create_property_dictionary(name, capitalized_name, type) click to toggle source
# File lib/swift/boiler/parser.rb, line 109
def create_property_dictionary(name, capitalized_name, type)
  property = {}
  property[NAME] = name
  property[TYPE] = type
  property[CAPITALIZED_NAME] = capitalized_name
  property
end
create_template_from_tokens(tokens) click to toggle source
# File lib/swift/boiler/parser.rb, line 19
def create_template_from_tokens(tokens)
  template = Template.new
  template.template_path = get_template_path(tokens)
  template.class_name = get_class_name(tokens)
  template.options = get_options(tokens)
  template.properties = get_properties(tokens)
  template
end
downcase_name(name) click to toggle source
# File lib/swift/boiler/parser.rb, line 134
def downcase_name(name)
  place_holder = name.dup
  first_letter = place_holder.slice!(0).downcase
  first_letter + place_holder
end
get_class_name(tokens) click to toggle source
# File lib/swift/boiler/parser.rb, line 48
def get_class_name(tokens)
  tokens.each do |token|
    if is_class_name_token(token)
      return token.content
    end
  end
end
get_name_from_abreviation(abreviation) click to toggle source
# File lib/swift/boiler/parser.rb, line 140
def get_name_from_abreviation(abreviation)
  print SHORTCUTS[abreviation.to_sym]
  SHORTCUTS[abreviation.to_sym] 
end
get_name_from_name_token(template_name_token) click to toggle source
# File lib/swift/boiler/parser.rb, line 145
def get_name_from_name_token(template_name_token)
  template_name_token.content.downcase
end
get_options(tokens) click to toggle source
# File lib/swift/boiler/parser.rb, line 56
def get_options(tokens)
  options = {}
  tokens.each do |token|
    options[:protocol] = is_protocol_token(token)
  end
  options
end
get_properties(tokens) click to toggle source
# File lib/swift/boiler/parser.rb, line 64
def get_properties(tokens)
  properties = {}
  properties[LABEL_TYPE] = Array.new
  properties[VIEW_TYPE] = Array.new
  properties[UNKNOWN_TYPE] = Array.new
  tokens.each do |token|
    if token.type == Token::PROPERTY
      new_property = get_property_from_token(token) 
      case new_property[TYPE].to_s
        when "UILabel"
          properties[LABEL_TYPE] << new_property
        when "UIView"
          properties[VIEW_TYPE] << new_property  
        else
          properties[UNKNOWN_TYPE] << new_property
      end
    end
  end
  properties
end
get_property_from_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 102
def get_property_from_token(token)
  name = get_property_name_from_token(token)
  type = get_property_type_from_token(token)
  capitalized_name = capitalize_name(name)
  create_property_dictionary(name, capitalized_name, type)
end
get_property_name_from_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 117
def get_property_name_from_token(token)
  argument_list = token.content.split(/:/)
  name = argument_list[PROPERTY_NAME_INDEX]
  downcase_name(name)
end
get_property_type_from_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 123
def get_property_type_from_token(token)
  argument_list = token.content.split(/:/)
  argument_list[PROPERTY_TYPE_INDEX]
end
get_template_name_from_token(template_name_token) click to toggle source
# File lib/swift/boiler/parser.rb, line 94
def get_template_name_from_token(template_name_token)
  if is_abreviation(template_name_token)
    get_name_from_abreviation(template_name_token.content.downcase)
  else
    get_name_from_name_token(template_name_token)
  end
end
get_template_path(tokens) click to toggle source
# File lib/swift/boiler/parser.rb, line 28
def get_template_path(tokens)
  tokens.each do |token|
    if is_path_generation_possible_from_token(token)
      return get_template_path_from_token(token)
    end
  end
end
get_template_path_from_name_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 89
def get_template_path_from_name_token(token)
  template_name = get_template_name_from_token(token)
  File.dirname(__FILE__) + '/templates/' + template_name + ".mustache" 
end
get_template_path_from_path_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 85
def get_template_path_from_path_token(token)
  token.content
end
get_template_path_from_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 40
def get_template_path_from_token(token)
  if is_template_path_token(token)
    return get_template_path_from_path_token(token)
  elsif is_template_name_token(token)
    return get_template_path_from_name_token(token)
  end
end
is_abreviation(template_name_token) click to toggle source
# File lib/swift/boiler/parser.rb, line 149
def is_abreviation(template_name_token)
  template_name = template_name_token.content.downcase
  template_name_token.type == Token::TEMPLATE_NAME && SHORTCUTS.has_key?(template_name.to_sym)
end
is_path_generation_possible_from_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 36
def is_path_generation_possible_from_token(token)
  is_template_path_token(token) || is_template_name_token(token)
end
is_protocol_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 154
def is_protocol_token(token) 
  token.type == Token::OPTION && (token.content == "-p" || token.content == "--protocol")
end

Private Instance Methods

is_class_name_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 168
def is_class_name_token(token)
  token.type == Token::CLASS_NAME
end
is_template_name_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 164
def is_template_name_token(token)
  token.type == Token::TEMPLATE_NAME
end
is_template_path_token(token) click to toggle source
# File lib/swift/boiler/parser.rb, line 160
def is_template_path_token(token)
  token.type == Token::TEMPLATE_PATH
end