qor_layout 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source :rubygems
2
2
 
3
- # gem_rails
4
- #
5
- # gem "qor_extlib", :path => '..'
6
- # gem 'qor_resources_engine', :path => '..'
7
- # gem 'qor_form', :path => '..'
8
- #
9
- # gem 'default_value_for'
3
+ gemspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -30,12 +30,12 @@ module Qor
30
30
 
31
31
  def values(name, for_setting=false)
32
32
  stored_value = (value || {}).with_indifferent_access[name]
33
- gadget_setting = gadget_settings[name]
33
+ gadget_setting = gadget_settings.find(:meta, name)
34
34
 
35
35
  if stored_value =~ /^([\w:]+)\((\d+)\)$/
36
36
  return ($1.constantize.find_by_id($2) rescue stored_value)
37
- elsif gadget_setting && (gadget_setting[:type].to_s == 'gadget')
38
- gadget_name = gadget_setting[:name] || name
37
+ elsif gadget_setting && (gadget_setting.options[:type].to_s == 'gadget')
38
+ gadget_name = gadget_setting.options[:name] || name
39
39
  gadgets = children.where(:name => gadget_name)
40
40
  return (for_setting ? gadgets.map(&:settings) : gadgets)
41
41
  else
@@ -44,10 +44,9 @@ module Qor
44
44
  end
45
45
 
46
46
  def meta_settings
47
- gadget_settings.inject({}) do |s, setting|
48
- key = setting[0]
49
- value = values(key, true)
50
- s.merge({key => value})
47
+ gadget_settings.children.inject({}) do |s, setting|
48
+ value = values(setting.name, true)
49
+ s.merge({setting.name => value})
51
50
  end.with_indifferent_access
52
51
  end
53
52
 
@@ -58,8 +57,10 @@ module Qor
58
57
  def value_attributes=(attrs)
59
58
  attrs = attrs.with_indifferent_access
60
59
  value_attrs = {}
61
- gadget_settings.map do |key, value|
62
- if value[:type].to_s =~ /image|file|media/
60
+ gadget_settings.find(:meta).map do |child|
61
+ key = child.name
62
+
63
+ if child.options[:type].to_s =~ /image|file|media/
63
64
  if self.value && (self.value[key] =~ /^([\w:]+)\((\d+)\)$/)
64
65
  asset = $1.constantize.find_by_id($2).update_attribute(:data, attrs[key]) if attrs[key]
65
66
  value_attrs.update({key => self.value[key]})
@@ -96,8 +97,8 @@ module Qor
96
97
  end
97
98
 
98
99
  def settings
99
- if gadget.try(:context_blk)
100
- self.instance_eval &gadget.try(:context_blk)
100
+ if gadget.first(:context).try(:block)
101
+ self.instance_eval &gadget.first(:context).try(:block)
101
102
  else
102
103
  meta_settings
103
104
  end
@@ -105,15 +106,15 @@ module Qor
105
106
 
106
107
  def resource_attributes_for_settings
107
108
  attrs = []
108
- (gadget.try(:settings) || {}).map do |key, value|
109
- attr_show = !value[:hidden]
110
- attrs << Qor::ResourceAttribute.new("value_attributes[#{key}]", gadget_settings[key]) if attr_show
109
+ gadget_settings.children.map do |child|
110
+ attr_show = !child.options[:hidden]
111
+ attrs << Qor::ResourceAttribute.new("value_attributes[#{child.name}]", child.options) if attr_show
111
112
  end
112
113
  attrs
113
114
  end
114
115
 
115
116
  def render_without_style
116
- ::Mustache.render(gadget.try(:template).to_s, settings)
117
+ ::Mustache.render(gadget.first(:template).try(:value).to_s, settings)
117
118
  end
118
119
 
119
120
  def render(edit_mode=false)
@@ -124,7 +125,7 @@ module Qor
124
125
  style_css = new_style.map {|k,v| "#{k}: #{v}"}.join("; ")
125
126
 
126
127
  parse_content.xpath('*').first.set_attribute("qor_layout_elements", id.to_s)
127
- parse_content.xpath('*').first.set_attribute("qor_layout_draggable_elements", id.to_s) if gadget.respond_to?(:floating) && gadget.floating
128
+ parse_content.xpath('*').first.set_attribute("qor_layout_draggable_elements", id.to_s) if gadget.options[:floating]
128
129
  parse_content.xpath('*').first.set_attribute("style", style_css)
129
130
  extra = edit_mode ? "<div for_qor_layout_elements='#{id}'><a href='/admin/layout_settings/#{id}/edit'><img src='/qor_widget/images/settings.png'/></a></div>" : ""
130
131
 
@@ -132,15 +133,11 @@ module Qor
132
133
  end
133
134
 
134
135
  def gadget
135
- Qor::Layout::Configuration.gadgets.with_indifferent_access[name]
136
+ Qor::Layout::Configuration.find(:gadget, name)
136
137
  end
137
138
 
138
139
  def gadget_settings
139
- (gadget.try(:settings) || {}).with_indifferent_access
140
- end
141
-
142
- def gadget_children_settings
143
- gadget_settings.select {|k,v| v[:type].to_s == 'gadget'}
140
+ gadget.first(:settings)
144
141
  end
145
142
 
146
143
  def method_missing(method_sym, *args, &block)
@@ -2,8 +2,8 @@ module Qor
2
2
  module Layout
3
3
  module Action
4
4
  def self.detect_action(app)
