Permalink
Browse files

cd command

  • Loading branch information...
1 parent bcc9603 commit 8d098f2b6ea5a36cc9adf31cfd2f55f89b934f91 @txus committed Apr 17, 2012
Showing with 12 additions and 9 deletions.
  1. +7 −3 lib/mayl/commands/cd.rb
  2. +2 −5 lib/mayl/env.rb
  3. +3 −1 lib/mayl/repl.rb
View
@@ -1,10 +1,10 @@
module Mayl
module Commands
- # Public: The Cd command enters in a YAML namespace.
+ # Public: The Cd command navigates through YAML namespaces.
#
# Example
#
- # command = Edit.new(env, 'es', 'Artículo')
+ # command = Cd.new(env, 'models.bla')
# command.execute
#
class Cd
@@ -29,7 +29,11 @@ def execute
when "."
@env.namespace = ""
else
- @env.namespace << '.' << @path
+ if @env.namespace.empty?
+ @env.namespace = @path
+ else
+ @env.namespace += '.' << @path
+ end
end
nil
end
View
@@ -4,21 +4,18 @@ module Mayl
class Env
attr_reader :locales
attr_accessor :last_value
+ attr_accessor :namespace
# Public: Initializes a new Env loading the locales from a path.
def initialize(path)
@locales = Loader.load(path)
@last_value = nil
+ @namespace = ""
end
# Public: Saves any changes to disk.
def commit
@locales.each(&:commit)
end
-
- # Public: The current namespace. For now it's just an empty slime.
- def namespace
- ""
- end
end
end
View
@@ -18,12 +18,14 @@ def initialize(path)
# Returns nothing.
def start
locales = @env.locales.map(&:name)
+ prompt = "> "
puts "Detected locales: #{locales.join(', ')}"
- while (print "> "; input = gets)
+ while (print prompt; input = gets)
begin
value = @parser.parse(input.chomp).execute
@env.last_value = value
@env.commit
+ prompt = [@env.namespace, '> '].reject(&:empty?).join ' '
rescue => e
print "Error: #{e.message}"
ensure

0 comments on commit 8d098f2

Please sign in to comment.