Sha256: 16b746c601ebb86afab23143534b728bf36da494a9ab4788d2d7c2466db305a7

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

module CSL
  
  class Style < Node
    types << CSL::Info << CSL::Locale
    
    @default = :apa

    @root = File.expand_path('../../../vendor/styles', __FILE__).freeze
        
    @extension = '.csl'.freeze
    @prefix = ''
    
    class << self
      include Loader
      
      attr_accessor :default

      def parse(data)
        node = CSL.parse!(data, self)
        
        raise ParseError, "root node is not a style: #{node.inspect}" unless
          node.is_a?(self)
        
        node
      end      
    end
    
    attr_defaults :version => Schema.version, :xmlns => Schema.namespace
    
    attr_struct :xmlns, :version, :class, :'default-locale',
      :'initialize-with-hyphen', :'page-range-format',
      :'demote-non-dropping-particle', *Schema.attr(:name, :names)
    
    attr_children :'style-options', :info, :locale, :macro,
      :citation, :bibliography
    
    alias options  style_options
    alias locales  locale
    
    def_delegators :info, :self_link, :self_link=, :has_self_link?,
      :template_link, :template_link=, :has_template_link?,
      :documentation_link, :documentation_link=, :has_documentation_link?,
			:title=, :id=
      
    def initialize(attributes = {})
      super(attributes, &nil)      
      children[:locale], children[:macro] = [], []
      
      yield self if block_given?
    end

    def validate
      Schema.validate self
    end
    
    def valid?
      validate.empty?
    end
    
    def info
      children[:info] ||= Info.new
    end
    
    alias_child :metadata, :info
    
    # @return [String] the style's id
		def id
			return nil unless info.has_id?
			info.id.to_s
		end
    
    # @return [String] the style's title
		def title
			return nil unless info.has_title?
			info.title.to_s
		end
		
		# @return [Time] timestamp for the time set in info.updated
		def updated_at
			return nil unless info.has_updated?
			Time.parse(info.updated)
		end

    private
    
    def preamble
      Schema.preamble.dup
    end 
  end
 
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csl-1.0.0.pre3 lib/csl/style.rb