Sha256: e0cdeccb726c23f6c3381f3c519bee3d6df7e4d945548f9a227b3b039f6a0ec7

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

module I18n::Tasks
  class ConsoleContext < BaseTask
    def banner
      puts Messages.banner
    end

    def guide
      puts Messages.guide
    end

    class << self
      def start
        require 'irb'
        IRB.setup nil
        ctx = IRB::Irb.new.context
        IRB.conf[:MAIN_CONTEXT] = ctx
        STDERR.puts Messages.banner
        require 'irb/ext/multi-irb'
        IRB.irb nil, new
      end
    end

    module Messages
      include Term::ANSIColor
      extend self

      def banner
        bold("i18n-tasks v#{I18n::Tasks::VERSION} IRB") + "\nType #{green 'guide'} to learn more"
      end

      def guide
        green(bold "i18n-tasks IRB Quick Start guide") + "\n" + <<-TEXT
#{yellow 'Data as trees'}
  data[base_locale]
  missing_tree(locale, compared_to = base_locale)
  used_tree(source_locations: false, key_filter: nil)
  unused_tree(locale)
  Tree::Siblings['es' => {'hello' => 'Hola'}]

#{yellow 'Traversal'}
  tree = missing_tree(base_locale)
  tree.nodes { |node| }
  tree.nodes.to_a
  tree.leaves { |node| }
  tree.each { |root_node| }
  # also levels, depth_first, and breadth_first

#{yellow 'Select nodes'}
  tree.select_nodes { |node| } # new tree with only selected nodes

#{yellow 'Match by full key'}
  tree.select_keys { |key, leaf| } # new tree with only selected keys
  tree.grep_keys(/hello/)          # grep, using ===
  tree.keys { |key, leaf| }        # enumerate over [full_key, leaf_node]
  # Pass {root: true} to include root node in full_key (usually locale)

#{yellow 'Nodes'}
  node = missing_tree(base_locale).leaves.first
  node.key      # only the part after the last dot
  node.full_key # full key. Includes root key, pass {root: false} to override.
  # also: value, value_or_children_hash, data, walk_to_root, walk_from_root
  Tree::Node.new(key: 'en')

#{yellow 'Keys'}
  t(key, locale)
  key_value?(key, locale)
  depluralize_key(key, locale) # convert 'hat.one' to 'hat'
  absolutize_key(key, path)    # '.title' to 'users.index.title'
        TEXT
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i18n-tasks-0.5.0 lib/i18n/tasks/console_context.rb