Class: Fastlane::Actions::ErbAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/erb.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, output, return_value, sh, step_text

Class Method Details

.authorsObject



53
54
55
# File 'lib/fastlane/actions/erb.rb', line 53

def self.authors
  ["hjanuschka"]
end

.available_optionsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/actions/erb.rb', line 24

def self.available_options
  [

    FastlaneCore::ConfigItem.new(key: :template,
                                 short_option: "-T",
                                 env_name: "FL_ERB_SRC",
                                 description: "ERB Template File",
                                 optional: false,
                                 is_string: true
                                ),
    FastlaneCore::ConfigItem.new(key: :destination,
                                 short_option: "-D",
                                 env_name: "FL_ERB_DST",
                                 description: "Destination file",
                                 optional: true,
                                 is_string: true
                                ),
    FastlaneCore::ConfigItem.new(key: :placeholders,
                                 short_option: "-p",
                                 env_name: "FL_ERB_PLACEHOLDERS",
                                 description: "Placeholders given as a hash",
                                 default_value: {},
                                 is_string: false,
                                 type: Hash
                                )

  ]
end

.descriptionObject



16
17
18
# File 'lib/fastlane/actions/erb.rb', line 16

def self.description
  "Allows to Generate output files based on ERB templates"
end

.detailsObject



20
21
22
# File 'lib/fastlane/actions/erb.rb', line 20

def self.details
  "Renders an ERB template with `placeholders` given as a hash via parameter, if no :destination is set, returns rendered template as string"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/fastlane/actions/erb.rb', line 57

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/fastlane/actions/erb.rb', line 4

def self.run(params)
  template = File.read(params[:template])
  result =   ERB.new(template).result(OpenStruct.new(params[:placeholders]).instance_eval { binding })
  File.open(params[:destination], 'w') { |file| file.write(result) } if params[:destination]
  Helper.log.info "Successfully parsed template: '#{params[:template]}' and rendered output to: #{params[:destination]}" if params[:destination]
  result
end