#マニフェスト\r
@models = {\r
scroll: {\r
+ peta: {\r
+ type: 'binder',\r
+ args: {\r
+ leaf_tree_name: 'owner',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
author: {\r
},\r
},\r
scroll_panel: {\r
+ peta: {\r
+ type: 'leaf',\r
+ },\r
associations: {\r
belongs_to: {\r
panel: {\r
},\r
},\r
comic: {\r
+ peta: {\r
+ type: 'binder',\r
+ args: {\r
+ leaf_tree_name: 'owner',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
author: {\r
},\r
},\r
story: {\r
+ peta: {\r
+ type: 'binder',\r
+ args: {\r
+ leaf_tree_name: 'owner',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
comic: {\r
},\r
},\r
story_sheet: {\r
+ peta: {\r
+ type: 'leaf',\r
+ },\r
associations: {\r
belongs_to: {\r
story: {\r
},\r
},\r
sheet: {\r
+ peta: {\r
+ type: 'root',\r
+ args: {\r
+ element_tree_name: 'owner',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
author: {\r
},\r
},\r
sheet_panel: {\r
+ peta: {\r
+ type: 'element',\r
+ args: {\r
+ element_tree_name: 'owner',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
sheet: {\r
},\r
},\r
panel_picture: {\r
+ peta: {\r
+ type: 'element',\r
+ args: {\r
+ element_tree_name: 'panel',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
panel: {\r
},\r
},\r
speech_balloon: {\r
+ peta: {\r
+ type: 'element',\r
+ args: {\r
+ element_tree_name: 'panel',\r
+ },\r
+ },\r
extend_column_name: 'classname', \r
associations: {\r
belongs_to: {\r
},\r
}, \r
balloon: {\r
+ peta: {\r
+ type: 'element',\r
+ args: {\r
+ element_tree_name: 'panel',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
speech_balloon: {\r
},\r
},\r
speech: {\r
+ peta: {\r
+ type: 'element',\r
+ args: {\r
+ element_tree_name: 'panel',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
speech_balloon: {\r
},\r
},\r
ground_picture: {\r
+ peta: {\r
+ type: 'element',\r
+ args: {\r
+ element_tree_name: 'panel',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
panel: {\r
},\r
},\r
ground_color: {\r
+ peta: {\r
+ type: 'element',\r
+ args: {\r
+ element_tree_name: 'panel',\r
+ },\r
+ },\r
associations: {\r
belongs_to: {\r
panel: {\r
end
def assist_items item_name, list_name
- list = Manifest.manifest.list_groups[item_name].lists[list_name]
+ list = Manifest::View::ListGroup.list item_name, list_name
list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
list_result.items
end
def assist_filer item_name, items
- @filer = Manifest::View::Filer.new @list.item_name, list_result.items, list_result.paginate, @operators
filer_manager = Pettanr::Application::manifest.filer_managers[item_name]
filer_manager.open(item_name, items, @operators, nil)
end
-class Balloon < Peta::Content
+class Balloon < Peta::Element
load_manifest
belongs_to :speech_balloon
belongs_to :system_picture
class GroundColor < Peta::Element
load_manifest
- include ElementInspire
belongs_to :panel
belongs_to :color
class GroundPicture < Peta::Element
load_manifest
- include ElementInspire
belongs_to :panel
belongs_to :picture
#ライセンスグループ
-class LicenseGroup < Peta::Item
+class LicenseGroup < Peta::SystemResource
load_manifest
has_many :licenses
'license_groups.name asc'
end
- def self.enable_list
- LicenseGroup.find(:all).delete_if {|lg|
- lg.enable? == false
- }
- end
-
def self.list_opt
{:include => {:licenses => {}}}
end
res = false
Panel.transaction do
self.panel_elements.each do |elm|
- elm.new_panel = self
elm.boost
end
#self.publish = nil
res
end
- def copy
- attr = self.copy_attributes
- self.class.child_models('panel') do |child_model|
- attr.merge! child_model.panelize(self.element_items(child_model).map {|elm| elm.copy_attributes})
- end
- attr
- end
-
- def copy_attributes
- r = self.attributes
- r.delete 'id'
- r.delete 'author_id'
- r.delete 'created_at'
- r.delete 'updated_at'
- r
- end
-
def self.panelize panel
attr = panel.attributes
attr.delete 'id'
class PanelPicture < Peta::Element
load_manifest
- include ElementInspire
belongs_to :panel
belongs_to :picture
-class Scroll < Peta::Content
+class Scroll < Peta::Binder
load_manifest
has_many :scroll_panels
belongs_to :author
-class ScrollPanel < Peta::Element
+class ScrollPanel < Peta::Leaf
load_manifest
belongs_to :author
belongs_to :panel
-class Sheet < Peta::Content
+class Sheet < Peta::Root
load_manifest
has_many :sheet_panels
has_many :story_sheets
-class Speech < Peta::Content
+class Speech < Peta::Element
load_manifest
belongs_to :speech_balloon
belongs_to :writing_format
class SpeechBalloon < Peta::Element
load_manifest
- include ElementInspire
has_one :balloon, :dependent => :destroy
has_one :speech, :dependent => :destroy
belongs_to :speech_balloon_template
#フキダシテンプレート
-class SpeechBalloonTemplate < Peta::Item
+class SpeechBalloonTemplate < Peta::SystemResource
load_manifest
has_many :speech_balloons
belongs_to :system_picture
self.system_picture.tmb_opt_img_tag
end
- def self.enable_list
- SpeechBalloonTemplate.find(:all).delete_if {|sbt|
- sbt.enable? == false
- }
- end
-
def self.list_opt
{}
end
#ストーリー
-class Story < Peta::Content
+class Story < Peta::Binder
load_manifest
has_many :story_sheets
belongs_to :comic
-class StorySheet < Peta::Element
+class StorySheet < Peta::Leaf
load_manifest
belongs_to :author
belongs_to :story
-class WritingFormat < Peta::Item
+class WritingFormat < Peta::SystemResource
load_manifest
has_many :speeches
belongs_to :system_picture
def self.list
self.enable_list
end
- def self.enable_list
- WritingFormat.find(:all).delete_if {|wf|
- wf.enable? == false
- }
- end
-
def self.list_opt
{}
end
<h2><%= t('panels.show.copy') -%></h2>
<%= form_for(Panel.new, :html => {:jqform => 'pettanr-panel-form'}) do |f| %>
- <%= hidden_field_tag "json", @panel.copy().to_json %>
+ <%= hidden_field_tag "json", @panel.post_attributes(:all).to_json %>
<div>
<%= submit_tag t('panels.show.inspire') -%>
</div>
require File.expand_path('../application', __FILE__)
require 'RMagick'
require 'rest_client'
-require 'inspire'
require 'picture_io'
require 'pettan_imager'
ActiveSupport::Dependencies.autoload_paths << File::join( Rails.root, 'lib')
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Editor'
- ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Manifest'
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Peta'
+ ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Manifest'
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
+++ /dev/null
-module ElementInspire
- def self.included(base)
- base.extend(ClassMethods)
- base.__send__ :include, InstanceMethods
- end
-
- module ClassMethods
- def panelize elements_attributes
- elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array)
- hash = {}
- index = 0
- elements_attributes.each do |element_attributes|
- hash[self.to_s.tableize + '_attributes'] ||= {}
- n = if element_attributes['id']
- element_attributes['id'].to_s
- else
- index += 1
- 'new' + index.to_s
- end
- hash[self.to_s.tableize + '_attributes'][n] = element_attributes
- end
- hash
- end
- end
-
- module InstanceMethods
- private
-
- public
-
- def parts
- @parts ||= []
- end
-
- def copy_attributes
- r = self.attributes
- r.delete 'id'
- r.delete 'panel_id'
- r.delete 'created_at'
- r.delete 'updated_at'
- self.parts.each do |part|
- new_part_attr = part ? part.class.panelize(part.copy_attributes) : {}
- r.merge! new_part_attr
- end
- r
- end
-
- def copy to_panel
- new_element = self.class.new self.copy_attributes
- new_element.t = to_panel.new_t
- new_element.z = to_panel.new_z
- new_attr = new_element.class.panelize new_element.copy_attributes
- r = {} #Panel.panelize to_panel
- r.merge! new_attr
- r
- end
-
- def copy_all index
- new_element = self.class.new self.copy_attributes
- new_attr = new_element.class.panelize(new_element.copy_attributes, index)
- r = {} #Panel.panelize to_panel
- r.merge! new_attr
- r
- end
-
- end
-
-end
-
end
def items operators, options, offset, page_size
- @model.enable_list
+ # enable_list does not work when configured auto load in development.rb
+ # auto loader undefing MODEL at reload manifest file
+ # @model.enable_list
+ super
end
end
end
end
- def add_action
- return
- @controllers.each do |controller_name, controller|
- model_name = controller.model_name
- next if model_name.blank?
- controller.actions.each do |action_name, conf|
- next unless conf['type'] == 'list'
- list_name = conf['list']['list_name']
- list = Pettanr::Application::manifest.list_managers[model_name]
- list.add_action action_name, list_name
- end
- end
- end
-
end
module ModuleMethods
require_dependency "manifest/model/peta/content"
require_dependency "manifest/model/peta/root"
require_dependency "manifest/model/peta/element"
+require_dependency "manifest/model/peta/binder"
+require_dependency "manifest/model/peta/leaf"
module Manifest
module ModelModule
class PetaFactory
include PetaModule
@@types = {
'item' => ItemPeta, 'owner' => OwnerPeta, 'content' => ContentPeta,
- 'root' => RootPeta, 'element' => ElementPeta
+ 'root' => RootPeta, 'element' => ElementPeta,
+ 'binder' => BinderPeta, 'leaf' => LeafPeta
}
def self.factory model, my_manifest
my_manifest['type'] ||= 'item'
--- /dev/null
+module Manifest
+ module ModelModule
+ module PetaModule
+ class BinderPeta < BasePeta
+ attr :leaf_tree_name
+
+ def set_default
+ super
+ raise "undefined leaf_tree_name for models> #{@model.model_name} > peta \n" unless @peta_manifest['args']['leaf_tree_name']
+ end
+
+ def init
+ super
+ @leaf_tree_name = @args['leaf_tree_name']
+ end
+
+ end
+
+ end
+ end
+end
module ModelModule
module PetaModule
class ElementPeta < BasePeta
+ attr :element_tree_name
def set_default
super
+ raise "undefined element_tree_name for models> #{@model.model_name} > peta \n" unless @peta_manifest['args']['element_tree_name']
end
def init
super
+ @element_tree_name = @args['element_tree_name']
end
end
--- /dev/null
+module Manifest
+ module ModelModule
+ module PetaModule
+ class LeafPeta < BasePeta
+
+ def set_default
+ super
+ end
+
+ def init
+ super
+ end
+
+ end
+
+ end
+ end
+end
end
require_dependency 'peta/item'
require_dependency 'peta/owner'
+require_dependency 'peta/system_resource'
require_dependency 'peta/content'
-require_dependency 'peta/element'
-require_dependency 'peta/element_part'
+require_dependency 'peta/element_nestable_content'
require_dependency 'peta/root'
+require_dependency 'peta/element'
+require_dependency 'peta/binder'
+require_dependency 'peta/leaf'
require_dependency 'peta/editize'
--- /dev/null
+module Peta
+ class Binder < Content
+ self.abstract_class = true
+
+ # Dynamic Methods
+
+ def self._leaf_tree_name
+ self.my_manifest.peta.leaf_tree_name
+ end
+
+ def self.load_manifest
+ super
+ # Class Methods
+ n = self._leaf_tree_name
+ define_singleton_method("leaf_tree_name") do
+ n
+ end
+ # Instance Methods
+ define_method("leaf_items") do |leaf_model|
+ self.__send__ self.class.my_manifest.associations.child_element_name(leaf_model)
+ end
+ define_method("leafs_items") do
+ self.class.child_models(self.class.leaf_tree_name).map {|child_model|
+ self.leaf_items child_model
+ }.flatten
+ end
+ end
+
+ # Class Methods
+
+ end
+end
+
super.merge!({'id' => self.dom_item_id(name)})
end
+ def post_attribute_key
+ if self.new_record?
+ self.dom_pool_type
+ else
+ super
+ end
+ end
+
end
end
module Peta
- class Element < Content
+ class Element < ElementNestableContent
self.abstract_class = true
# Dynamic ClassMethods
{}
end
+ def self.panelize elements_attributes
+ elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array)
+ hash = {}
+ index = 0
+ elements_attributes.each do |element_attributes|
+ hash[self.to_s.tableize + '_attributes'] ||= {}
+ n = if element_attributes['id']
+ element_attributes['id'].to_s
+ else
+ index += 1
+ 'new' + index.to_s
+ end
+ hash[self.to_s.tableize + '_attributes'][n] = element_attributes
+ end
+ hash
+ end
+
def has_picture?
false
end
})
end
+ def copy_attributes opt = {}
+ r = self.attributes
+ r.delete 'id'
+ r.delete 'panel_id'
+ r.delete 't' unless opt[:all]
+ r.delete 'z' unless opt[:all]
+ r.delete 'created_at'
+ r.delete 'updated_at'
+ r
+ end
+
end
end
--- /dev/null
+module Peta
+ class ElementNestableContent < Content
+ self.abstract_class = true
+
+ # Dynamic Methods
+
+ def self._element_tree_name
+ self.my_manifest.peta.element_tree_name
+ end
+
+ def self.load_manifest
+ super
+ # Class Methods
+ n = self._element_tree_name
+ define_singleton_method("element_tree_name") do
+ n
+ end
+ c = self.child_models(self.element_tree_name)
+ define_singleton_method("element_models") do
+ c
+ end
+ # Instance Methods
+ define_method("element_items") do |element_model|
+ self.__send__ self.class.my_manifest.associations.child_element_name(element_model)
+ end
+ define_method("elements_items") do
+ self.class.element_models.map {|element_model|
+ self.element_items element_model
+ }.flatten
+ end
+ end
+
+ # Class Methods
+
+ # Instance Methods
+ def post_attributes opt = {}
+ attr = self.copy_attributes
+ hash = {}
+ self.class.element_models.each do |element_model|
+ name = self.class.my_manifest.associations.child_element_name(element_model) + '_attributes'
+ hash[name] ||= {}
+ self.element_items(element_model).each do |element|
+ hash[name][element.post_attribute_key] = element.post_attributes opt
+ end
+ end
+ attr.merge hash
+ end
+
+ end
+end
+
)
end
+ def post_attribute_key
+ self.dom_id
+ end
+
end
end
--- /dev/null
+module Peta
+ class Leaf < Content
+ self.abstract_class = true
+
+ # Dynamic ClassMethods
+
+ def self.play_list_where cid
+ ['scroll_panels.scroll_id = ?', cid]
+ end
+
+ def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
+ ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
+ end
+
+ def self.play_sheet_where sid
+ ['story_sheets.story_id = ?', sid]
+ end
+
+ def self.play_sheet story, operators, page = 1
+ ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
+ if ss
+ if ss.sheet
+ Sheet.show(ss.sheet.id, operators)
+ else
+ nil
+ end
+ else
+ nil
+ end
+ end
+
+ def self.play_paginate story, page
+ Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
+ end
+
+ def self.new_t binder_id
+ r = ScrollPanel.max_t(binder_id)
+ r.blank? ? 0 : r.to_i + 1
+ end
+
+ def self.max_t binder_id
+ self.class..maximum(:t, :conditions => ['scroll_id = ?', binder_id])
+ end
+
+ def self.find_t binder_id, t
+ self.class.find(:first, :conditions => ['scroll_id = ? and t = ?', binder_id, t])
+ end
+
+ def self.collect_t scroll_panel
+ r = self.class.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
+ r.map {|sp| sp.t}
+ end
+
+ def self.top_sheet story, author
+ StorySheet.play_list(story, author).first
+ end
+
+ def self.collect_t story_sheet
+ r = StorySheet.find(:all, :conditions => ['story_id = ?', story_sheet.story_id], :order => 't')
+ r.map {|sp| sp.t}
+ end
+
+ def self.serial? ary
+ i = 0
+ ary.compact.sort.each do |t|
+ break false unless t == i
+ i += 1
+ end
+ ary.compact.size == i
+ end
+
+ def self.validate_t scroll_panel
+ ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
+ end
+
+ def insert_shift
+ ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
+ end
+
+ def lesser_shift old_t
+ self.t = 0 if self.t < 0
+ ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
+ end
+
+ def higher_shift old_t
+ nf = ScrollPanel.find_t(self.scroll_id, self.t)
+ max_t = ScrollPanel.max_t(self.scroll_id).to_i
+ self.t = max_t if self.t > max_t
+ ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
+ end
+
+ def update_shift old_t
+ if self.t > old_t
+ higher_shift old_t
+ else
+ lesser_shift old_t
+ end
+ end
+
+ def rotate old_t = nil
+ if self.new_record?
+ if self.t.blank?
+ self.t = ScrollPanel.new_t self.scroll_id
+ else
+ self.insert_shift
+ end
+ else
+ if self.t.blank?
+ else
+ self.update_shift old_t
+ end
+ end
+ end
+
+ def allow? operators
+ return nil if self.scroll_id == nil or self.panel_id == nil
+ self.scroll.own?(operators) and self.panel.usable?(operators)
+ end
+
+ def destroy_and_shorten
+ res = false
+ ScrollPanel.transaction do
+ ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ?)', self.scroll_id, self.t])
+ raise ActiveRecord::Rollback unless self.destroy
+ res = true
+ end
+ res
+ end
+
+ end
+end
+
module Peta
- class Root < Content
+ class Root < ElementNestableContent
self.abstract_class = true
# Dynamic Methods
- def self._element_tree_name
- self.my_manifest.peta.element_tree_name
- end
-
def self.load_manifest
super
# Class Methods
- n = self._element_tree_name
- define_singleton_method("element_tree_name") do
- n
- end
# Instance Methods
- define_method("element_items") do |element_model|
- self.__send__ self.class.my_manifest.associations.child_element_name(element_model)
- end
- define_method("elements_items") do
- self.class.child_models(self.class.element_tree_name).map {|child_model|
- self.element_items child_model
- }.flatten
- end
end
# Class Methods
+ # Instance Methods
+ def copy_attributes opt = {}
+ r = self.attributes
+ r.delete 'id'
+ r.delete 'author_id'
+ r.delete 'created_at'
+ r.delete 'updated_at'
+ r
+ end
+
end
end
--- /dev/null
+module Peta
+ class SystemResource < Item
+ self.abstract_class = true
+
+ # Dynamic ClassMethods
+
+ # ClassMethods
+
+ def self.enable_list
+ self.find(:all).delete_if {|sbt|
+ sbt.enable? == false
+ }
+ end
+
+ end
+end
},\r
"models": {\r
"scroll": {\r
+ "peta": {\r
+ "type": "binder",\r
+ "args": {\r
+ "leaf_tree_name": "owner"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"author": {}\r
}\r
},\r
"scroll_panel": {\r
+ "peta": {\r
+ "type": "leaf"\r
+ },\r
"associations": {\r
"belongs_to": {\r
"panel": {},\r
}\r
},\r
"comic": {\r
+ "peta": {\r
+ "type": "binder",\r
+ "args": {\r
+ "leaf_tree_name": "owner"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"author": {}\r
}\r
},\r
"story": {\r
+ "peta": {\r
+ "type": "binder",\r
+ "args": {\r
+ "leaf_tree_name": "owner"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"comic": {}\r
}\r
},\r
"story_sheet": {\r
+ "peta": {\r
+ "type": "leaf"\r
+ },\r
"associations": {\r
"belongs_to": {\r
"story": {},\r
}\r
},\r
"sheet": {\r
+ "peta": {\r
+ "type": "root",\r
+ "args": {\r
+ "element_tree_name": "owner"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"author": {}\r
}\r
},\r
"sheet_panel": {\r
+ "peta": {\r
+ "type": "element",\r
+ "args": {\r
+ "element_tree_name": "owner"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"sheet": {},\r
}\r
},\r
"panel_picture": {\r
+ "peta": {\r
+ "type": "element",\r
+ "args": {\r
+ "element_tree_name": "panel"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"panel": {}\r
}\r
},\r
"speech_balloon": {\r
+ "peta": {\r
+ "type": "element",\r
+ "args": {\r
+ "element_tree_name": "panel"\r
+ }\r
+ },\r
"extend_column_name": "classname",\r
"associations": {\r
"belongs_to": {\r
}\r
},\r
"balloon": {\r
+ "peta": {\r
+ "type": "element",\r
+ "args": {\r
+ "element_tree_name": "panel"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"speech_balloon": {},\r
}\r
},\r
"speech": {\r
+ "peta": {\r
+ "type": "element",\r
+ "args": {\r
+ "element_tree_name": "panel"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"speech_balloon": {},\r
}\r
},\r
"ground_picture": {\r
+ "peta": {\r
+ "type": "element",\r
+ "args": {\r
+ "element_tree_name": "panel"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"panel": {}\r
}\r
},\r
"ground_color": {\r
+ "peta": {\r
+ "type": "element",\r
+ "args": {\r
+ "element_tree_name": "panel"\r
+ }\r
+ },\r
"associations": {\r
"belongs_to": {\r
"panel": {}\r
"belongs_to": [\r
"system_picture"\r
],\r
- "has_many": [\r
- ]\r
+ "has_many": []\r
}\r
},\r
"license_group": {\r