Class: Redbreast::Serializer::ObjC

Inherits:
Base
  • Object
show all
Includes:
Helper::General
Defined in:
lib/redbreast/serializers/objc_serializer.rb

Overview

Used for saving and creating ObjC files

Constant Summary

Constants included from Helper::General

Helper::General::ESCAPE_KEYWORDS

Instance Attribute Summary

Attributes inherited from Base

#asset_names, #bundle

Instance Method Summary collapse

Methods included from Helper::General

#app_name, #bundles, #clean_case_name, #clean_enum_name, #clean_variable_name, #config, #escape_keyword_if_needed, #escape_with_underscore_if_needed, #indent, #programming_language, #upper_camel_case

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Redbreast::Serializer::Base

Instance Method Details

#create_objc_test_cases(names:, variable:) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/redbreast/serializers/objc_serializer.rb', line 29

def create_objc_test_cases(names:, variable:)
  text = ''
  names.each do |name|
    temp_array = name.split('/')
    variable_name = temp_array.length == 1 ? clean_variable_name(name) : temp_array.unshift(temp_array.shift.downcase).join('')
    text += variable % variable_name
  end
  text
end

#generate_category(type, class_name, app_name) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/redbreast/serializers/objc_serializer.rb', line 65

def generate_category(type, class_name, app_name)
  text = "@#{type} #{class_name} ("

  return text += 'Common)\n' if app_name.nil? || app_name.empty?

  text + app_name + ")\n"
end

#generate_h_file_objc(names:, variable:) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/redbreast/serializers/objc_serializer.rb', line 53

def generate_h_file_objc(names:, variable:)
  text = ''

  names.each do |name|
    temp_arr = name.split('/').map { |folder| upper_camel_case(folder) }
    variable_name = temp_arr.length == 1 ? clean_variable_name(name) : temp_arr.unshift(temp_arr.shift.downcase).join('')
    text += variable % variable_name
  end

  text
end

#generate_m_file_objc(names:, variable_declaration:, variable_implementation:, bundle_name:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/redbreast/serializers/objc_serializer.rb', line 39

def generate_m_file_objc(names:, variable_declaration:, variable_implementation:, bundle_name:)
  text = ''

  names.each do |name|
    temp_arr = name.split('/').map { |folder| upper_camel_case(folder) }

    variable_name = temp_arr.length == 1 ? clean_variable_name(name) : temp_arr.unshift(temp_arr.shift.downcase).join('')
    text += variable_declaration % variable_name + variable_implementation % [name, bundle_name[:reference]]
    text += name == names.last ? '' : "\n"
  end

  text
end

#save(output_source_path:, template_generator:, generate_colors:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/redbreast/serializers/objc_serializer.rb', line 9

def save(output_source_path:, template_generator:, generate_colors:)
  FileUtils.mkdir_p output_source_path unless File.exist? output_source_path

  file_base_name = generate_colors ? 'UIColor' : 'UIImage'
  name = app_name.nil? ? 'Common' : app_name

  if template_generator.h_template
    write(output_source_path, template_generator.h_template, "#{file_base_name}+#{name}.h")
  end

  return unless template_generator.m_template

  write(output_source_path, template_generator.m_template, "#{file_base_name}+#{name}.m")
end

#write(output_source_path, template, file_name) ⇒ Object



24
25
26
27
# File 'lib/redbreast/serializers/objc_serializer.rb', line 24

def write(output_source_path, template, file_name)
  file = ERB.new(template, trim_mode: '-').result(binding)
  File.write(File.join(output_source_path, file_name), file)
end