Sha256: a94171a93b6c6f67e840e4641f0f7e87d563d28453b276af002fa833dd866f88

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

module Skr
    module Print
        class Template

            class Definition
                def initialize(path)
                    @path = path
                end
                def name
                    @path.basename.to_s
                end
                def choices
                    Pathname.glob(@path.join('*.tex.erb')).map{|pn|
                        pn.basename('.tex.erb').to_s
                    }
                end
                def model
                    "skr/#{name}".underscore.classify.constantize
                end
                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
            end

            def self.get(type)
                Definition.new( Skr::Print::ROOT.join('types', type ) )
            end

            def self.definitions
                Pathname.glob(Skr::Print::ROOT.join('types','*')).select { | type |
                    type.directory?
                }.map { | type |
                    Definition.new( type )
                }
            end

            def self.as_json
                json={}
                definitions.each do | definition |
                    json[definition.name] = definition.choices
                end
                json
            end
        end
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stockor-0.5.0 lib/skr/print/template.rb
stockor-0.4.0 lib/skr/print/template.rb
stockor-0.3.0 lib/skr/print/template.rb
stockor-0.2 lib/skr/print/template.rb