rich_cms 2.0.7 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -1
- data/README.textile +58 -16
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/{lib/app → app}/controllers/rich/cms_controller.rb +7 -7
- data/{lib/app → app}/views/rich/cms/_dock.html.erb +1 -1
- data/{lib/app → app}/views/rich/cms/dock/_menu.html.erb +1 -1
- data/{lib/app → app}/views/rich/cms/dock/_panel.html.erb +1 -1
- data/app/views/rich/cms/dock/panel/_edit.html.erb +1 -0
- data/app/views/rich/cms/dock/panel/_login.html.erb +1 -0
- data/app/views/rich/cms/dock/panel/edit/_rails3.html.erb +10 -0
- data/{lib/app/views/rich/cms/dock/panel/_login.html.erb → app/views/rich/cms/dock/panel/login/_rails2.html.erb} +4 -4
- data/app/views/rich/cms/dock/panel/login/_rails3.html.erb +15 -0
- data/{lib/app → app}/views/rich_cms.html.erb +1 -1
- data/{lib/assets → assets}/jzip/jquery/cleditor.js +14 -14
- data/assets/jzip/jquery/extensions/ajaxify.js +26 -0
- data/{lib/assets → assets}/jzip/jquery/raccoon_tip.js +22 -22
- data/assets/jzip/jquery/ui/components/draggable.js +797 -0
- data/assets/jzip/jquery/ui/components/mouse.js +151 -0
- data/assets/jzip/jquery/ui/components/widget.js +237 -0
- data/{lib/assets → assets}/jzip/rich/cms/dock.js +5 -5
- data/{lib/assets → assets}/jzip/rich/cms/editor.js +21 -21
- data/{lib/assets → assets}/jzip/rich/cms/menu.js +3 -3
- data/{lib/assets → assets}/jzip/rich/cms.js +1 -1
- data/{lib/assets → assets}/sass/rich_cms/_dock.sass +2 -2
- data/{lib/assets → assets}/sass/rich_cms/_menu.sass +2 -2
- data/{lib/assets → assets}/sass/rich_cms/_panel.sass +2 -2
- data/{lib/assets → assets}/sass/tools/_mixins.sass +5 -5
- data/config/routes.rb +36 -0
- data/lib/generators/rich/authlogic_user/authlogic_user_generator.rb +63 -0
- data/lib/generators/rich/authlogic_user/templates/migration.rb +25 -0
- data/lib/generators/rich/authlogic_user/templates/model.rb +12 -0
- data/lib/generators/rich/authlogic_user/templates/session.rb +7 -0
- data/lib/generators/rich/cms_content/cms_content_generator.rb +59 -0
- data/lib/generators/rich/cms_content/templates/migration.rb +15 -0
- data/lib/generators/rich.rb +25 -0
- data/lib/rich/cms/actionpack/action_controller/base.rb +8 -8
- data/lib/rich/cms/actionpack/action_view/base.rb +14 -14
- data/lib/rich/cms/activesupport/active_support/dependencies.rb +12 -0
- data/lib/rich/cms/activesupport.rb +1 -0
- data/lib/rich/cms/content/group.rb +13 -13
- data/lib/rich/cms/content/item.rb +17 -17
- data/lib/rich/cms/core/string/html_safe.rb +18 -0
- data/lib/rich/cms/core/string.rb +6 -0
- data/lib/rich/cms/core.rb +1 -0
- data/lib/rich/cms/engine.rb +85 -74
- data/lib/rich/cms/rails/engine.rb +5 -0
- data/lib/rich/cms/rails.rb +1 -0
- data/lib/rich_cms.rb +8 -6
- data/rails_generators/rich_authlogic_user/rich_authlogic_user_generator.rb +4 -4
- data/rails_generators/rich_authlogic_user/templates/migration.rb +1 -1
- data/rails_generators/rich_authlogic_user/templates/model.rb +1 -1
- data/rails_generators/rich_authlogic_user/templates/session.rb +4 -0
- data/rails_generators/rich_cms_content/rich_cms_content_generator.rb +3 -3
- data/rails_generators/rich_cms_content/templates/migration.rb +1 -1
- data/rich_cms.gemspec +69 -60
- data/test/test_helper.rb +4 -1
- metadata +73 -62
- data/lib/app/controllers/rich/._cms_controller.rb +0 -0
- data/lib/app/views/._rich_cms.html.erb +0 -0
- data/lib/app/views/rich/cms/dock/.__menu.html.erb +0 -0
- data/lib/app/views/rich/cms/dock/.__panel.html.erb +0 -0
- data/lib/app/views/rich/cms/dock/panel/.__login.html.erb +0 -0
- data/lib/assets/jzip/jquery/extensions/ajaxify.js +0 -26
- data/lib/assets/jzip/jquery/ui/components/draggable.js +0 -797
- data/lib/assets/jzip/jquery/ui/components/mouse.js +0 -151
- data/lib/assets/jzip/jquery/ui/components/widget.js +0 -237
- data/lib/config/routes.rb +0 -19
- data/lib/rich/cms/actionpack/action_controller/._base.rb +0 -0
- data/lib/rich/cms/actionpack/action_view/._base.rb +0 -0
- data/test/engine_test.rb +0 -15
- /data/{lib/app/views/rich/cms/dock/panel/_edit.html.erb → app/views/rich/cms/dock/panel/edit/_rails2.html.erb} +0 -0
- /data/{lib/assets → assets}/images/cleditor/buttons.gif +0 -0
- /data/{lib/assets → assets}/images/cleditor/toolbar.gif +0 -0
- /data/{lib/assets → assets}/jzip/jquery/core.jz +0 -0
- /data/{lib/assets → assets}/jzip/jquery/extensions/browser_detect.js +0 -0
- /data/{lib/assets → assets}/jzip/jquery/extensions/modules.js +0 -0
- /data/{lib/assets → assets}/jzip/jquery/extensions/object.js +0 -0
- /data/{lib/assets → assets}/jzip/jquery/ui/components/core.js +0 -0
- /data/{lib/assets → assets}/jzip/jquery/ui/rich_cms/core.jz +0 -0
- /data/{lib/assets → assets}/jzip/jquery/ui/rich_cms/draggable.jz +0 -0
- /data/{lib/assets → assets}/jzip/jquery/ui/rich_cms/mouse.jz +0 -0
- /data/{lib/assets → assets}/jzip/jquery/ui/rich_cms/widget.jz +0 -0
- /data/{lib/assets → assets}/jzip/rich.js +0 -0
- /data/{lib/assets → assets}/jzip/rich_cms.jz +0 -0
- /data/{lib/assets → assets}/sass/rich_cms/_content.sass +0 -0
- /data/{lib/assets → assets}/sass/rich_cms/_reset.sass +0 -0
- /data/{lib/assets → assets}/sass/rich_cms.sass +0 -0
- /data/{lib/assets → assets}/sass/tools/_css3.sass +0 -0
data/config/routes.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
if Rails::VERSION::MAJOR >= 3
|
2
|
+
|
3
|
+
Rails.application.routes.draw do
|
4
|
+
scope :module => "rich" do
|
5
|
+
%w(login logout update).each do |action|
|
6
|
+
match "/cms/#{action}" => "cms##{action}", :as => "rich_cms_#{action}"
|
7
|
+
end
|
8
|
+
match "/cms/" => "cms#display", :as => "rich_cms" , :display => true
|
9
|
+
match "/cms/hide" => "cms#display", :as => "rich_cms_hide", :display => false
|
10
|
+
match "/cms/position" => "cms#position"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
else
|
15
|
+
|
16
|
+
# TODO: add routes the right way as this is evil
|
17
|
+
class << ActionController::Routing::Routes;self;end.class_eval do
|
18
|
+
define_method :clear!, lambda {}
|
19
|
+
end
|
20
|
+
# END
|
21
|
+
|
22
|
+
ActionController::Routing::Routes.draw do |map|
|
23
|
+
map.namespace :rich, :path_prefix => "" do |rich|
|
24
|
+
|
25
|
+
%w(login logout update).each do |action|
|
26
|
+
rich.send "cms_#{action}", "cms/#{action}", :controller => "cms", :action => action
|
27
|
+
end
|
28
|
+
|
29
|
+
rich.cms "cms" , :controller => "cms", :action => "display", :display => true
|
30
|
+
rich.cms_hide "cms/hide" , :controller => "cms", :action => "display", :display => false
|
31
|
+
rich.connect "cms/position", :controller => "cms", :action => "position"
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "generators/rich"
|
2
|
+
|
3
|
+
module Rich
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class AuthlogicUserGenerator < Base
|
7
|
+
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
include Rich::Generators::Migration
|
10
|
+
|
11
|
+
desc "Creates Authlogic model and migration and also registers authenticated model to Rich-CMS."
|
12
|
+
argument :model_name, :type => :string , :default => "user"
|
13
|
+
class_option :migrate , :type => :boolean, :default => false, :aliases => "-m", :desc => "Run 'rake db:migrate' after generating model and migration"
|
14
|
+
|
15
|
+
def register_authentication
|
16
|
+
filename = "config/initializers/enrichments.rb"
|
17
|
+
line = "\nRich::Cms::Engine.authenticate(:authlogic, {:class_name => \"#{model_class_name}\", :identifier => :email})"
|
18
|
+
|
19
|
+
return if File.open(filename, "a+").readlines.include? line.strip
|
20
|
+
|
21
|
+
File.open(filename, "a+") do |file|
|
22
|
+
file << line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_model
|
27
|
+
template "model.rb", "app/models/#{model_file_name}.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_session
|
31
|
+
template "session.rb", "app/models/#{model_file_name}_session.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_migration
|
35
|
+
migration_template "migration.rb", "db/migrate/create_#{table_name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def migrate
|
39
|
+
rake "db:migrate" if options[:migrate]
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def model_file_name
|
45
|
+
model_name.underscore
|
46
|
+
end
|
47
|
+
|
48
|
+
def model_class_name
|
49
|
+
model_name.classify
|
50
|
+
end
|
51
|
+
|
52
|
+
def migration_class_name
|
53
|
+
migration_file_name.pluralize.camelize
|
54
|
+
end
|
55
|
+
|
56
|
+
def table_name
|
57
|
+
model_file_name.underscore.gsub("/", "_").pluralize
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :email
|
6
|
+
t.string :crypted_password
|
7
|
+
t.string :password_salt
|
8
|
+
t.datetime :created_at
|
9
|
+
t.string :persistence_token , :default => "", :null => false
|
10
|
+
t.string :single_access_token, :default => "", :null => false
|
11
|
+
t.string :perishable_token , :default => "", :null => false
|
12
|
+
t.integer :login_count
|
13
|
+
t.datetime :last_request_at
|
14
|
+
t.datetime :current_login_at
|
15
|
+
t.datetime :last_login_at
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
|
19
|
+
add_index :<%= table_name %>, :email
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.down
|
23
|
+
drop_table :<%= table_name %>
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "generators/rich"
|
2
|
+
|
3
|
+
module Rich
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class CmsContentGenerator < Base
|
7
|
+
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
include Rich::Generators::Migration
|
10
|
+
|
11
|
+
desc "Creates Rich-CMS content model and migration and also registers content to Rich-CMS."
|
12
|
+
argument :model_name, :type => :string , :default => "cms_content"
|
13
|
+
class_option :migrate , :type => :boolean, :default => false, :aliases => "-m", :desc => "Run 'rake db:migrate' after generating model and migration"
|
14
|
+
|
15
|
+
def register_content
|
16
|
+
filename = "config/initializers/enrichments.rb"
|
17
|
+
line = "\nRich::Cms::Engine.register(\".#{model_file_name}\", {:class_name => \"#{model_class_name}\"})"
|
18
|
+
|
19
|
+
return if File.open(filename, "a+").readlines.include? line.strip
|
20
|
+
|
21
|
+
File.open(filename, "a+") do |file|
|
22
|
+
file << line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_model
|
27
|
+
invoke "active_record:model", [model_file_name], :migration => false
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_migration
|
31
|
+
migration_template "migration.rb", "db/migrate/create_#{table_name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def migrate
|
35
|
+
rake "db:migrate" if options[:migrate]
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def model_file_name
|
41
|
+
model_name.underscore
|
42
|
+
end
|
43
|
+
|
44
|
+
def model_class_name
|
45
|
+
model_name.classify
|
46
|
+
end
|
47
|
+
|
48
|
+
def migration_class_name
|
49
|
+
migration_file_name.pluralize.camelize
|
50
|
+
end
|
51
|
+
|
52
|
+
def table_name
|
53
|
+
model_file_name.underscore.gsub("/", "_").pluralize
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
t.string :key
|
5
|
+
t.text :value
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index :<%= table_name %>, :key
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :<%= table_name %>
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "rails/generators/named_base"
|
2
|
+
|
3
|
+
module Rich
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class Base < Rails::Generators::Base
|
7
|
+
def self.source_root
|
8
|
+
File.expand_path File.join(File.dirname(__FILE__), "rich", generator_name, "templates")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Migration
|
13
|
+
def self.included(base)
|
14
|
+
base.extend ClassMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def next_migration_number(dirname)
|
19
|
+
Time.now.strftime "%Y%m%d%H%M%S"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -3,21 +3,21 @@ module ActionController
|
|
3
3
|
class Base
|
4
4
|
|
5
5
|
around_filter :prepare_rich_cms
|
6
|
-
|
6
|
+
|
7
7
|
def prepare_rich_cms
|
8
8
|
::Rich::Cms::Engine.current_controller = self
|
9
9
|
yield
|
10
10
|
ensure
|
11
11
|
::Rich::Cms::Engine.current_controller = nil
|
12
12
|
end
|
13
|
-
|
14
|
-
view_path = File.
|
13
|
+
|
14
|
+
view_path = File.expand_path "../../../../../../app/views", __FILE__
|
15
15
|
if respond_to? :append_view_path
|
16
16
|
self.append_view_path view_path
|
17
17
|
elsif respond_to? :view_paths
|
18
18
|
self.view_paths << view_path
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
helper_method :current_rich_cms_admin, :current_rich_cms_admin_name, :rich_cms_authenticated_class, :rich_cms_authentication_inputs
|
22
22
|
|
23
23
|
def require_current_rich_cms_admin
|
@@ -39,24 +39,24 @@ module ActionController
|
|
39
39
|
def current_rich_cms_admin_name
|
40
40
|
current_rich_cms_admin[rich_cms_auth.specs[:identifier]] if current_rich_cms_admin
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def rich_cms_auth
|
44
44
|
::Rich::Cms::Engine.authentication
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def rich_cms_authenticated_class
|
48
48
|
case rich_cms_auth.logic
|
49
49
|
when :authlogic
|
50
50
|
"#{rich_cms_auth.specs[:class_name]}Session".constantize
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def rich_cms_authentication_inputs
|
55
55
|
case rich_cms_auth.logic
|
56
56
|
when :authlogic
|
57
57
|
rich_cms_auth.specs[:inputs] || [:email, :password]
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
end
|
62
62
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
|
2
2
|
module ActionView
|
3
3
|
class Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
|
5
|
+
def rich_cms
|
6
|
+
render :file => File.expand_path("../../../../../../app/views/rich_cms.html.erb", __FILE__) if display_rich_cms?
|
7
|
+
end
|
8
|
+
|
9
9
|
def display_rich_cms?
|
10
10
|
!!session[:rich_cms].try(:fetch, :display, nil)
|
11
11
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
|
13
|
+
def link(name, options = nil)
|
14
|
+
options = {:class => options || name.underscore} unless options.is_a?(Hash)
|
15
|
+
link_to name, "#", options
|
16
|
+
end
|
17
|
+
|
18
|
+
def rich_cms_tag(*args)
|
19
|
+
Rich::Cms::Engine.to_content_tag *args
|
20
|
+
end
|
21
21
|
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "activesupport", "active_support", "dependencies.rb")
|
@@ -2,13 +2,13 @@
|
|
2
2
|
module Rich
|
3
3
|
module Cms
|
4
4
|
module Content
|
5
|
-
|
5
|
+
|
6
6
|
class Group < Struct.new(:selector, :tag, :class_name, :key, :value, :add, :before_edit, :after_update)
|
7
|
-
|
7
|
+
|
8
8
|
def self.build(selector, specs)
|
9
9
|
self.new *{:selector => selector, :key => :key, :value => :value}.merge(specs).stringify_keys.values_at(*self.members)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def fetch(ref, as_content_item = true)
|
13
13
|
reference = if ref.is_a?(Hash)
|
14
14
|
ref
|
@@ -16,24 +16,24 @@ module Rich
|
|
16
16
|
{identifiers.first => ref}
|
17
17
|
end
|
18
18
|
reference.stringify_keys! if reference.is_a?(Hash)
|
19
|
-
|
19
|
+
|
20
20
|
unless valid_reference?(reference)
|
21
21
|
raise ArgumentError, "Invalid reference #{reference.inspect} (#{reference.values_at(*identifiers).inspect}) passed for #{identifiers.inspect}"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
object = self.class_name.constantize.send :"find_or_initialize_by_#{identifiers.join "_and_"}", *reference.values_at(*identifiers)
|
25
|
-
|
25
|
+
|
26
26
|
as_content_item ? Cms::Content::Item.new(self, object) : object
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def keys
|
30
30
|
(identifiers + [self.add || []].flatten.collect(&:to_s)).sort
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def identifiers
|
34
34
|
@identifiers ||= [self.key].flatten.collect(&:to_s).sort
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def to_javascript_hash
|
38
38
|
"#{self.selector.inspect}: {#{
|
39
39
|
members.collect do |k|
|
@@ -54,15 +54,15 @@ module Rich
|
|
54
54
|
end.compact.join(", ")
|
55
55
|
}}"
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
private
|
59
|
-
|
59
|
+
|
60
60
|
def valid_reference?(reference)
|
61
61
|
reference.is_a?(Hash) && (identifiers - reference.keys).empty? && reference.values_at(*identifiers).compact!.nil?
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -4,7 +4,7 @@ module Rich
|
|
4
4
|
module Content
|
5
5
|
|
6
6
|
class Item
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(*args)
|
9
9
|
if args.size == 1 && args.first.is_a?(Hash)
|
10
10
|
hash = args.first
|
@@ -13,13 +13,13 @@ module Rich
|
|
13
13
|
else
|
14
14
|
raise ArgumentError, "Invalid arguments #{args.inspect} passed for #{self.class.name}"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
if hash && (selector = hash.stringify_keys["__selector__"])
|
18
18
|
@group = Engine.editable_content[selector]
|
19
19
|
@object = @group.fetch hash, false
|
20
|
-
|
20
|
+
|
21
21
|
attributes, params = hash.partition{|k, v| @object.attribute_names.include? k.to_s}
|
22
|
-
|
22
|
+
|
23
23
|
@object.attributes = Hash[*attributes.flatten]
|
24
24
|
@params = HashWithIndifferentAccess[*params.flatten]
|
25
25
|
|
@@ -27,7 +27,7 @@ module Rich
|
|
27
27
|
@group, @object = *array
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def save
|
32
32
|
@object.save
|
33
33
|
|
@@ -37,38 +37,38 @@ module Rich
|
|
37
37
|
keys = @group.keys << @group.value.to_s
|
38
38
|
hash = @object.attributes.reject{|k, v| !keys.include?(k.to_s)}
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
selector = @group.selector
|
42
42
|
identifier = @group.identifiers.inject({}){|h, k| h[k] = @object.send(k); h}
|
43
|
-
|
43
|
+
|
44
44
|
hash.merge({:__selector__ => selector, :__identifier__ => identifier})
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def to_tag(options = {})
|
48
|
-
|
49
|
-
attrs = []
|
50
|
-
|
48
|
+
attrs = []
|
51
49
|
default = @group.identifiers.size == 1 ? @object.send(@group.identifiers.first) : @object.attributes.values_at(*@group.identifiers).inspect
|
52
50
|
value = @object.send(@group.value)
|
53
|
-
|
51
|
+
|
54
52
|
if Engine.can_render_metadata?
|
55
53
|
default = "< #{default} >"
|
56
54
|
keys = @group.keys << @group.value.to_s
|
57
55
|
data = @object.attributes.reject{|k, v| !keys.include?(k.to_s)}
|
58
56
|
|
59
57
|
data[:editable_input_type] = options[:as] if %w(string text html).include? options[:as].to_s.downcase
|
60
|
-
|
58
|
+
|
61
59
|
if class_name = @group.selector.match(/^\.\w+$/)
|
62
60
|
(options[:html] ||= {}).store :class, [class_name.to_s.gsub(/^\./, ""), options[:html].try(:fetch, :class, nil)].compact.join(" ")
|
63
61
|
end
|
64
|
-
|
62
|
+
|
65
63
|
attrs << options[:html].collect{|k, v| "#{k}=\"#{::ERB::Util.html_escape v}\""}.join(" ") if options[:html]
|
66
64
|
attrs << data .collect{|k, v| "data-#{k}=\"#{::ERB::Util.html_escape v}\""}.join(" ")
|
67
65
|
end
|
68
|
-
|
69
|
-
|
66
|
+
|
67
|
+
tag = options[:tag] || @group.tag || (%w(text html).include?(data.try :fetch, :editable_input_type, nil) ? :div : :span)
|
68
|
+
|
69
|
+
"<#{tag} #{attrs.join(" ")}>#{value.blank? ? default : value}</#{tag}>".html_safe
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "core", "string.rb")
|