Module: Neapolitan

Defined in:
lib/neapolitan.rb,
lib/neapolitan/cli.rb,
lib/neapolitan/part.rb,
lib/neapolitan/factory.rb,
lib/neapolitan/version.rb,
lib/neapolitan/template.rb,
lib/neapolitan/rendering.rb

Defined Under Namespace

Classes: Factory, Part, Rendering, Template

Class Method Summary collapse

Class Method Details

.cli(*argv) ⇒ Object

Command line interface.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/neapolitan/cli.rb', line 4

def self.cli(*argv)
  options = {}

  option_parser(options).parse!(argv)

  if src = options[:source]
    data = YAML.load(File.new(src))
  else
    data = {} #@source ||= YAML.load(STDIN.read)
  end

  files = argv

  begin
    files.each do |file|
      template = Template.new(File.new(file))
      if options[:output]
        #template.save(data)
      else
        puts template.render(data)
      end
    end
  rescue => e
    $DEBUG ? raise(e) : puts(e.message)
  end
end

.const_missing(name) ⇒ Object

Access project metadata as constants.



12
13
14
15
# File 'lib/neapolitan/version.rb', line 12

def self.const_missing(name)
  key = name.to_s.downcase
  [key] || super(name)
end

.file(fname, options = {}) ⇒ Object

Specifically create a new template from a file, given the files name.

Examples:

Neapolitan::Template.file('example.np')


71
72
73
# File 'lib/neapolitan.rb', line 71

def self.file(fname, options={})
  Template.new(File.new(fname), options)
end

.load(source, options = {}) ⇒ Object

Load template from given source.

Parameters:

  • source (File, IO, String) —

    The document to render.

  • options (Hash) (defaults to: {}) —

    Rendering options.



50
51
52
# File 'lib/neapolitan.rb', line 50

def self.load(source, options={})
  Template.new(source, options)
end

.metadata ⇒ Object

Access to project metadata.



4
5
6
7
8
9
# File 'lib/neapolitan/version.rb', line 4

def self.
  @metadata ||= (
    require 'yaml'
    YAML.load(File.new(File.dirname(__FILE__) + '/neapolitan.yml'))
  )
end

.option_parser(options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/neapolitan/cli.rb', line 34

def self.option_parser(options)
  require 'optparse'

  OptionParser.new do |opt|
    opt.banner = "neapolitan [file1 file2 ...]"
    #opt.on("--output", "-o [PATH]", "save output to specified directory") do |path|
    #  options[:output] = path
    #end
    opt.on("--source", "-s [FILE]", "data souce (YAML file)") do |file|
      options[:source] = file
    end
    opt.on("--tilt", "use Tilt for rendering instead of Malt") do
      options[:tilt] = true
    end
    opt.on("--trace", "show extra operational information") do
      $TRACE = true
    end
    opt.on("--dryrun", "-n", "don't actually write to disk") do
      $DRYRUN = true
    end
    opt.on("--debug", "run in debug mode") do
      $DEBUG   = true
      $VERBOSE = true
    end
    opt.on_tail("--help", "display this help message") do
      puts opt
      exit
    end
  end

end

.reject(&reject) ⇒ Object

Limit the section formats for all templates via a rejection procedure.



37
38
39
40
# File 'lib/neapolitan.rb', line 37

def self.reject(&reject)
  @reject = reject if reject
  @reject
end

.select(&select) ⇒ Object

Limit the section formats for all templates to the sepecified selection via a selection procedure.



30
31
32
33
# File 'lib/neapolitan.rb', line 30

def self.select(&select)
  @select = select if select
  @select
end

.system(libname = nil) ⇒ Object

Set default rendering system for all templates. This can either be :tilt or :malt, the default.



23
24
25
26
# File 'lib/neapolitan.rb', line 23

def self.system(libname=nil)
  @system = libname if libname
  @system
end

.text(source, options = {}) ⇒ Object

Specifically create a new template from a text string.

Parameters:

  • source (#to_s) —

    The document to render.

  • options (Hash) (defaults to: {}) —

    Rendering options.



62
63
64
# File 'lib/neapolitan.rb', line 62

def self.text(source, options={})
  Template.new(source.to_s, options)
end