Class: XCRes::ResourcesBuilder
- Inherits:
-
FileBuilder
- Object
- FileBuilder
- XCRes::ResourcesBuilder
- Includes:
- FileHelper
- Defined in:
- lib/xcres/builder/resources_builder.rb
Constant Summary collapse
- BANNER =
<<EOS // generated by xcres // // DO NOT EDIT. This file is machine-generated and constantly overwritten. // See https://github.com/mrackwitz/xcres for more info. // EOS
- OBJC_COMPILER_KEYWORDS =
%w{ auto break case char const continue default do double else enum extern float for goto if inline int long register restrict return short signed sizeof static struct switch typedef union unsigned void volatile while }
- SWIFT_COMPILER_KEYWORDS =
%w{ class deinit enum extension func import init internal let operator private protocol public static struct subscript typealias var break case continue default do else fallthrough for if in return switch where while as dynamicType false is nil self Self super true }
- SWIFT_EXTENSIONS =
<<EOS public extension %s.Strings { public var localizedValue: String { return NSLocalizedString(self.rawValue, bundle: NSBundle(forClass: R.self), comment: "") } } EOS
Instance Attribute Summary collapse
-
#documented ⇒ Bool
(also: #documented?)
Whether the generated resources constant should contain inline documentation for each key, true by default.
-
#resources_constant_name ⇒ String
Extract resource name from #output_path, if not customized.
-
#sections ⇒ Hash{String => {String => String}}
readonly
The sections, which will been written to the built files.
-
#swift ⇒ Bool
(also: #swift?)
Whether Swift code should be generated, Objective-C used if false, false by default.
Attributes inherited from FileBuilder
Instance Method Summary collapse
- #add_section(name, items, options = {}) ⇒ Object
- #build ⇒ Object
-
#initialize ⇒ ResourcesBuilder
constructor
Initialize a new instance.
Methods included from FileHelper
Methods inherited from FileBuilder
#build_contents, #prepare_output_path!, #write_file, #write_file_eventually
Constructor Details
#initialize ⇒ ResourcesBuilder
Initialize a new instance
61 62 63 64 65 |
# File 'lib/xcres/builder/resources_builder.rb', line 61 def initialize @sections = {} self.documented = true self.swift = false end |
Instance Attribute Details
#documented ⇒ Bool Also known as: documented?
Returns whether the generated resources constant should contain inline documentation for each key, true by default.
46 47 48 |
# File 'lib/xcres/builder/resources_builder.rb', line 46 def documented @documented end |
#resources_constant_name ⇒ String
Extract resource name from #output_path, if not customized
41 42 43 |
# File 'lib/xcres/builder/resources_builder.rb', line 41 def resources_constant_name @resources_constant_name end |
#sections ⇒ Hash{String => {String => String}} (readonly)
Returns the sections, which will been written to the built files.
57 58 59 |
# File 'lib/xcres/builder/resources_builder.rb', line 57 def sections @sections end |
#swift ⇒ Bool Also known as: swift?
Returns whether Swift code should be generated, Objective-C used if false, false by default.
52 53 54 |
# File 'lib/xcres/builder/resources_builder.rb', line 52 def swift @swift end |
Instance Method Details
#add_section(name, items, options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/xcres/builder/resources_builder.rb', line 75 def add_section name, items, = {} raise ArgumentError.new 'No items given!' if items.nil? transformed_items = {} for key, value in items transformed_key = transform_key key, # Skip invalid key names if transformed_key.length == 0 logger.warn "Skip invalid key: '%s'. (Was transformed to empty text)", key next end # Skip compiler keywords compiler_keywords = swift? ? SWIFT_COMPILER_KEYWORDS : OBJC_COMPILER_KEYWORDS if compiler_keywords.include? transformed_key logger.warn "Skip invalid key: '%s'. (Was transformed to keyword '%s')", key, transformed_key next end transformed_items[transformed_key] = value end @sections[name] = transformed_items end |
#build ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/xcres/builder/resources_builder.rb', line 102 def build super if swift? build_and_write_swift else build_and_write_objc end end |