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)
1  2 
app/models/ground_color.rb
app/models/ground_picture.rb
app/models/panel.rb
app/models/speech_balloon.rb
app/models/speech_balloon_template.rb
app/views/ground_colors/_element.html.erb
app/views/ground_pictures/_element.html.erb
app/views/panels/_body.html.erb
lib/manifest/manifest.rb
lib/peta/element.rb
lib/peta/item.rb

@@@ -100,9 -108,9 +100,15 @@@ class GroundColor < Peta::Elemen
      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
@@@ -59,9 -67,9 +59,15 @@@ class GroundPicture < Peta::Elemen
      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
@@@ -68,6 -67,6 +68,13 @@@ class Panel < Peta::Conten
      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
Simple merge
Simple merge
@@@ -1,3 -1,3 +1,3 @@@
- <%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-ground-color", 'style' => element.opt_div_style(spot)}) do %>
 -<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 %>
@@@ -1,3 -1,3 +1,3 @@@
- <%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-ground-picture", 'style' => element.opt_div_style(full_url(element.picture.url), spot)}) do %>
 -<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 %>
@@@ -1,13 -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, :spot => spot %>
++      <%= render element.path_name + '/element', :element => element, :root => panel, :spot => spot %>
      <% end %>
    <% else %>
      <h2><%= t('panels.hidden') %></h2>
@@@ -15,38 -16,17 +16,37 @@@ module Manifes
      def init
        # managers can't initialize before load  application.rb
        return unless defined? ::Pettanr
-       @controllers = Controller.manager(self, @manifest['controllers'])
-       @models = Model.manager(self, @manifest['models'])
+       @controllers = Controller.manager(self, @manifest['controllers'] || {})
+       @models = Model.manager(self, @manifest['models'] || {})
        @locals = @manifest['locals']
        @list_groups = ListGroup.manager(self, @locals['list_groups'] || {})
-       @filers = Filer.manager(self, @locals['filers'])
-       @profilers = Profiler.manager(self, @locals['profilers'])
-       @forms = Form.base_manager(self, @locals['forms'])
-       @forms.merge(Form.extend_manager(self, @locals['forms']))
+       @filers = Filer.manager(self, @locals['filers'] || {})
+       @profilers = Profiler.manager(self, @locals['profilers'] || {})
+       @forms = Form.base_manager(self, @locals['forms'] || {})
+       @forms.merge(Form.extend_manager(self, @locals['forms'] || {}))
        @system_resources.init
-       add_action
      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
  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
  
@@@ -86,8 -71,38 +86,30 @@@ module Pet
        {}
      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
+       speech_balloon_settings = params[:speech_balloon][:settings]
+       if speech_balloon_settings.is_a?(Hash)
+         params[:speech_balloon][:settings] = speech_balloon_settings.to_json
+       end
+       balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
+       if balloon_settings.is_a?(Hash)
+         params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
+       end
+       speech_settings = params[:speech_balloon][:speech_attributes][:settings]
+       if speech_settings.is_a?(Hash)
+         params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
+       end
+     end
+     
+     def extend_engine_module
+       self.extend self.speech_balloon_template.engine_speech_balloon_module
+       self.elements.each do |element|
+         element.extend_item
+       end
+     end
+     
      def item_name
        self.class.item_name
      end