Class: Haml::I18n::Extractor
- Inherits:
-
Object
- Object
- Haml::I18n::Extractor
- Defined in:
- lib/haml-i18n-extractor/helpers.rb,
lib/haml-i18n-extractor/version.rb,
lib/haml-i18n-extractor/prompter.rb,
lib/haml-i18n-extractor/workflow.rb,
lib/haml-i18n-extractor/extractor.rb,
lib/haml-i18n-extractor/yaml_tool.rb,
lib/haml-i18n-extractor/haml_reader.rb,
lib/haml-i18n-extractor/haml_writer.rb,
lib/haml-i18n-extractor/text_finder.rb,
lib/haml-i18n-extractor/user_action.rb,
lib/haml-i18n-extractor/tagging_tool.rb,
lib/haml-i18n-extractor/text_replacer.rb
Defined Under Namespace
Modules: Helpers Classes: HamlReader, HamlWriter, InvalidSyntax, NotADirectory, NotDefinedLineType, Prompter, TaggingTool, TextFinder, TextReplacer, UserAction, Workflow, YamlTool
Constant Summary collapse
- VERSION =
"0.0.17"
- LINE_TYPES_ALL =
[:text, :not_text, :loud, :silent, :element]
- LINE_TYPES_ADD_EVAL =
[:text, :element]
- DEFAULT_LINE_LOCALE_HASH =
{ :modified_line => nil,:keyname => nil,:replaced_text => nil, :path => nil }
Instance Attribute Summary collapse
-
#haml_reader ⇒ Object
readonly
Returns the value of attribute haml_reader.
-
#haml_writer ⇒ Object
readonly
Returns the value of attribute haml_writer.
-
#locale_hash ⇒ Object
readonly
Returns the value of attribute locale_hash.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#yaml_tool ⇒ Object
readonly
Returns the value of attribute yaml_tool.
Class Method Summary collapse
Instance Method Summary collapse
- #assign_new_body ⇒ Object
- #assign_replacements ⇒ Object
- #assign_yaml ⇒ Object
-
#initialize(haml_path, opts = {}) ⇒ Extractor
constructor
A new instance of Extractor.
- #new_body ⇒ Object
-
#process_line(orig_line, line_no) ⇒ Object
this is the bulk of it: where we end up setting body info and locale_hash.
- #prompt_per_line? ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize(haml_path, opts = {}) ⇒ Extractor
Returns a new instance of Extractor.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 21 def initialize(haml_path, opts = {}) @type = opts[:type] @prompt_per_line = opts[:prompt_per_line] @prompter = Haml::I18n::Extractor::Prompter.new @haml_reader = Haml::I18n::Extractor::HamlReader.new(haml_path) validate_haml(@haml_reader.body) @haml_writer = Haml::I18n::Extractor::HamlWriter.new(haml_path, {:type => @type}) @yaml_tool = Haml::I18n::Extractor::YamlTool.new @tagging_tool ||= Haml::I18n::Extractor::TaggingTool.new # hold all the processed lines @body = [] # holds a line_no => {info_about_line_replacemnts_or_not} @locale_hash = {} end |
Instance Attribute Details
#haml_reader ⇒ Object (readonly)
Returns the value of attribute haml_reader.
16 17 18 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 16 def haml_reader @haml_reader end |
#haml_writer ⇒ Object (readonly)
Returns the value of attribute haml_writer.
16 17 18 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 16 def haml_writer @haml_writer end |
#locale_hash ⇒ Object (readonly)
Returns the value of attribute locale_hash.
17 18 19 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 17 def locale_hash @locale_hash end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
17 18 19 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 17 def type @type end |
#yaml_tool ⇒ Object (readonly)
Returns the value of attribute yaml_tool.
17 18 19 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 17 def yaml_tool @yaml_tool end |
Class Method Details
.debug? ⇒ Boolean
5 6 7 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 5 def self.debug? ENV['DEBUG'] end |
Instance Method Details
#assign_new_body ⇒ Object
43 44 45 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 43 def assign_new_body @haml_writer.body = new_body end |
#assign_replacements ⇒ Object
51 52 53 54 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 51 def assign_replacements assign_new_body assign_yaml end |
#assign_yaml ⇒ Object
47 48 49 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 47 def assign_yaml @yaml_tool.locale_hash = @locale_hash end |
#new_body ⇒ Object
56 57 58 59 60 61 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 56 def new_body @haml_reader.lines.each_with_index do |orig_line, line_no| process_line(orig_line,line_no) end @body.join("\n") end |
#process_line(orig_line, line_no) ⇒ Object
this is the bulk of it: where we end up setting body info and locale_hash. not write, just set that info in memory in correspoding locations. refactor more?
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 67 def process_line(orig_line, line_no) orig_line.chomp! orig_line, whitespace = handle_line_whitespace(orig_line) line_type, line_match = handle_line_finding(orig_line) should_be_replaced, text_to_replace, line_locale_hash = handle_line_replacing(orig_line, line_match, line_type, line_no) user_action = Haml::I18n::Extractor::UserAction.new('y') # default if no prompting: just do it. if should_be_replaced if prompt_per_line? user_action = @prompter.ask_user(orig_line,text_to_replace) end end if user_action.tag? @tagging_tool.write(line_locale_hash[:path], line_no) add_to_body("#{whitespace}#{orig_line}") elsif user_action.replace_line? append_to_locale_hash(line_no, line_locale_hash) add_to_body("#{whitespace}#{text_to_replace}") elsif user_action.no_replace? append_to_locale_hash(line_no, DEFAULT_LINE_LOCALE_HASH) add_to_body("#{whitespace}#{orig_line}") end return should_be_replaced end |
#prompt_per_line? ⇒ Boolean
94 95 96 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 94 def prompt_per_line? !!@prompt_per_line end |
#run ⇒ Object
36 37 38 39 40 41 |
# File 'lib/haml-i18n-extractor/extractor.rb', line 36 def run assign_replacements validate_haml(@haml_writer.body) @haml_writer.write_file @yaml_tool.write_file end |