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
Returns the value of a configuration setting
# File lib/glyph.rb, line 148 def self.[](setting) Glyph::CONFIG.get(setting) end
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
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
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
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
@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
Used to access @@document
# File lib/glyph.rb, line 138 def self.document @@document end
Used to set @@document
# File lib/glyph.rb, line 143 def self.document=(document) @@document = document end
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
Reenables all Glyph
Rake tasks
# File lib/glyph.rb, line 185 def self.enable_all Rake::Task.tasks.each {|t| t.reenable } end
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
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
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
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
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
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
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
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
Loads all Rake tasks
# File lib/glyph.rb, line 131 def self.setup FileList["#{TASKS_DIR}/**/*.rake"].each do |f| load f end end