Class: Translatomatic::ResourceFile::Markdown

Inherits:
HTML
  • Object
show all
Defined in:
lib/translatomatic/resource_file/markdown.rb

Instance Attribute Summary

Attributes inherited from Base

#locale, #path, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HTML

#locale_path

Methods inherited from XML

#initialize, #set

Methods inherited from Base

#format, #get, #initialize, #locale_path, #sentences, #set, #to_s, #valid?

Methods included from Util

#locale, #log, #string

Constructor Details

This class inherits a constructor from Translatomatic::ResourceFile::XML

Class Method Details

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



8
9
10
# File 'lib/translatomatic/resource_file/markdown.rb', line 8

def self.extensions
  %w{md}
end

Instance Method Details

#save(target = path, options = {}) ⇒ void

This method returns an undefined value.

Save the resource file.

Parameters:

  • target (Pathname) (defaults to: path)

    The destination path

  • options (Hash<Symbol, Object>) (defaults to: {})

    Output format options



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/translatomatic/resource_file/markdown.rb', line 13

def save(target = path, options = {})
  if @doc
    begin
      add_created_by unless options[:no_created_by]
      html = @doc.to_html
      # convert html back to markdown
      markdown = ReverseMarkdown.convert(html, unknown_tags: :bypass)
      target.write(markdown.chomp)
    rescue Exception => e
      puts "error: #{e.message}"
    end
  end
end