Class: KCommercial::Resources::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/KCommercialPipeline/core/resource/i18n/generator.rb,
lib/KCommercialPipeline/core/resource/code_generator/resources_status.rb

Defined Under Namespace

Classes: ResourcesStatus, SupportLanguage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, source, options = {}) ⇒ Generator

Create a new Generator



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 60

def initialize(component, source, options = {})
  @component = component
  @super_module = options.delete(:super_module) { 'MKResources' }
  @language = options.delete(:language) || component.main_language
  @source = source
  @resources_status = ResourcesStatus.new
  @language = SupportLanguage::OC if @language == 'oc'
  unless SupportLanguage.values.include?(@language)
    raise "You set unsupported language #{@language}, please check!"
  end
  raise "Unsupported options: #{options}" if options.count.positive?
end

Instance Attribute Details

#auto_pushObject (readonly)

Returns the value of attribute auto_push.



58
59
60
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 58

def auto_push
  @auto_push
end

#componentCocoaDepot::Component (readonly)

The component for generate the resources



50
51
52
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 50

def component
  @component
end

#languageObject (readonly)

Returns the value of attribute language.



56
57
58
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 56

def language
  @language
end

#sourceCocoaDepot::Resources::GitSource (readonly)

The source for this generator

Returns:

  • (CocoaDepot::Resources::GitSource)


54
55
56
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 54

def source
  @source
end

Instance Method Details

#auto_assets_pathPathname

The path for auto generated resources

Returns:



81
82
83
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 81

def auto_assets_path
  auto_path.join('Assets')
end

#auto_classes_pathPathname

The path for auto generated classes

Returns:



87
88
89
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 87

def auto_classes_path
  auto_path.join('Classes')
end

#auto_pathPathname

The path for auto generated files

Returns:



75
76
77
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 75

def auto_path
  component.path.join('Auto')
end

#check_local_file_statusObject



91
92
93
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 91

def check_local_file_status
  @auto_push = ResourcesUpdate.can_auto_push?
end

#generate!Object

Do the generate process, it will generate the code and get the remote resources



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/KCommercialPipeline/core/resource/i18n/generator.rb', line 95

def generate!
  check_local_file_status
  update_source
  write_colors
  write_files
  write_fonts
  write_i18ns
  write_images
  case language
  when SupportLanguage::SWIFT
    write_swift_code 'Resources.swift', resources_class_contents
  when SupportLanguage::OC
    write_oc_key_defines OCFileModel.main_model, []
    write_oc_key_defines OCFileModel.public_model, []
  end
  auto_compoment_list = component.auto_compoment_list
  component.check_auto_compoment!
  component.check_auto_codes!
  auto_publish_components(auto_compoment_list || [])
  push_resource_to_remote
end