Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Achieved 100% documentation coverage.
  • Loading branch information
h3rald committed Aug 28, 2011
1 parent 93ae0f8 commit 4694cb2
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ thumbs.db
.bundle
spec/config.yml
*.gem
doc
Gemfile.lock
book/output
book/output/*
11 changes: 10 additions & 1 deletion lib/glyph.rb
Expand Up @@ -40,8 +40,13 @@ module Glyph
require LIB/'reporter'
extend Glyph::Utils

# A generic Glyph error.
class Error < RuntimeError; end

# A syntax error.
class SyntaxError < Error; end

# A macro error.
class MacroError < Error
include Glyph::Utils
attr_reader :macro
Expand All @@ -62,6 +67,8 @@ def display
msg "#{"-"*54}\n#{@macro.node.to_s.gsub(/\t/, ' ')}\n#{"-"*54}" if Glyph.debug?
end
end

# An infinite recursion error
class MutualInclusionError < MacroError; end

# The current version of Glyph
Expand Down Expand Up @@ -110,10 +117,13 @@ class MutualInclusionError < MacroError; end
CONFIG = Glyph::Config.new :resettable => true, :mutable => false

home_dir = Pathname.new(RUBY_PLATFORM.match(/win32|mingw/) ? ENV['HOMEPATH'] : ENV['HOME'])
# System configuration
SYSTEM_CONFIG =
Glyph::Config.new(:file => HOME/'config.yml')
# Global configuration
GLOBAL_CONFIG =
Glyph.test? ? Glyph::Config.new(:file => SPEC_DIR/'.glyphrc') : Glyph::Config.new(:file => home_dir/'.glyphrc')
# Project configuration
PROJECT_CONFIG =
Glyph::Config.new(:file => PROJECT/'config.yml', :resettable => true) rescue Glyph::Config.new(:resettable => true, :mutable => true)

Expand Down Expand Up @@ -306,7 +316,6 @@ def self.filter(text)
result
end


end

Glyph.setup
2 changes: 1 addition & 1 deletion lib/glyph/bookmark.rb
Expand Up @@ -33,7 +33,7 @@ def code

# Returns true if the two bookmarks have the same ID and file
# @param [Glyph::Bookmark] b the bookmark to compare
# @raises [RuntimeError] if the parameter supplied is not a bookmark
# @raise [RuntimeError] if the parameter supplied is not a bookmark
def ==(b)
raise RuntimeError, "#{b.inspect} is not a bookmark" unless b.is_a? Glyph::Bookmark
self.code == b.code && self.file == b.file
Expand Down
9 changes: 6 additions & 3 deletions lib/glyph/document.rb
Expand Up @@ -9,6 +9,7 @@ module Glyph
# as well as replacing placeholders.
class Document

# A Regexp containing the characters to escape
ESCAPES = /\\([\\\]\[\|\/=])/

attr_reader :bookmarks, :placeholders, :headers, :styles, :context
Expand Down Expand Up @@ -80,7 +81,8 @@ def bookmark?(key)
end

# Stores a new bookmark
# @param [Hash] hash the bookmark hash: {:id => "BookmarkID", :title => "Bookmark Title", :file => "dir/preface.glyph"}
# @param [Hash] hash the bookmark hash
# @example {:id => "BookmarkID", :title => "Bookmark Title", :file => "dir/preface.glyph"}
# @return [Glyph::Bookmark] the stored bookmark
# @raise [RuntimeError] if the bookmark is already defined.
def bookmark(hash)
Expand All @@ -91,7 +93,8 @@ def bookmark(hash)
end

# Stores a new header
# @param [Hash] hash the header hash: {:id => "Bookmark_ID", :title => "Bookmark Title", :level => 3}
# @param [Hash] hash the header hash
# @example {:id => "Bookmark_ID", :title => "Bookmark Title", :level => 3}
# @return [Glyph::Header] the stored header
# @raise [RuntimeError] if the bookmark is already defined.
def header(hash)
Expand Down Expand Up @@ -129,7 +132,7 @@ def snippet?(key)
# @since 0.4.0
# Stores a stylesheet
# @param [String] file the stylesheet file
# @raises [RuntimeError] if the stylesheet is already specified for the document (unless the output has more than one file)
# @raise [RuntimeError] if the stylesheet is already specified for the document (unless the output has more than one file)
def style(file)
f = Pathname.new file
if @styles.include?(f) && !Glyph.multiple_output_files? then
Expand Down
1 change: 1 addition & 0 deletions lib/glyph/macro.rb
Expand Up @@ -212,6 +212,7 @@ def interpret(string)
@node[:escape] ? string : inject(string).document.output
end

# @see Glyph::Document#placeholder
def placeholder(&block)
@node[:document].placeholder &block
end
Expand Down
2 changes: 1 addition & 1 deletion lib/glyph/macro_validators.rb
Expand Up @@ -23,7 +23,7 @@ def validate(message, options={:level => :error}, &block)
end

# Ensures that the provided name is a valid XML element name.
# @params [String, Symbol] name the element name to validate
# @param [String, Symbol] name the element name to validate
# @param [Hash] options a hash containing validation options (for now the only option is :level)
# @return [Boolean] whether the validation passed or not
# @since 0.3.0
Expand Down
1 change: 1 addition & 0 deletions lib/glyph/node.rb
@@ -1,5 +1,6 @@
# encoding: utf-8

# Core Hash class.
class Hash

# Converts self to a Node
Expand Down
2 changes: 2 additions & 0 deletions lib/glyph/syntax_node.rb
Expand Up @@ -64,6 +64,8 @@ def to_s
"#{self[:name]}["+e+contents+e+"]"
end

# @return [String] a textual representation of the macro parameters.
# @since 0.3.0
def contents
attributes.join+parameters.join("|")
end
Expand Down
6 changes: 6 additions & 0 deletions lib/glyph/system_extensions.rb
@@ -1,16 +1,22 @@
# Core Symbol class.
class Symbol
# Comparison operator based on the one in the String class.
def <=>(b)
self.to_s <=> b.to_s
end
end

# Core String class.
class String
# Converts the strings to "title case" (capitalizes each word).
def title_case
self.snake_case.split('_').map{|s| s.capitalize}.join(' ')
end
end

# Core Hash class.
class Hash
# Converts the hash to a string of Glyph options.
def to_options(sep=" ")
"".tap do |s|
self.each_pair do |k, v|
Expand Down

0 comments on commit 4694cb2

Please sign in to comment.