Class: Translatomatic::ResourceFile::Markdown

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

Overview

Markdown resource file

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

#set

Methods inherited from Base

#create_variable, enabled?, #format, #get, #initialize, is_key_value?, #locale_path, #sentences, #set, supports_variable_interpolation?, #to_s, #type, #variable_regex

Constructor Details

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

Class Method Details

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



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

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



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

def save(target = path, options = {})
  if @doc
    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)
  end
end