OSDN Git Service

e
authoryasushiito <yas@pen-chan.jp>
Wed, 5 Mar 2014 08:45:28 +0000 (17:45 +0900)
committeryasushiito <yas@pen-chan.jp>
Wed, 5 Mar 2014 08:45:28 +0000 (17:45 +0900)
47 files changed:
app/controllers/scrolls_controller.rb
app/controllers/sheets_controller.rb
app/controllers/stories_controller.rb
app/models/artist.rb
app/models/author.rb
app/models/balloon.rb
app/models/comic.rb
app/models/ground_color.rb
app/models/ground_picture.rb
app/models/license.rb
app/models/license_group.rb
app/models/original_picture.rb
app/models/panel.rb
app/models/panel_picture.rb
app/models/picture.rb
app/models/resource_picture.rb
app/models/scroll.rb
app/models/scroll_panel.rb
app/models/sheet.rb
app/models/sheet_panel.rb
app/models/speech.rb
app/models/speech_balloon.rb
app/models/speech_balloon_template.rb
app/models/story.rb
app/models/story_sheet.rb
app/models/system_picture.rb
app/models/writing_format.rb
app/views/ground_colors/_element.html.erb
app/views/ground_pictures/_element.html.erb
app/views/panel_pictures/_element.html.erb
app/views/panels/_body.html.erb
app/views/speech_balloons/_element.html.erb
config/environment.rb
lib/common.rb
lib/editor/editor.rb
lib/editor/panel_editor.rb
lib/editor/pool.rb [new file with mode: 0644]
lib/manifest/form/field/tag/base.rb
lib/manifest/local/view/form/field.rb
lib/manifest/local/view/form/field/field.rb [deleted file]
lib/manifest/manifest.rb
lib/manifest/model.rb
lib/manifest/model/association.rb
lib/manifest/model/tree.rb
lib/peta/content.rb
lib/peta/element.rb
lib/peta/item.rb

index b9f52d5..8faed6b 100644 (file)
@@ -28,7 +28,7 @@ class ScrollsController < ApplicationController
     format.html {
       @scroll = @item
       if @operators.author
-        @new_panel_items = assist_items('panel', 'private_list')
+        @new_panel_items = assist_items('panel', 'private')
         #@new_panel_filer = assist_filer 'panel', @new_panel_items
       end
     }
index d36dfb7..571a268 100644 (file)
@@ -33,12 +33,12 @@ class SheetsController < ApplicationController
   def show_html_format format
     format.html {
       if @operators.author
-        @new_panel_items = assist_items('panel', 'private_list')
+        @new_panel_items = assist_items('panel', 'private')
         #new_panel_filer = assist_filer 'panel', @new_panel_items
         
-        @new_story_items = assist_items('story', 'private_list')
+        @new_story_items = assist_items('story', 'private')
         #new_story_filer = assist_filer 'story', @new_story_items
-        @fresh_story_items = assist_items('story_sheet', 'private_list').map {|ss| ss.story}
+        @fresh_story_items = assist_items('story_sheet', 'private').map {|ss| ss.story}
         #@fresh_story_filer = assist_filer 'story', @fresh_story_items
       end
     }
index 1058c62..0b8fea2 100644 (file)
@@ -33,7 +33,7 @@ class StoriesController < ApplicationController
   def show_html_format format
     format.html {
       if @operators.author
-        @new_sheet_items = assist_items('sheet', 'private_list')
+        @new_sheet_items = assist_items('sheet', 'private')
         #@new_sheet_filer = assist_filer 'sheet', @new_sheet_items
       end
     }
index 04a6edf..fa455cd 100644 (file)
@@ -1,4 +1,5 @@
 class Artist < Peta::Owner
+  load_manifest
   belongs_to :user
   has_many :original_pictures
   has_many :pictures
@@ -8,10 +9,6 @@ class Artist < Peta::Owner
   validates :user_id, :numericality => true, :existence => {:both => false}
   validates :provider_id, :numericality => {:allow_nil => true}
   
-  def self.valid_encode_columns
-    super + ['name']
-  end
-  
   def self.visible_count_options
     {:conditions => ['artists.author_id is not null']}
   end
index e571bc3..8560076 100644 (file)
@@ -1,4 +1,5 @@
 class Author < Peta::Owner
+  load_manifest
   belongs_to :user
   has_many :scrolls
   has_many :comics
@@ -10,10 +11,6 @@ class Author < Peta::Owner
   validates :working_panel_id, :numericality => {:allow_nil => true}
   validates :user_id, :numericality => true, :existence => {:both => false}
   
-  def self.valid_encode_columns
-    super + ['name']
-  end
-  
   def supply_default
     self.name = 'no name' if self.name.blank?
   end
index ad9bbe4..b36a825 100644 (file)
@@ -1,4 +1,5 @@
 class Balloon < Peta::Content
+  load_manifest
   include Peta::ElementPart
   belongs_to :speech_balloon
   belongs_to :system_picture
@@ -13,14 +14,6 @@ class Balloon < Peta::Content
 #  validates :caption, :presence => true
   validates :settings, :extend_balloon => true
 
