Class: Skr::Print::Template::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/skr/print/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Definition

Returns a new instance of Definition.



6
7
8
# File 'lib/skr/print/template.rb', line 6

def initialize(path)
    @path = path
end

Instance Method Details

#choicesObject



12
13
14
15
16
# File 'lib/skr/print/template.rb', line 12

def choices
    Pathname.glob(@path.join('*.tex.erb')).map{|pn|
        pn.basename('.tex.erb').to_s
    }
end

#modelObject



17
18
19
# File 'lib/skr/print/template.rb', line 17

def model
    "skr/#{name}".underscore.classify.constantize
end

#nameObject



9
10
11
# File 'lib/skr/print/template.rb', line 9

def name
    @path.basename.to_s
end

#path_for_record(record) ⇒ Object



20
21
22
23
24
# File 'lib/skr/print/template.rb', line 20

def path_for_record(record)
    form = record.respond_to?(:form) ? record.form : 'default'
    path = @path.join( form + '.tex.erb' )
    path.exist? ? path : @path.join( 'default.tex.erb' )
end