Sha256: 64392b1adb1cc98fd2e4c0ac58c997fd4b4a4d248002fdf07146d0cf940b4a8d

Contents?: true

Size: 1.92 KB

Versions: 17

Compression:

Stored size: 1.92 KB

Contents

module CiteProc
  module Ruby
    class Renderer

      def citation_mode?
        state.mode == 'citation'
      end

      def bibliography_mode?
        state.mode == 'bibliography'
      end

      def sort_mode?
        state.mode == 'key'
      end

      def substitution_mode?
        !state.substitute.nil?
      end

      def style
        return unless state.node && !state.node.root? &&
          state.node.root.is_a?(CSL::Style)

        state.node.root
      end

      class State
        include Observable

        attr_reader :history, :node, :item, :authors, :substitute

        def initialize
          @history, @authors = History.new(self, 3), []
        end

        def store!(item, node)
          @item, @node = item, node
        ensure
          changed
        end

        def store_authors!(authors)
          @authors << authors
        ensure
          changed
        end

        def clear!(result = nil)
          memories = conserve(result)
          reset
        ensure
          notify_observers :clear!, memories.delete(:mode), memories
        end

        def reset
          @item, @node, @substitute, @authors, @names = nil, nil, nil, [], nil
          self
        ensure
          changed
        end

        def mode
          node && node.nodename
        end

        def substitute!(names)
          @substitute = names
        end

        def clear_substitute!(backup = nil)
          @substitute = backup
        end

        def previous_authors
          past = history.recall(mode)
          return unless past && !past.empty?

          past[:authors]
        end

        def rendered_names?
          @names
        end

        def rendered_names!
          @names = true
        end

        def conserve(result = nil)
          {
            :mode => mode,
            :item => item,
            :authors => authors,
            :result => result
          }
        end
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
citeproc-ruby-1.1.13 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.12 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.11 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.10 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.8 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.7 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.6 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.5 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.4 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.3 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.2 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.1 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.1.0 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.0.6 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.0.5 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.0.4 lib/citeproc/ruby/renderer/state.rb
citeproc-ruby-1.0.3 lib/citeproc/ruby/renderer/state.rb