-  def owner_model
-    self.speech_balloon.panel
-  end
-  
-  def self.valid_encode_columns
-    super + ['settings']
-  end
-  
   def self.colum_structures
     @@colum_structures ||= {
       :r => {
@@ -83,6 +76,13 @@ self.system_picture_id = 1
     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
   end
   
+  def style
+    {
+      'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
+      'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
+    }
+  end
+  
   def copy_attributes
     r = self.attributes
     r.delete 'id'
index 92f1568..5204201 100644 (file)
@@ -1,5 +1,6 @@
 #コミック
 class Comic < Peta::Content
+  load_manifest
   has_many :stories, :order => 't'
   belongs_to :author
   
@@ -7,10 +8,6 @@ class Comic < Peta::Content
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
   
-  def self.valid_encode_columns
-    super + ['title', 'description']
-  end
-  
   def self.visible_count_options
     {:conditions => 'visible > 0'}
   end
index 85f0dc2..cf78ded 100644 (file)
@@ -1,5 +1,5 @@
-class GroundColor < Peta::Content
-  include Peta::Element
+class GroundColor < Peta::Element
+  load_manifest
   include ElementInspire
   belongs_to :panel
   belongs_to :color
@@ -12,14 +12,6 @@ class GroundColor < Peta::Content
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
-  def self.owner_model
-    Panel
-  end
-  
-  def self.valid_encode_columns
-    super + ['caption']
-  end
-  
   def self.colum_structures
     @@colum_structures ||= {
       :code => {
@@ -108,9 +100,15 @@ class GroundColor < Peta::Content
     end
   end
   
-  def opt_div_style spot = nil, opacity = 20
-    o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
-    "position: absolute; left:#{self.div_x}%; top:#{self.div_y}%; width:#{self.div_width}%; height:#{self.div_height}%; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}"
+  def style spot = nil, opacity = 20
+    r = {
+      'position' => 'absolute', 'z-index' => self.z, 
+      'top' => self.div_y.to_s + '%', 'left' => self.div_x.to_s + '%', 
+      'width' => self.div_width.to_s + '%', 'height' => self.div_height.to_s + '%', 
+      'background-color' => '#' + format("%06x", self.code)
+    }
+    self.merge_opacity(r, opacity) if spot and spot != self
+    r
   end
   
   def boost
index f356aa2..779848d 100644 (file)
@@ -1,5 +1,5 @@
-class GroundPicture < Peta::Content
-  include Peta::Element
+class GroundPicture < Peta::Element
+  load_manifest
   include ElementInspire
   belongs_to :panel
   belongs_to :picture
@@ -14,14 +14,6 @@ class GroundPicture < Peta::Content
   
   @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
   
-  def self.owner_model
-    Panel
-  end
-  
-  def self.valid_encode_columns
-    super + ['caption']
-  end
-  
   def self.list_opt_for_panel
     {
       :ground_pictures => {
@@ -67,9 +59,15 @@ class GroundPicture < Peta::Content
     self.owner_model.visible? operators
   end
   
-  def opt_div_style full_url, spot = nil, opacity = 20
-    o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
-    "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; top: 0px; left: 0px;  z-index:#{self.z}; background-image: url(#{full_url}); background-repeat: #{self.repeat_text}; background-position: #{self.x}px #{self.y}px; #{o}"
+  def style spot = nil, opacity = 20
+    r = {
+      'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z, 
+      'background-image' => "url(#{self.picture.url})", 
+      'background-repeat' => self.repeat_text, 
+      'background-position' => "#{self.x}px #{self.y}px"
+    }
+    self.merge_opacity(r, opacity) if spot and spot != self
+    r
   end
   
   def tmb_opt_img_tag
index fc264af..e06e621 100644 (file)
@@ -1,5 +1,6 @@
 #
 class License < Peta::Item
+  load_manifest
   belongs_to :license_group
   belongs_to :system_picture
   has_many :resource_pictures
@@ -10,10 +11,6 @@ class License < Peta::Item
   validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => {:message => I18n.t('errors.messages.url')} #{:allow_blank => true}
   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   
-  def self.valid_encode_columns
-    super + ['name', 'caption', 'url', 'settings', 'credit_pictures']
-  end
-  
   def supply_default
   end
   
index 34c66ab..638cb36 100644 (file)
@@ -1,5 +1,6 @@
 #ライセンスグループ
 class LicenseGroup < Peta::Item
+  load_manifest
   has_many :licenses
   
   validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
@@ -7,10 +8,6 @@ class LicenseGroup < Peta::Item
   validates :caption, :presence => true, :length => {:maximum => 30}
   validates :url, :presence => true, :length => {:maximum => 200}, :url => {:message => I18n.t('errors.messages.url')}
   
-  def self.valid_encode_columns
-    super + ['name', 'classname', 'caption', 'url']
-  end
-  
   def supply_default
   end
   
index 3215627..020bc56 100644 (file)
@@ -1,4 +1,5 @@
 class OriginalPicture < Peta::Content
+  load_manifest
   belongs_to :artist
   belongs_to :original_picture_license_group
   has_one :resource_picture
@@ -11,10 +12,6 @@ class OriginalPicture < Peta::Content
   validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
   
-  def self.owner_type
-    :artist
-  end
-  
   def supply_default
   end
   
index 28029ed..1c81e69 100644 (file)
@@ -1,5 +1,6 @@
 #コマ
 class Panel < Peta::Content
+  load_manifest
   belongs_to :author
   has_many :scroll_panels
   has_many :sheet_panels
@@ -67,6 +68,13 @@ class Panel < Peta::Content
     self.publish > 0
   end
   
+  # ground_picture element template 
+  def style_wh
+    {
+      'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px'
+    }
+  end
+  
   def tag_id c = nil
     'panel' + self.tag_panel_id + c.to_s
   end
index 0e05933..4c463d9 100644 (file)
@@ -1,5 +1,5 @@
-class PanelPicture < Peta::Content
-  include Peta::Element
+class PanelPicture < Peta::Element
+  load_manifest
   include ElementInspire
   belongs_to :panel
   belongs_to :picture
@@ -14,14 +14,6 @@ class PanelPicture < Peta::Content
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
-  def self.owner_model
-    Panel
-  end
-  
-  def self.valid_encode_columns
-    super + ['link', 'caption']
-  end
-  
   def self.colum_structures
     @@colum_structures ||= {
       :width => {
@@ -101,10 +93,11 @@ class PanelPicture < Peta::Content
   
   def opt_img_tag spot = nil, opacity = 20
     o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
-    {:id => self.tag_id(:img), :panel_id => self.tag_panel_id, :element_id => self.tag_element_id, :element_type => self.tag_element_type,
-    :class => "panel-picture", :vPicture => self.id, 
-    :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption, 
-    :style => "#{o}"}
+    self.tag_attributes(:img, {
+      :class => "panel-picture", :vPicture => self.id, 
+      :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption, 
+      :style => "#{o}"
+    })
   end
   
   def tmb_opt_img_tag
index 255d932..c408bab 100644 (file)
@@ -1,5 +1,6 @@
 #実素材
 class Picture < Peta::Content
+  load_manifest
   belongs_to :original_picture
   belongs_to :license
   belongs_to :artist
@@ -17,14 +18,6 @@ class Picture < Peta::Content
   validates :artist_name, :presence => true
   validates :classname, :presence => true, :length => {:maximum => 50}
   
-  def self.owner_type
-    :artist
-  end
-  
-  def self.valid_encode_columns
-    super + ['artist_name', 'classname', 'credit', 'settings']
-  end
-  
   def supply_default
   end
   
index fe6812d..bd97c7d 100644 (file)
@@ -1,5 +1,6 @@
 #素材
 class ResourcePicture < Peta::Content
+  load_manifest
   belongs_to :artist
   belongs_to :license
   belongs_to :picture
@@ -17,14 +18,6 @@ class ResourcePicture < Peta::Content
   validates :classname, :presence => true, :length => {:maximum => 50}
   validates :picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   
-  def self.owner_type
-    :artist
-  end
-  
-  def self.valid_encode_columns
-    super + ['artist_name', 'classname', 'credit', 'settings']
-  end
-  
   def supply_default
   end
   
index ab8e658..a569013 100644 (file)
@@ -1,15 +1,11 @@
 class Scroll < Peta::Content
+  load_manifest
   has_many :scroll_panels
   belongs_to :author
   
   validates :title, :presence => true, :length => {:maximum => 100}
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
-
-  def self.valid_encode_columns
-    super + ['title']
-  end
-  
   def supply_default
     self.visible = 0 if self.visible.blank?
   end
@@ -52,11 +48,6 @@ class Scroll < Peta::Content
     {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
   end
   
-  def tag_attributes column = nil, opt = {}
-    {
-    }
-  end
-  
   def self.visible_count
     Scroll.count 'visible > 0'
   end
index 75e658d..356efd0 100644 (file)
@@ -1,4 +1,5 @@
-class ScrollPanel < Peta::Content
+class ScrollPanel < Peta::Element
+  load_manifest
   belongs_to :author
   belongs_to :panel
   belongs_to :scroll
@@ -13,10 +14,6 @@ class ScrollPanel < Peta::Content
     }
   end
   
-  def self.owner_model
-    Scroll
-  end
-  
   def supply_default
     self.scroll_id = nil
     self.panel_id = nil
index 269dd21..ee85e6f 100644 (file)
@@ -1,4 +1,5 @@
 class Sheet < Peta::Content
+  load_manifest
   has_many :sheet_panels
   has_many :story_sheets
   belongs_to :author
@@ -9,10 +10,6 @@ class Sheet < Peta::Content
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
   accepts_nested_attributes_for :sheet_panels, :allow_destroy => true
   
-  def self.valid_encode_columns
-    super + ['caption']
-  end
-  
   def self.each_element_class_names
     {'SheetPanel' => 'sheet_panels'}.each do |k, n|
       yield k
index efcd98f..300980c 100644 (file)
@@ -1,4 +1,5 @@
-class SheetPanel < Peta::Content
+class SheetPanel < Peta::Element
+  load_manifest
   belongs_to :author
   belongs_to :panel
   belongs_to :sheet
@@ -12,10 +13,6 @@ class SheetPanel < Peta::Content
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
-  def self.owner_model
-    Sheet
-  end
-  
   def supply_default
     self.x = 15
     self.y = 15
index c6d0cf8..506671c 100644 (file)
@@ -1,4 +1,5 @@
 class Speech < Peta::Content
+  load_manifest
   include Peta::ElementPart
   belongs_to :speech_balloon
   belongs_to :writing_format
@@ -17,14 +18,6 @@ class Speech < Peta::Content
   
   @@text_align_texts = ['left', 'left', 'right', 'center']
   
-  def owner_model
-    self.speech_balloon.panel
-  end
-  
-  def self.valid_encode_columns
-    super + ['content', 'quotes', 'settings']
-  end
-  
   def self.colum_structures
     @@colum_structures ||= {
       :fore_color => {
@@ -57,6 +50,21 @@ class Speech < Peta::Content
     'speech'
   end
   
+  def outer_style
+    {
+      'top' => self.y, 'left' => self.x, 
+      'width' => self.width, 'height' => self.height
+    }
+  end
+  
+  def inner_style
+    {
+      'font-size' => self.font_size.to_s + 'em',
+      'text-align' => self.text_align_text, 
+      'color' => '#' + format("%06x", self.fore_color)
+    }
+  end
+  
   def text_align_text
     @@text_align_texts[self.text_align]
   end
index 5604235..440d7fa 100644 (file)
@@ -1,5 +1,5 @@
-class SpeechBalloon < Peta::Content
-  include Peta::Element
+class SpeechBalloon < Peta::Element
+  load_manifest
   include ElementInspire
   has_one :balloon, :dependent => :destroy
   has_one :speech, :dependent => :destroy
@@ -16,14 +16,6 @@ class SpeechBalloon < Peta::Content
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   validates :settings, :extend_speech_balloon => true
   
-  def self.owner_model
-    Panel
-  end
-  
-  def self.valid_encode_columns
-    super + ['caption', 'classname', 'settings']
-  end
-  
   def self.list_opt_for_panel
     {
       :speech_balloons => {:balloon => {}, :speech => {}}
index ff799cc..a4ad04a 100644 (file)
@@ -1,5 +1,6 @@
 #フキダシテンプレート
 class SpeechBalloonTemplate < Peta::Item
+  load_manifest
   has_many :speech_balloons
   belongs_to :system_picture
   
@@ -10,10 +11,6 @@ class SpeechBalloonTemplate < Peta::Item
   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :settings, :presence => true
   
-  def self.valid_encode_columns
-    super + ['name', 'classname', 'caption', 'settings']
-  end
-  
   def supply_default
   end
   
index d24edb2..9153230 100644 (file)
@@ -1,5 +1,6 @@
 #ストーリー
 class Story < Peta::Content
+  load_manifest
   has_many :story_sheets
   belongs_to :comic
   
@@ -13,14 +14,6 @@ class Story < Peta::Content
     }
   end
   
-  def self.owner_model
-    Comic
-  end
-  
-  def self.valid_encode_columns
-    super + ['title', 'description']
-  end
-  
   def supply_default
     self.comic_id = nil
     self.visible = 0 if self.visible.blank?
index 47750d5..3650fe5 100644 (file)
@@ -1,4 +1,5 @@
-class StorySheet < Peta::Content
+class StorySheet < Peta::Element
+  load_manifest
   belongs_to :author
   belongs_to :story
   belongs_to :sheet
@@ -13,10 +14,6 @@ class StorySheet < Peta::Content
     }
   end
   
-  def self.owner_model
-    Story
-  end
-  
   def supply_default
     self.story_id = nil
     self.sheet_id = nil
index 19226a5..8a3210d 100644 (file)
@@ -1,4 +1,5 @@
 class SystemPicture < Peta::Item
+  load_manifest
   has_many :balloons
   has_many :speech_balloon_templates
   has_many :licenses
index 97965f6..44fe9f0 100644 (file)
@@ -1,4 +1,5 @@
 class WritingFormat < Peta::Item
+  load_manifest
   has_many :speeches
   belongs_to :system_picture
   
@@ -9,10 +10,6 @@ class WritingFormat < Peta::Item
   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :settings, :presence => true
   
-  def self.valid_encode_columns
-    super + ['name', 'classname', 'caption', 'settings']
-  end
-  
   def supply_default
   end
   
index 5d1d59f..dba1a3f 100644 (file)
@@ -1,3 +1,3 @@
-<div <%= raw elm.any_tag_attr() -%> class="pettanr-comic-ground-color" style="<%= elm.opt_div_style(spot) -%>">
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-ground-color", 'style' => raw(element.style(spot).to_style)}) do %>
 
-</div>
+<% end %>
index 105e48f..99da9ca 100644 (file)
@@ -1,3 +1,3 @@
-<div <%= raw elm.any_tag_attr() -%> class="pettanr-comic-ground-picture" style="<%= elm.opt_div_style(full_url(elm.picture.url), spot) -%>">
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-ground-picture", 'style' => raw(element.style(spot).merge(root.style_wh).to_style)}) do %>
   
-</div>
+<% end %>
index aab93df..13c65ee 100644 (file)
@@ -1,3 +1,3 @@
-<div <%= raw elm.any_tag_attr(:div) -%> class="pettanr-panel-picture-wrapper" style="<%= elm.opt_div_style() -%>">
-  <%= link_to_unless(elm.link.blank?, tag(:img, elm.opt_img_tag(spot)), elm.link) %>
-</div>
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-panel-picture-wrapper", 'style' => element.opt_div_style()}) do %>
+  <%= link_to_unless(element.link.blank?, tag(:img, element.opt_img_tag(spot)), element.link) %>
+<% end %>
index e3d504d..bdfa554 100644 (file)
@@ -1,13 +1,7 @@
-<% panel.panel_elements.each do |elm| %>
-  <% case elm.class.to_s %>
-  <% when 'SpeechBalloon' %>
-    <% elm.boost %>
-  <% end %>
-<% end %>
 <%= content_tag :div, :id => panel.tag_id, :panel_id => panel.tag_panel_id, :class => "pettanr-comic-panel", :style => "width: #{panel.width}px; height: #{panel.height}px; border-style: solid; border-width: #{panel.border}px; border-color: black; background-color: white;" do %>
   <% if panel.visible? operators -%>
-    <% panel.panel_elements.each do |elm| %>
-      <%= render elm.class.to_s.tableize + '/element', :elm => elm, :spot => spot %>
+    <% panel.panel_elements.each do |element| %>
+      <%= render element.path_name + '/element', :element => element, :root => panel, :spot => spot %>
     <% end %>
   <% else %>
     <h2><%= t('panels.hidden') %></h2>
index c2c52cf..41d6091 100644 (file)
@@ -1,8 +1,8 @@
-<div <%= raw elm.any_tag_attr() -%> balloon_id="<%= elm.balloon.tag_element_part_id -%>" speech_id="<%= elm.speech.tag_element_part_id -%>" class="pettanr-comic-balloon" style="width:<%= elm.balloon.width -%>px; height:<%= elm.balloon.height -%>px; top:<%= elm.balloon.y -%>px; left:<%= elm.balloon.x -%>px; z-index:<%= elm.z -%>; ">
-  <img <%= raw elm.balloon.tag_attr -%> class="pettanr-balloon" src="<%= elm.balloon.system_picture.url -%>" alt="<%= elm.caption -%>">
-  <div class="pettanr-comic-speech" style="top:<%= elm.speech.y -%>%; left:<%= elm.speech.x -%>%;width:<%= elm.speech.width -%>%; height:<%= elm.speech.height -%>%;">
-    <div class="pettanr-comic-speech-inner" <%= raw elm.speech.tag_attr -%> style="font-size:<%= elm.speech.font_size -%>em; text-align:<%= elm.speech.text_align_text -%>; color:#<%= format("%06x", elm.speech.fore_color) -%>;">
-      <%= raw elm.speech.writing_format.engine_model.render(elm.speech.content) -%>
-    </div>
-  </div>
-</div>
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-balloon", 'style' => raw(element.balloon.style.merge({'z-index' => element.z}).to_style)}) do %>
+  <%= tag :img, element.balloon.tag_attributes(nil, {'class' => "pettanr-balloon", 'src' => element.balloon.system_picture.url, 'alt' => element.caption}) %>
+  <%= content_tag :div, {'class' => "pettanr-comic-speech", 'style' => raw(element.speech.outer_style.to_style)} do %>
+    <%= content_tag :div, element.speech.tag_attributes(nil, {'class' => "pettanr-comic-speech-inner", 'style' => raw(element.speech.inner_style.to_style)}) do %>
+      <%= raw element.speech.writing_format.engine_model.render(element.speech.content) -%>
+    <% end %>
+  <% end %>
+<% end %>
index 3797f80..b1ae8e5 100644 (file)
@@ -16,3 +16,4 @@ Pettanr::Application.initialize!
 require_dependency 'manifest'
 require_dependency 'editor/editor'
 Manifest.manifest.init
+Manifest.manifest.load_models_manifest
index 7d0eb2e..04c5856 100644 (file)
@@ -16,5 +16,10 @@ class Hash
   def to_attr
     self.map {|k, n| "#{k}=\"#{n}\"" }.join(' ')
   end
+  
+  def to_style
+    self.map {|k, n| "#{k}: #{n}" }.join('; ')
+  end
+  
 end
   
index 957003e..20cd2a9 100644 (file)
@@ -4,7 +4,8 @@ module Editor
 
   class Editor
     include EditorModule
-    
+    cattr_accessor :eid
+    @@eid = 0
     class Generator
       def initialize editor
         @editor = editor
@@ -30,14 +31,25 @@ module Editor
     
     attr_accessor :root_item, :dock, :generator, :operators
     def initialize root_item, operators
+      @@eid += 1
       @root_item = root_item
       @operators = operators
       @dock = self.new_dock
+      @pool = Pool.new self, @root_item
       @generator = Generator.new self
+      @@eid = 0 if @@eid > 0x7fffff
     end
     
     #InstanceMethods
     
+    def name
+      'owner'
+    end
+    
+    def eid
+      @@eid
+    end
+    
     def new_dock
       Dock.new self
     end
@@ -54,6 +66,18 @@ module Editor
       self.template_dir + self.template_file_name
     end
     
+    def register
+      @root_item.editor = self
+      @root_item.each_elements(self.name) do |element|
+        element.editor = self
+        element.parent = @root_item
+      end
+    end
+    
+    def eid
+      'editor-' + @@eid.to_s
+    end
+    
     def dom_id
       'editor-' + @root_item.id.to_s
     end
index ad7b2be..43f3923 100644 (file)
@@ -1,6 +1,10 @@
 require_dependency "editor/panel_dock/panel_dock"
 module Editor
   class PanelEditor < Editor
+    def name
+      'panel'
+    end
+    
     def new_dock
       PanelDock.new self
     end
diff --git a/lib/editor/pool.rb b/lib/editor/pool.rb
new file mode 100644 (file)
index 0000000..ace50c3
--- /dev/null
@@ -0,0 +1,52 @@
+module Editor
+  module EditorModule
+    class Pool
+      attr_accessor :editor, :root_item, :pool, :index
+      def initialize editor, root_item
+        @editor = editor
+        @root_item = root_item
+        @pool = {}
+        @index = 1
+        self.editize
+      end
+      
+      # regist stored element
+      def editize
+        self.register @root_item
+        @root_item.each_elements(self.name) do |element|
+          self.register element
+        end
+      end
+      
+      def register item
+        @item.editor = @editor
+        parent_model = item.parent_model(@editor.name)
+        if parent_model
+          item.parent = find
+        end
+        if item.new_record?
+          if parent_model
+            # element 
+            item.parent__send__ "build_#{parent_model.child_element_name(item.item_name)}"
+          else
+            # root 
+            
+          end
+          item.pool_id = @index
+          @index += 1
+        else
+          item.pool_id = item.id
+        end
+        @pool[item.item_name] ||= {'stored' => {}, 'new'  => {}}
+        @pool[item.item_name][item.dom_pool_type] ||= {}
+        @pool[item.item_name][item.dom_pool_type][item.pool_id] = item
+      end
+      
+      def unregister item
+        
+      end
+      
+    end
+    
+  end
+end
index c457315..6c7ca5d 100644 (file)
@@ -34,21 +34,6 @@ module Manifest
           
         end
         
-        class TextTag < Base
-        end
-        
-        class NumberTag < Base
-        end
-        
-        class TextAreaTag < Base
-        end
-        
-        class SelectTag < Base
-        end
-        
-        class HiddenTag < Base
-        end
-        
       end
     end
   end
index 94dff29..97146dd 100644 (file)
@@ -25,6 +25,10 @@ module Manifest
           @form.mounted ? 0 : 1
         end
         
+        def mount_option
+          {'mount' => self.mounted}
+        end
+        
         def item
           @form.item
         end
@@ -34,7 +38,7 @@ module Manifest
         end
         
         def options tag_options = {}
-          self.item.field_tag_attributes(@field_manifest.column_name, self.mounted, tag_options)
+          self.item.field_tag_attributes(@field_manifest.column_name, tag_options).merge(self.mount_option)
         end
         
         def form_field_name
diff --git a/lib/manifest/local/view/form/field/field.rb b/lib/manifest/local/view/form/field/field.rb
deleted file mode 100644 (file)
index e69de29..0000000
index 05800a6..12f5c89 100644 (file)
@@ -27,6 +27,26 @@ module Manifest
       @system_resources.init
     end
     
+    def load_models_manifest
+      @models.each do |model_name, model|
+        model.classify.load_manifest
+      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
index 876b0a4..f11b84a 100644 (file)
@@ -64,6 +64,55 @@ module Manifest
       ::Manifest.item_name_to_model @model_name
     end
     
+    def table_name
+      self.classify.table_name
+    end
+    
+    def valid_encode_columns
+      r = []
+      @attributes.each {|attribute_name, attribute|
+        next unless attribute.type == 'text'
+        r << attribute_name
+      }
+      r
+    end
+    
+    def owner_type
+      return :author if @attributes['author_id']
+      return :artist if @attributes['artist_id']
+      false
+    end
+    
+    def content_model
+      return true if self.owner_type
+      false
+    end
+    
+    def each_child_model_manifest tree_name
+      ::Manifest.models.each {|child_model_name, child_model_manifest|
+        next unless child_model_manifest.tree[tree_name]
+        next unless child_model_manifest.tree[tree_name].parent_model_name == @model_name
+        yield child_model_manifest
+      }
+    end
+    
+    def child_models tree_name
+      r = []
+      self.each_child_model_manifest(tree_name) {|child_model_manifest|
+        r << child_model_manifest.classify
+      }
+      r
+    end
+    
+    def child_element_names tree_name
+      r = []
+      self.each_child_model_manifest(tree_name) {|child_model_manifest|
+        # has_one ?
+        r << self.associations.child_element_name(child_model_manifest.model_name)
+      }
+      r
+    end
+    
   end
 end
 
index f21d082..60e3118 100644 (file)
@@ -43,6 +43,14 @@ module Manifest
         @model.model_manifest
       end
       
+      def child_element_name child_item_name
+        if @has_one[child_item_name]
+          child_model_manifest.model_name
+        else
+          child_model_manifest.table_name
+        end
+      end
+      
     end
     
   end
index 8ae8336..27f41ee 100644 (file)
@@ -34,6 +34,10 @@ module Manifest
         end
       end
       
+      def parent_model
+        self.parent_model_manifest.classify
+      end
+      
       def model_manifest
         @model.model_manifest
       end
index 8458c51..fbc9cf8 100644 (file)
@@ -1,33 +1,68 @@
 module Peta
   class Content < Item
     self.abstract_class = true
-    # ClassMethods
     
-    def self.owner_model
-      nil
+    # Dynamic Methods
+    
+    def self._content?
+      self.my_manifest.content_model
     end
     
-    def self.owner_type
-      :author
+    def self._owner_type
+      self.my_manifest.owner_type
     end
     
-    def self.content?
-      true
+    def self._owner_model
+      t = self.my_manifest.tree['owner']
+      return nil unless t
+      t.parent_model 
     end
     
-    def self.operator operators
-      case self.owner_type
-      when :author
-        operators.author
-      when :artist
-        operators.artist
-      else
-        nil
+    def self._owner_column
+      self.owner_type.to_s + '_id'
+    end
+    
+    def self.load_manifest
+      super
+      # Class Methods
+      f = self._content?
+      define_singleton_method("content?") do 
+        f
+      end
+      t = self._owner_type
+      define_singleton_method("owner_type") do 
+        t
+      end
+      m = self._owner_model
+      define_singleton_method("owner_model") do 
+        m
+      end
+      define_singleton_method("parent_model") do |tree_name|
+        self.my_manifest.tree[tree_name].parent_model
+      end
+      o = self._owner_column
+      define_singleton_method("owner_column") do 
+        o
+      end
+      define_singleton_method("child_models") do  |tree_name|
+        self.my_manifest.child_models tree_name
+      end
+      # Instance Methods
+      define_method("parent_model") do |tree_name|
+        self.__send__ self.class.parent_model(tree_name).item_name
+      end
+      define_method("elements") do |tree_name|
+        self.my_manifest.child_element_names(tree_name).map {|element_name|
+          self.__send__ element_name
+        }
       end
     end
     
-    def self.owner_column
-      self.owner_type.to_s + '_id'
+    # Class Methods
+    
+    def self.operator operators
+      return nil unless self.owner_type
+      operators.__send__ self.owner_type
     end
     
     def self.public_list_where
@@ -39,8 +74,7 @@ module Peta
       raise ActiveRecord::Forbidden unless content.own?(operators)
       content
     end
-    
-    #InstanceMethods
+    # Instance Methods
     
     def owner_model
       self.class.owner_model ? self.__send__(self.class.owner_model.item_name) : self
index 8346bff..91092a2 100644 (file)
 module Peta
-  module Element
-    def self.included(base)
-      base.extend(ClassMethods)
-      base.__send__ :include, InstanceMethods
+  class Element < Content
+    self.abstract_class = true
+    
+    # Dynamic ClassMethods
+    
+    
+    def self.list_opt_for_panel
+      {}
+    end
+    
+    def self.show_opt_for_panel
+      {}
+    end
+    
+    def self.json_opt_for_panel
+      {}
+    end
+    
+    def has_picture?
+      false
+    end
+    
+    def has_part?
+      false
+    end
+    
+    def parts
+      @parts ||= []
     end
     
-    module ClassMethods
-      def colum_structures
-        raise
-      end
-      
-      def list_opt_for_panel
-        {}
-      end
-      
-      def show_opt_for_panel
-        {}
-      end
-      
-      def json_opt_for_panel
-        {}
-      end
-      
-      def path_name with_engine = false
-        self.to_s.tableize
-      end
-      
+    def extend_column
+      nil
     end
     
-    module InstanceMethods
-      private
-      
-      public
-      
-      def has_picture?
-        false
-      end
-      
-      def has_part?
-        false
-      end
-      
-      def parts
-        @parts ||= []
-      end
-      
-      def has_helper? column_name
-        self.class.colum_structures[column_name] and self.class.colum_structures[column_name][:helper]
-      end
-      
-      def element_name
-        self.class.to_s.underscore
-      end
-      
-      def extend_column
-        nil
-      end
-      
-      def extend_element_name
-        self.extend_column ? self.attributes[extend_column] : self.element_name
-      end
-      
-      def find_configurations hash, key
-         if hash[key].is_a? String
-           self.find_configurations hash, hash[key]
-         else
-           return hash[key]
-         end
-      end
-      
-      def element_index
-        @element_index ||= self.t
-      end
-      
-      def parent
-        @parent ||= self.panel
-      end
-      
-      def parent= content
-        @parent = content
-      end
-      
-      def new_index
-        @new_index
-      end
-      
-      def new_index= v
-        @new_index = v
-      end
-      
-      def new_panel
-        @new_panel
-      end
-      
-      def new_panel= v
-        @new_panel = v
-      end
-      
-      def get_panel
-        self.panel || @new_panel
-      end
-      
-      def tag_id c = nil
-        'panel' + self.tag_panel_id + self.tag_element_type + self.tag_element_id + c.to_s
-      end
-      
-      def field_tag_id f
-        self.tag_id + f.to_s
-      end
-      
-      def tag_panel_id
-        self.get_panel.new_record? ? '0' : self.get_panel.id.to_s
-      end
-      
-      def tag_element_id
-        self.new_record? ? '0' : self.id.to_s
-      end
-      
-      def tag_element_type
-        raise
-      end
-      
-      def tag_new_index
-        self.new_index.to_s
-      end
-      
-      def path_name with_engine = false
-        self.class.path_name(with_engine)
-      end
-      
-      def form_template with_engine = false
-        self.path_name(with_engine) + '/form'
-      end
-      
-      def scenario_template with_engine = false
-        self.path_name(with_engine) + '/scenario'
-      end
-      
-      def element_face_template with_engine = false
-        self.path_name(with_engine) + '/element_face'
-      end
-      
-      def form_helper_template(colum_name)
-        self.class.colum_structures[colum_name][:helper]
-      end
-      
-      def tag_attributes column = nil, opt = {}
-        {
-          :id => self.field_tag_id(column), :panel_id => self.tag_panel_id, 
-          :element_id => self.tag_element_id, :element_type => self.tag_element_type
-        }.merge(opt)
-      end
-      
-      def field_tag_attributes column, no_attr, opt = {}
-        self.tag_attributes(column).merge(
-          {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
-        ).merge(opt)
-      end
-      
-      #render element by body
-      def any_tag_attributes name = nil, opt = {}
-        r = self.tag_attributes(name)
-        r.merge!(
-          {:new_index => self.tag_new_index}
-        ) if self.new_index
-        r.merge(opt)
-      end
-      
-      def select_tag_attributes(selected, column, no_attr)
-        [
-          :last, :first, 
-          {:html => {:selected => selected}}, 
-          self.field_tag_attributes(column, no_attr)
-        ]
-      end
-      
-      def tag_attr column = nil, opt = {}
-        self.tag_attributes(column, opt).to_attr
-      end
-      
-      def field_tag_attr column, no_attr, opt = {}
-        self.field_tag_attributes(column, no_attr, opt).to_attr
-      end
-      
-      def any_tag_attr name = nil, opt = {}
-        self.any_tag_attributes(name, opt).to_attr
-      end
-      
+    def extend_element_name
+      self.extend_column ? self.attributes[extend_column] : self.element_name
     end
+    
+    def parent
+      @parent
+    end
+    
+    def parent= content
+      @parent = content
+    end
+    
+    def scenario_template with_engine = false
+      self.path_name(with_engine) + '/scenario'
+    end
+    
+    def element_face_template with_engine = false
+      self.path_name(with_engine) + '/element_face'
+    end
+    
+    def tag_attributes column = nil, opt = {}
+      r = super
+      r.merge({'data-parent_dom_id' => self.parent.dom_item_id}) if self.editor
+      r
+    end
+    
+    def merge_opacity s, opacity
+      s.merge({
+        'opacity' => opacity.to_f/100, 
+        'filter' => "alpha(opacity=#{opacity})"
+      })
+    end
+    
   end
 end
 
index b3db406..b8b889a 100644 (file)
@@ -1,12 +1,31 @@
 module Peta
   class Item < ActiveRecord::Base
     self.abstract_class = true
+    
+    # Dynamic ClassMethods
+    
+    def self._valid_encode_columns
+      self.my_manifest.valid_encode_columns
+    end
+    
+    def self.load_manifest
+      return nil unless self.my_manifest
+      r = self._valid_encode_columns
+      define_singleton_method("valid_encode_columns") do 
+        r
+      end
+    end
+    
     # ClassMethods
     # class_name
     # table_name
     
     before_validation :valid_encode
     
+    def self.my_manifest
+      Manifest.manifest.models[self.item_name]
+    end
+    
     def self.singular
       self.to_s
     end
@@ -31,10 +50,6 @@ module Peta
       self.plural.underscore
     end
     
-    def self.valid_encode_columns
-      []
-    end
-    
     def self.visible_count_options
       nil
     end
@@ -71,14 +86,6 @@ module Peta
       {}
     end
     
-    def self.visible_count
-      self.count self.visible_count_options
-    end
-    
-    def self.visible_count_options
-      []
-    end
-    
     #InstanceMethods
     
     def self.fold_extend_settings params
@@ -115,6 +122,14 @@ module Peta
       self.class.table_name
     end
     
+    def path_name with_engine = false
+      self.class.path_name(with_engine)
+    end
+    
+    def form_template with_engine = false
+      self.path_name(with_engine) + '/form'
+    end
+    
     def extend_column
       nil
     end
@@ -149,69 +164,50 @@ module Peta
       true
     end
     
-    def dom_id_item 
-      self.new_record? ? '0' : self.id.to_s
+    def editor
+      @editor
     end
     
-    def tag_item_id c = nil
-      self.item_name + self.item_id + c.to_s
+    def editor=(e)
+      @editor = e
     end
     
-    def dom_id_item_field field_name
-      self.tag_item_id + field_name.to_s
+    def pool_id
+      @pool_id || self.id
     end
     
-    def path_name with_engine = false
-      self.class.path_name(with_engine)
-    end
-    
-    def form_template with_engine = false
-      self.path_name(with_engine) + '/form'
-    end
-    
-    def tag_item_attributes column = nil, opt = {}
-      {
-        :id => self.field_tag_id(column), :panel_id => self.tag_panel_id, 
-        :element_id => self.tag_element_id, :element_type => self.tag_element_type
-      }.merge(opt)
-    end
-    
-      def tag_new_index
-      end
-      
-    def field_tag_attributes column, no_attr, opt = {}
-      self.tag_attributes(column).merge(
-        {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
-      ).merge(opt)
+    def pool_id=(i)
+      @pool_id = i
     end
     
-    #render element by body
-    def any_tag_attributes name = nil, opt = {}
-      r = self.tag_attributes(name)
-      r.merge!(
-        {:new_index => self.tag_new_index}
-      ) if self.new_index
-      r.merge(opt)
+    def dom_id
+      self.pool_id.to_s
     end
     
-    def select_tag_attributes(selected, column, no_attr)
-      [
-        :last, :first, 
-        {:html => {:selected => selected}}, 
-        self.field_tag_attributes(column, no_attr)
-      ]
+    def dom_pool_type
+      self.new_record? ? 'stored' : 'new'
     end
     
-    def tag_attr column = nil, opt = {}
-      self.tag_attributes(column, opt).to_attr
+    def dom_item_id name = nil
+      r = [self.editor.eid, self.dom_pool_type, self.item_name, self.dom_id]
+      r += name.to_s if column_name
+      r.join '-'
     end
     
-    def field_tag_attr column, no_attr, opt = {}
-      self.field_tag_attributes(column, no_attr, opt).to_attr
+    def tag_attributes name = nil, opt = {}
+      r = {
+        'data-pool_type' => self.dom_pool_type, 'data-id' => self.dom_id, 
+        'data-item_name' => self.item_name
+      }
+      r.merge!({'id' => self.dom_item_id(name)}) if self.editor
+      r.merge!(opt)
+      r
     end
     
-    def any_tag_attr name = nil, opt = {}
-      self.any_tag_attributes(name, opt).to_attr
+    def field_tag_attributes column_name, opt = {}
+      self.tag_attributes(column_name, opt).merge(
+        {'data-column_name' => column_name}
+      )
     end
     
   end