Class: SBConstants::ObjcConstantWriter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SBConstants::ObjcConstantWriter
- Defined in:
- lib/sbconstants/objc_constant_writer.rb
Instance Attribute Summary collapse
-
#templates_dir ⇒ Object
readonly
Returns the value of attribute templates_dir.
Instance Method Summary collapse
- #default_templates_dir ⇒ Object
- #header ⇒ Object
- #implementation ⇒ Object
-
#initialize(data_source, int_out, imp_out, templates_dir) ⇒ ObjcConstantWriter
constructor
A new instance of ObjcConstantWriter.
- #present_constants(section) ⇒ Object
- #template_file_path(basename) ⇒ Object
- #template_with_file(head, body) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(data_source, int_out, imp_out, templates_dir) ⇒ ObjcConstantWriter
8 9 10 11 12 13 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 8 def initialize data_source, int_out, imp_out, templates_dir super(data_source) @int_out = int_out @imp_out = imp_out @templates_dir = templates_dir end |
Instance Attribute Details
#templates_dir ⇒ Object (readonly)
Returns the value of attribute templates_dir.
6 7 8 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 6 def templates_dir @templates_dir end |
Instance Method Details
#default_templates_dir ⇒ Object
20 21 22 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 20 def default_templates_dir @default_templates_dir ||= File.dirname(__FILE__) + '/templates' end |
#header ⇒ Object
24 25 26 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 24 def header template_with_file "#import <Foundation/Foundation.h>\n\n", File.open(template_file_path("objc_header.erb")).read end |
#implementation ⇒ Object
28 29 30 31 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 28 def implementation head = %Q{#import "<%= File.basename(options.output_path) %>.h"\n\n} template_with_file head, File.open(template_file_path("objc_implementation.erb")).read end |
#present_constants(section) ⇒ Object
40 41 42 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 40 def present_constants(section) section.constants.map { |constant| [ sanitise_key(constant), constant ] } end |
#template_file_path(basename) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 44 def template_file_path basename if templates_dir && File.exist?("#{templates_dir}/#{basename}") "#{templates_dir}/#{basename}" else "#{default_templates_dir}/#{basename}" end end |
#template_with_file(head, body) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 33 def template_with_file head, body @head = head @body = body pre_processed_template = ERB.new(File.open(template_file_path("objc_body.erb")).read, nil, '<>').result(binding) ERB.new(pre_processed_template, nil, '<>').result(binding) end |
#write ⇒ Object
15 16 17 18 |
# File 'lib/sbconstants/objc_constant_writer.rb', line 15 def write @int_out.puts header @imp_out.puts implementation end |