module Glyph

Glyph is a Rapid Document Authoring Framework able to produce structured documents effortlessly.

Constants

ALIASES

All macro aliases

CONFIG

Glyph's configuration

GLOBAL_CONFIG

Global configuration

HOME

The directory containing the full Glyph installation

LIB

The directory containing Glyph library files

MACROS

All the currently-loaded macros

MODE
PROJECT

The directory of the current Glyph project.

PROJECT_CONFIG

Project configuration

REPS

All the currently-loaded macro representations

SPEC_DIR

The directory containing all Glyph tests

SYSTEM_CONFIG

System configuration

TASKS_DIR

The directory containing all Glyph Rake tasks

VERSION

The current version of Glyph

Public Class Methods

[](setting) click to toggle source

Returns the value of a configuration setting

# File lib/glyph.rb, line 148
def self.[](setting)
        Glyph::CONFIG.get(setting)
end
[]=(setting, value) click to toggle source

Overrides a configuration setting @param [String, Symbol] setting the configuration setting to change @param value the new value

# File lib/glyph.rb, line 155
def self.[]=(setting, value)
        PROJECT_CONFIG.set setting, value
        self.config_refresh
end
compile(src, out=nil) click to toggle source

Compiles a single Glyph file @param [String] src the full or relative path to the source file @param [String] out the full or relative path to the output file

# File lib/glyph.rb, line 274
def self.compile(src, out=nil)
        pwd = Dir.pwd
        Dir.chdir Pathname.new(src).parent.to_s
        begin
                require 'glyph/commands'
                self['system.quiet'] = true
                self.library_mode = true
                TOPLEVEL_BINDING.eval('self').run ["compile", src.to_s, out].compact 
        rescue Exception => e
                raise 
        ensure
                Dir.chdir pwd
                self.library_mode = false
                self.lite_mode = false
                self['system.quiet'] = false
        end
end
config_refresh() click to toggle source

Restores Glyph configuration (keeping all overrides and project settings)

# File lib/glyph.rb, line 161
def self.config_refresh
        CONFIG.merge!(SYSTEM_CONFIG.merge(GLOBAL_CONFIG.merge(PROJECT_CONFIG)))
        Glyph.safe_mode = Glyph['options.safe_mode']
end
config_reset() click to toggle source

Resets Glyph configuration (removing all overrides and project settings)

# File lib/glyph.rb, line 167
def self.config_reset
        Glyph::CONFIG.reset
        Glyph::PROJECT_CONFIG.reset
        self.config_refresh
end
define(name, text) click to toggle source

@since 0.5.0

Defines a new macro in Glyph code.
@param [Symbol, String] name the name of the macro
@param [String] text the Glyph code used to define the macro
# File lib/glyph.rb, line 243
def self.define(name, text)
        macro name do
                body = text.dup
                # Parameters
                body.gsub!(/\{\{(\d+)\}\}/) do
                        raw_param($1.to_i).to_s.strip
                end
                # Attributes
                body.gsub!(/\{\{([^\[\]\|\\\s]+)\}\}/) do
                        raw_attr($1.to_sym).to_s.strip
                end
                interpret body
        end
end
document() click to toggle source

Used to access @@document

# File lib/glyph.rb, line 138
def self.document
        @@document
end
document=(document) click to toggle source

Used to set @@document

# File lib/glyph.rb, line 143
def self.document=(document)
        @@document = document
end
enable(task) click to toggle source

Reenables a Rake task @param [Symbol, String] task the task to enable

# File lib/glyph.rb, line 191
def self.enable(task)
        Rake::Task[task].reenable
end
enable_all() click to toggle source

Reenables all Glyph Rake tasks

# File lib/glyph.rb, line 185
def self.enable_all
        Rake::Task.tasks.each {|t| t.reenable }
end
filter(text) click to toggle source

Converts a text containing Glyph markup language into the current Glyph output target.

Note Only 'html' is supported as output target for now. @param [String] text the text to convert @return [String] the converted text @example

require 'glyph'
Glyph.filter "section[header[Test]\nA Test section...]"
# File lib/glyph.rb, line 300
def self.filter(text)
        self.lite_mode = true
        self.enable_all
        result = ""
        begin
                self['system.quiet'] = true
                self.library_mode = true
                self.run 'load:all'
                result = Interpreter.new(text).document.output
        rescue Exception => e
                raise 
        ensure
                self.lite_mode = false
                self.library_mode = false
                self['system.quiet'] = false
        end
        result
end
macro(name, &block) click to toggle source

Defines a new macro @param [Symbol, String] name the name of the macro

# File lib/glyph.rb, line 212
def self.macro(name, &block)
        MACROS[name.to_sym] = block
end
macro_alias(pair) click to toggle source

Defines an alias for an existing macro @param [Hash] text the single-key hash defining the alias @example

{:old_name => :new_name}
# File lib/glyph.rb, line 262
def self.macro_alias(pair)
        name = pair.keys[0].to_sym
        orig = pair.values[0].to_sym
        ALIASES[:by_def][orig] = [] unless ALIASES[:by_def][orig]
        ALIASES[:by_def][orig] << name unless ALIASES[:by_def][orig].include? name
        ALIASES[:by_alias][name] = orig 
        MACROS[name] = MACROS[orig]
end
project_reps_for(output) click to toggle source

Loads project macro representations for a given output @since 0.5.0 @param [Symbol, String] output a valid output format

# File lib/glyph.rb, line 235
def self.project_reps_for(output)
        Glyph.instance_eval file_load(Glyph::PROJECT/"lib/macros/reps/#{output}.rb") rescue nil
end
rep(name, &block) click to toggle source

Defines a new macro representation @since 0.5.0 @param [Symbol, String] name the name of the macro

# File lib/glyph.rb, line 219
def self.rep(name, &block)
        REPS[name.to_sym] = block
        # Mirror aliases as well
        ALIASES[:by_def][name.to_sym].to_a.each { |a| REPS[a] = block }
end
reps_for(output) click to toggle source

Loads macro representations for a given output @since 0.5.0 @param [Symbol, String] output a valid output format

# File lib/glyph.rb, line 228
def self.reps_for(output)
        Glyph.instance_eval file_load(Glyph::HOME/"macros/reps/#{output}.rb") rescue nil
end
reset() click to toggle source

Resets Glyph completely, i.e.:

  • Re-enables all Glyph Rake tasks

  • Resets the configuration to system defaults

  • Clears macros and snippets

# File lib/glyph.rb, line 177
def self.reset
        self.enable_all
        self.config_reset
        MACROS.clear
        REPS.clear
end
run(task, *args) click to toggle source

Runs a Rake task @param [Symbol, String] task the task to run @param *args the task arguments

# File lib/glyph.rb, line 206
def self.run(task, *args)
        Rake::Task[task].invoke *args
end
run!(task, *args) click to toggle source

Reenables and runs a Rake task @param [Symbol, String] task the task to run @param *args the task arguments

# File lib/glyph.rb, line 198
def self.run!(task, *args)
        Rake::Task[task].reenable
        self.run task, *args
end
setup() click to toggle source

Loads all Rake tasks

# File lib/glyph.rb, line 131
def self.setup
        FileList["#{TASKS_DIR}/**/*.rake"].each do |f|
                load f
        end   
end