module EPUB::Publication::FixedLayout::ItemrefMixin

Constants

PAGE_SPREAD_PREFIX
PAGE_SPREAD_PROPERTY

Public Class Methods

included(base) click to toggle source

@todo Define using Module#prepend after Ruby 2.0 will become popular

# File lib/epub/publication/fixed_layout.rb, line 118
def included(base)
  return if base.instance_methods.include? :page_spread_without_fixed_layout
  base.__send__ :alias_method, :page_spread_without_fixed_layout, :page_spread
  base.__send__ :alias_method, :page_spread_writer_without_fixed_layout, :page_spread=

  prefixed_page_spread_property = "#{PAGE_SPREAD_PREFIX}#{PAGE_SPREAD_PROPERTY}"
  base.__send__ :define_method, :page_spread do
    property = page_spread_without_fixed_layout
    return property if property
    properties.include?(prefixed_page_spread_property) ? PAGE_SPREAD_PROPERTY : nil
  end

  base.__send__ :define_method, :page_spread= do |new_value|
    if new_value == PAGE_SPREAD_PROPERTY
      page_spread_writer_without_fixed_layout nil
      properties << prefixed_page_spread_property
    else
      page_spread_writer_without_fixed_layout new_value
    end
    new_value
  end
end