5
- Qor::Layout::Configuration.actions.values.map do |action|
6
- return action if action.detect_blk.safe_call(app)
5
+ Qor::Layout::Configuration.find(:action).map do |action|
6
+ return action if action.first(:detect).block.safe_call(app)
7
7
  end
8
8
  end
9
9
  end
@@ -1,144 +1,31 @@
1
+ require 'qor_dsl'
2
+
1
3
  module Qor
2
4
  module Layout
3
5
  module Configuration
4
- class Inputs
5
- include Qor::Extlib::Dsl::Configuration::InputMeta
6
- end
7
-
8
- class RawData
9
- include Qor::Extlib::Dsl::Configuration::RawData
10
- attr_accessor :description, :description_blk, :meta_inputs, :template_blk, :context_blk, :detect_blk
11
-
12
- def layout(name, options = {}, &blk)
13
- Qor::Layout::Configuration::Layout.new(blk, self.owner, options.merge(:name => name))
14
- end
15
-
16
- def gadget(name, options = {}, &blk)
17
- Qor::Layout::Configuration::Gadget.new(blk, self.owner, options.merge(:name => name))
18
- end
19
-
20
- def action(name, options = {}, &blk)
21
- ::Qor::Layout::Configuration::Action.new(blk, self.owner, options.merge(:name => name))
22
- end
23
-
24
- def gadgets(name, options = {}, &blk)
25
- # TODO define gadgets for layout
26
- end
27
-
28
- def settings(&blk)
29
- self.meta_inputs = Inputs.new
30
- self.meta_inputs.instance_eval(&blk)
31
- self.meta_inputs
32
- end
33
-
34
- def context(&blk)
35
- self.context_blk = blk
36
- end
37
-
38
- def template(&blk)
39
- self.template_blk = blk
40
- end
41
-
42
- def detect(&blk)
43
- self.detect_blk = blk
44
- end
45
-
46
- def desc(description = nil, &blk)
47
- raise 'desc must be string or blcok' unless description.is_a?(String) || blk
48
- self.description = description
49
- self.description_blk = blk
50
- end
51
- end
52
-
53
- class Base
54
- include Qor::Extlib::Dsl::Configuration::Base
55
- attr_accessor :name, :floating
56
-
57
- self.raw_data_klazz = ::Qor::Layout::Configuration::RawData
58
- def initialize(*arguments)
59
- super
60
-
61
- root = arguments[1]
6
+ include Qor::Dsl
7
+ default_configs ["config/qor/layout.rb", "config/layout.rb"]
62
8
 
63
- if root
64
- root.group_children ||= {}
65
- root.group_children[self.class.to_s] ||= {}
66
- root.group_children[self.class.to_s][self.name.to_s] = self
67
- end
68
- end
9
+ node :template
69
10
 
70
- def child_key
71
- File.join(self.class.to_s, self.name.to_s)
72
- end
11
+ node :gadget do
12
+ node :desc
73
13
 
74
- def description
75
- self.raw_data.description || self.raw_data.description_blk.try(:call)
14
+ node :settings do
15
+ node :meta
76
16
  end
77
- end
78
-
79
- class Root < Base
80
- attr_accessor :group_children
81
17
 
82
- def layouts(name=nil)
83
- children = group_children[Layout.to_s]
84
- children = children[name] if name.present?
85
- children
86
- end
87
-
88
- def gadgets(name=nil)
89
- children = group_children[Gadget.to_s]
90
- children = children[name] if name.present?
91
- children
92
- end
93
-
94
- def gadget_by_name(name)
95
- Qor::Layout::Configuration.gadgets.with_indifferent_access[name]
96
- end
97
-
98
- def gadget_settings_by_name(name)
99
- (gadget_by_name(name).try(:settings) || {}).with_indifferent_access
100
- end
101
-
102
- def actions(name=nil)
103
- children = group_children[Action.to_s]
104
- children = children[name] if name.present?
105
- children
106
- end
18
+ node :context
19
+ node :template, :inherit => true
107
20
  end
108
21
 
109
- class Layout < Base
22
+ node :layout do
23
+ node :gadgets
110
24
  end
111
- class Gadget < Base
112
- def settings
113
- self.raw_data.meta_inputs.meta_hash.inject({}) do |s, v|
114
- s.update({v[0] => {:label => (v[1].with_indifferent_access[:name] || v[0]).to_s}.merge(v[1])})
115
- end
116
- end
117
-
118
- def context_blk
119
- self.raw_data.context_blk
120
- end
121
-
122
- def template
123
- self.raw_data.template_blk.call
124
- end
125
- end
126
- class Action < Base
127
- def detect_blk
128
- self.raw_data.detect_blk
129
- end
130
- end
131
-
132
- class << self
133
- def load(path="config/layout.rb")
134
- @root = Qor::Extlib::Dsl::Configuration.load(::Qor::Layout::Configuration::Root, path)
135
- end
136
-
137
- def root
138
- @root ||= load
139
- end
140
25
 
141
- delegate :layouts, :gadgets, :actions, :gadget_by_name, :gadget_settings_by_name, :to => :root
26
+ node :action do
27
+ node :desc
28
+ node :detect
142
29
  end
143
30
  end
144
31
  end
data/qor_layout.gemspec CHANGED
@@ -16,4 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "qor_dsl"
19
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qor_layout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: qor_dsl
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: Easily to make your own layout
15
31
  email:
16
32
  - wosmvp@gmail.com