spontaneous 0.2.0.alpha7 → 0.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -4
- data/Readme.markdown +1 -1
- data/application/css/definitions.css.scss +5 -0
- data/application/css/dialogue.css.scss +62 -0
- data/application/js/content.js +1 -1
- data/application/js/dom.js +1 -1
- data/application/js/event_source.js +3 -0
- data/application/js/{field_types/date_field.js → field/date.js} +2 -2
- data/application/js/{field_types/file_field.js → field/file.js} +2 -2
- data/application/js/{field_types/image_field.js → field/image.js} +54 -20
- data/application/js/{field_types/long_string_field.js → field/long_string.js} +2 -2
- data/application/js/{field_types/markdown_field.js → field/markdown.js} +2 -2
- data/application/js/{field_types/select_field.js → field/select.js} +2 -2
- data/application/js/{field_types/string_field.js → field/string.js} +21 -7
- data/application/js/{field_types/webvideo_field.js → field/webvideo.js} +2 -2
- data/application/js/field.js +2 -2
- data/application/js/publish.js +99 -19
- data/application/js/spontaneous.js +8 -8
- data/application/js/top_bar.js +6 -4
- data/db/migrations/20130109125023_add_page_publish_lock.rb +17 -0
- data/db/migrations/20130111161934_convert_bcrypt_passwords.rb +22 -0
- data/db/migrations/20130114120000_create_revision_tables.rb +106 -0
- data/db/migrations/20130116220423_add_index_to_archive.rb +9 -0
- data/lib/spontaneous/box.rb +53 -18
- data/lib/spontaneous/box_style.rb +2 -3
- data/lib/spontaneous/change.rb +39 -13
- data/lib/spontaneous/cli/fields.rb +29 -0
- data/lib/spontaneous/cli/init.rb +2 -2
- data/lib/spontaneous/cli/migrate.rb +0 -1
- data/lib/spontaneous/cli/server.rb +14 -10
- data/lib/spontaneous/cli/site.rb +20 -9
- data/lib/spontaneous/cli.rb +8 -6
- data/lib/spontaneous/collections/box_set.rb +11 -0
- data/lib/spontaneous/collections/field_set.rb +24 -1
- data/lib/spontaneous/concern.rb +37 -0
- data/lib/spontaneous/config.rb +3 -4
- data/lib/spontaneous/crypt/version.rb +130 -0
- data/lib/spontaneous/crypt.rb +84 -0
- data/lib/spontaneous/data_mapper/content_model/associations.rb +199 -0
- data/lib/spontaneous/data_mapper/content_model/column_accessors.rb +52 -0
- data/lib/spontaneous/data_mapper/content_model/instance_hooks.rb +34 -0
- data/lib/spontaneous/data_mapper/content_model/serialization.rb +54 -0
- data/lib/spontaneous/data_mapper/content_model/timestamps.rb +39 -0
- data/lib/spontaneous/data_mapper/content_model.rb +343 -0
- data/lib/spontaneous/data_mapper/content_table.rb +103 -0
- data/lib/spontaneous/data_mapper/dataset.rb +194 -0
- data/lib/spontaneous/data_mapper/scope.rb +195 -0
- data/lib/spontaneous/data_mapper.rb +161 -0
- data/lib/spontaneous/facet.rb +2 -2
- data/lib/spontaneous/field/base.rb +418 -0
- data/lib/spontaneous/field/date.rb +54 -0
- data/lib/spontaneous/{field_version.rb → field/field_version.rb} +1 -1
- data/lib/spontaneous/field/file.rb +100 -0
- data/lib/spontaneous/{field_types/image_field.rb → field/image.rb} +33 -33
- data/lib/spontaneous/{field_types/location_field.rb → field/location.rb} +2 -2
- data/lib/spontaneous/{field_types/long_string_field.rb → field/long_string.rb} +3 -3
- data/lib/spontaneous/field/markdown.rb +36 -0
- data/lib/spontaneous/{field_types/select_field.rb → field/select.rb} +4 -5
- data/lib/spontaneous/field/string.rb +17 -0
- data/lib/spontaneous/field/update.rb +156 -0
- data/lib/spontaneous/field/webvideo.rb +310 -0
- data/lib/spontaneous/field.rb +80 -0
- data/lib/spontaneous/generators/site/Gemfile.tt +2 -2
- data/lib/spontaneous/generators/site/config/environments/development.rb.tt +1 -1
- data/lib/spontaneous/generators/site/config/environments/production.rb.tt +1 -1
- data/lib/spontaneous/generators/site/lib/content.rb.tt +6 -0
- data/lib/spontaneous/generators/site/schema/box.rb.tt +3 -2
- data/lib/spontaneous/generators/site/schema/page.rb.tt +3 -1
- data/lib/spontaneous/generators/site/schema/piece.rb.tt +3 -1
- data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +3 -1
- data/lib/spontaneous/generators/site.rb +4 -3
- data/lib/spontaneous/image_size.rb +8 -1
- data/lib/spontaneous/layout.rb +5 -1
- data/lib/spontaneous/loader.rb +2 -5
- data/lib/spontaneous/media/file.rb +11 -2
- data/lib/spontaneous/media/temp_file.rb +23 -0
- data/lib/spontaneous/media.rb +20 -39
- data/lib/spontaneous/{plugins → model/box}/allowed_types.rb +38 -17
- data/lib/spontaneous/model/box.rb +18 -0
- data/lib/spontaneous/{plugins → model/core}/aliases.rb +10 -14
- data/lib/spontaneous/{plugins → model/core}/boxes.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/content_groups.rb +2 -2
- data/lib/spontaneous/model/core/editor_class.rb +4 -0
- data/lib/spontaneous/{plugins → model/core}/entries.rb +19 -7
- data/lib/spontaneous/{plugins → model/core}/entry.rb +3 -3
- data/lib/spontaneous/{plugins → model/core}/fields.rb +38 -5
- data/lib/spontaneous/{plugins → model/core}/instance_code.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/media.rb +2 -12
- data/lib/spontaneous/{plugins → model/core}/modifications.rb +7 -6
- data/lib/spontaneous/model/core/page_search.rb +36 -0
- data/lib/spontaneous/{plugins → model/core}/permissions.rb +4 -4
- data/lib/spontaneous/{plugins → model/core}/prototypes.rb +4 -4
- data/lib/spontaneous/{plugins → model/core}/publishing.rb +93 -115
- data/lib/spontaneous/{plugins → model/core}/render.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/schema_hierarchy.rb +7 -11
- data/lib/spontaneous/model/core/schema_id.rb +65 -0
- data/lib/spontaneous/{plugins → model/core}/schema_title.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/serialisation.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/styles.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/supertype.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/visibility.rb +7 -48
- data/lib/spontaneous/model/core.rb +143 -0
- data/lib/spontaneous/{plugins → model/page}/controllers.rb +3 -3
- data/lib/spontaneous/{plugins → model}/page/formats.rb +2 -2
- data/lib/spontaneous/{plugins → model/page}/layouts.rb +2 -2
- data/lib/spontaneous/model/page/locks.rb +14 -0
- data/lib/spontaneous/{plugins → model/page}/page_tree.rb +3 -3
- data/lib/spontaneous/{plugins → model/page}/paths.rb +30 -12
- data/lib/spontaneous/{plugins → model}/page/request.rb +2 -2
- data/lib/spontaneous/{plugins → model/page}/site_map.rb +2 -2
- data/lib/spontaneous/model/page/site_timestamps.rb +44 -0
- data/lib/spontaneous/{page.rb → model/page.rb} +49 -28
- data/lib/spontaneous/{piece.rb → model/piece.rb} +7 -6
- data/lib/spontaneous/model.rb +97 -0
- data/lib/spontaneous/output/context.rb +1 -1
- data/lib/spontaneous/output/format.rb +4 -0
- data/lib/spontaneous/output/template/renderer.rb +2 -2
- data/lib/spontaneous/output.rb +2 -2
- data/lib/spontaneous/page_lock.rb +62 -0
- data/lib/spontaneous/page_piece.rb +1 -1
- data/lib/spontaneous/permissions/access_key.rb +9 -4
- data/lib/spontaneous/permissions/user.rb +19 -9
- data/lib/spontaneous/permissions.rb +2 -5
- data/lib/spontaneous/plugins/application/facets.rb +1 -2
- data/lib/spontaneous/plugins/application/features.rb +1 -1
- data/lib/spontaneous/plugins/application/paths.rb +1 -1
- data/lib/spontaneous/plugins/application/render.rb +1 -1
- data/lib/spontaneous/plugins/application/serialisation.rb +1 -1
- data/lib/spontaneous/plugins/application/state.rb +30 -1
- data/lib/spontaneous/plugins/application/system.rb +12 -12
- data/lib/spontaneous/prototypes/box_prototype.rb +1 -1
- data/lib/spontaneous/prototypes/field_prototype.rb +3 -6
- data/lib/spontaneous/prototypes/style_prototype.rb +1 -1
- data/lib/spontaneous/publishing/immediate.rb +77 -49
- data/lib/spontaneous/publishing/revision.rb +355 -0
- data/lib/spontaneous/publishing/simultaneous.rb +10 -49
- data/lib/spontaneous/publishing.rb +1 -0
- data/lib/spontaneous/rack/around_back.rb +1 -1
- data/lib/spontaneous/rack/around_front.rb +2 -4
- data/lib/spontaneous/rack/around_preview.rb +1 -1
- data/lib/spontaneous/rack/back.rb +80 -63
- data/lib/spontaneous/rack/cacheable_file.rb +2 -2
- data/lib/spontaneous/rack/cookie_authentication.rb +1 -1
- data/lib/spontaneous/rack/front.rb +1 -1
- data/lib/spontaneous/rack/helpers.rb +8 -9
- data/lib/spontaneous/{page_controller.rb → rack/page_controller.rb} +1 -1
- data/lib/spontaneous/rack/public.rb +3 -3
- data/lib/spontaneous/rack.rb +15 -15
- data/lib/spontaneous/schema/uid.rb +4 -1
- data/lib/spontaneous/schema.rb +57 -24
- data/lib/spontaneous/search/database.rb +12 -1
- data/lib/spontaneous/search/index.rb +34 -6
- data/lib/spontaneous/search/results.rb +1 -1
- data/lib/spontaneous/server.rb +3 -3
- data/lib/spontaneous/simultaneous.rb +53 -0
- data/lib/spontaneous/{plugins/site → site}/features.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/helpers.rb +2 -3
- data/lib/spontaneous/{plugins/site → site}/hooks.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/instance.rb +4 -6
- data/lib/spontaneous/{plugins/site → site}/level.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/map.rb +4 -4
- data/lib/spontaneous/{plugins/site → site}/paths.rb +2 -2
- data/lib/spontaneous/site/publishing.rb +89 -0
- data/lib/spontaneous/{plugins/site → site}/schema.rb +4 -4
- data/lib/spontaneous/{plugins/site → site}/search.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/selectors.rb +15 -7
- data/lib/spontaneous/{plugins/site → site}/state.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/storage.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/url.rb +2 -2
- data/lib/spontaneous/site.rb +31 -14
- data/lib/spontaneous/state.rb +5 -6
- data/lib/spontaneous/style.rb +3 -2
- data/lib/spontaneous/utils/database/mysql_dumper.rb +13 -0
- data/lib/spontaneous/utils/database/postgres_dumper.rb +5 -0
- data/lib/spontaneous/version.rb +1 -1
- data/lib/spontaneous.rb +34 -89
- data/spontaneous.gemspec +112 -114
- data/test/experimental/test_crypt.rb +158 -0
- data/test/experimental/test_features.rb +3 -3
- data/test/fixtures/example_application/config/environments/development.rb +1 -1
- data/test/fixtures/example_application/lib/content.rb +5 -0
- data/test/fixtures/example_application/schema/page.rb +2 -1
- data/test/fixtures/example_application/schema/piece.rb +3 -2
- data/test/fixtures/serialisation/class_hash.yaml.erb +5 -5
- data/test/fixtures/serialisation/root_hash.yaml.erb +8 -0
- data/test/functional/test_application.rb +12 -1
- data/test/functional/test_back.rb +80 -48
- data/test/functional/test_front.rb +39 -46
- data/test/functional/test_user_manager.rb +3 -9
- data/test/javascript/test_markdown.rb +2 -2
- data/test/test_helper.rb +78 -23
- data/test/unit/test_alias.rb +21 -15
- data/test/unit/test_asset_bundler.rb +3 -3
- data/test/unit/test_assets.rb +2 -2
- data/test/unit/test_async.rb +7 -6
- data/test/unit/test_authentication.rb +43 -37
- data/test/unit/test_boxes.rb +46 -21
- data/test/unit/test_changesets.rb +65 -20
- data/test/unit/test_config.rb +9 -9
- data/test/unit/test_content.rb +50 -51
- data/test/unit/test_content_inheritance.rb +6 -20
- data/test/unit/test_datamapper.rb +1330 -0
- data/test/unit/test_datamapper_content.rb +214 -0
- data/test/unit/test_fields.rb +543 -54
- data/test/unit/test_formats.rb +2 -3
- data/test/unit/test_generators.rb +6 -6
- data/test/unit/test_helpers.rb +1 -1
- data/test/unit/test_image_size.rb +10 -5
- data/test/unit/test_images.rb +17 -18
- data/test/unit/test_layouts.rb +18 -3
- data/test/unit/test_media.rb +74 -49
- data/test/unit/test_modifications.rb +43 -43
- data/test/unit/test_page.rb +7 -10
- data/test/unit/test_permissions.rb +3 -10
- data/test/unit/test_piece.rb +5 -6
- data/test/unit/test_plugins.rb +7 -14
- data/test/unit/test_prototypes.rb +3 -3
- data/test/unit/test_publishing.rb +49 -27
- data/test/unit/test_render.rb +46 -15
- data/test/unit/test_revisions.rb +124 -127
- data/test/unit/test_schema.rb +53 -58
- data/test/unit/test_search.rb +64 -16
- data/test/unit/test_serialisation.rb +4 -11
- data/test/unit/test_site.rb +11 -12
- data/test/unit/test_structure.rb +2 -5
- data/test/unit/test_styles.rb +22 -24
- data/test/unit/test_type_hierarchy.rb +7 -5
- data/test/unit/test_visibility.rb +79 -55
- metadata +128 -102
- data/lib/sequel/plugins/content_table_inheritance.rb +0 -203
- data/lib/sequel/plugins/scoped_table_name.rb +0 -54
- data/lib/spontaneous/content.rb +0 -129
- data/lib/spontaneous/field_types/date_field.rb +0 -56
- data/lib/spontaneous/field_types/field.rb +0 -302
- data/lib/spontaneous/field_types/file_field.rb +0 -68
- data/lib/spontaneous/field_types/markdown_field.rb +0 -38
- data/lib/spontaneous/field_types/string_field.rb +0 -19
- data/lib/spontaneous/field_types/webvideo_field.rb +0 -313
- data/lib/spontaneous/field_types.rb +0 -38
- data/lib/spontaneous/generators/site/lib/site.rb.tt +0 -4
- data/lib/spontaneous/plugins/field/editor_class.rb +0 -13
- data/lib/spontaneous/plugins/page/site_timestamps.rb +0 -28
- data/lib/spontaneous/plugins/page_search.rb +0 -63
- data/lib/spontaneous/plugins/schema_id.rb +0 -68
- data/lib/spontaneous/plugins/site/publishing.rb +0 -75
- data/lib/spontaneous/rack/fiber_pool.rb +0 -26
- data/test/unit/test_table_scoping.rb +0 -80
data/lib/spontaneous/content.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("../../sequel/plugins/content_table_inheritance", __FILE__)
|
4
|
-
|
5
|
-
module Spontaneous
|
6
|
-
class Content < Sequel::Model(:content)
|
7
|
-
class << self
|
8
|
-
alias_method :sequel_plugin, :plugin unless method_defined?(:sequel_plugin)
|
9
|
-
end
|
10
|
-
|
11
|
-
alias_method :each_attribute, :each
|
12
|
-
|
13
|
-
# need to load this first because it's used by the ContentTableInheritance plugin
|
14
|
-
include Plugins::SchemaId
|
15
|
-
|
16
|
-
sequel_plugin :content_table_inheritance, :type_sid
|
17
|
-
sequel_plugin :serialization, :ojson, :field_store, :entry_store, :box_store, :serialized_modifications
|
18
|
-
sequel_plugin :instance_hooks
|
19
|
-
sequel_plugin :skip_create_refresh
|
20
|
-
sequel_plugin :timestamps, :create=>:created_at, :update_on_create => true
|
21
|
-
sequel_plugin :identity_map
|
22
|
-
sequel_plugin :association_dependencies
|
23
|
-
sequel_plugin :defaults_setter
|
24
|
-
sequel_plugin :scoped_table_name
|
25
|
-
|
26
|
-
# overwrite the sequel version defined in IdentityMap to support
|
27
|
-
# revisions
|
28
|
-
def self.identity_map_key(pk)
|
29
|
-
"#{super}:#{revision}"
|
30
|
-
end
|
31
|
-
|
32
|
-
# must resolve my is_*? schizophrenia
|
33
|
-
def self.page?
|
34
|
-
false
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.is_page?
|
38
|
-
page?
|
39
|
-
end
|
40
|
-
|
41
|
-
many_to_one :owner, :key => :owner_id, :class => Content, :reciprocal => :_pieces
|
42
|
-
one_to_many :_pieces, :key => :owner_id, :class => Content, :reciprocal => :owner
|
43
|
-
many_to_one :page, :key => :page_id, :class => Content, :reciprocal => :content
|
44
|
-
many_to_one :created_by, :key => :created_by_id, :class => Spontaneous::Permissions::User
|
45
|
-
|
46
|
-
include Enumerable
|
47
|
-
|
48
|
-
include Plugins::Entry
|
49
|
-
include Plugins::Boxes
|
50
|
-
include Plugins::Fields
|
51
|
-
include Plugins::Entries
|
52
|
-
include Plugins::Styles
|
53
|
-
include Plugins::SchemaTitle
|
54
|
-
include Plugins::Render
|
55
|
-
include Plugins::SchemaHierarchy
|
56
|
-
include Plugins::InstanceCode
|
57
|
-
include Plugins::Serialisation
|
58
|
-
include Plugins::Media
|
59
|
-
include Plugins::Publishing
|
60
|
-
include Plugins::Modifications
|
61
|
-
include Plugins::Aliases
|
62
|
-
include Plugins::Visibility
|
63
|
-
include Plugins::Prototypes
|
64
|
-
include Plugins::Permissions
|
65
|
-
include Plugins::ContentGroups
|
66
|
-
|
67
|
-
# marker method enabling a simple test for "cms content" vs "everything else"
|
68
|
-
def spontaneous_content?
|
69
|
-
true
|
70
|
-
end
|
71
|
-
|
72
|
-
def alias?
|
73
|
-
false
|
74
|
-
end
|
75
|
-
|
76
|
-
# Provides consistency between aliases & non-aliases
|
77
|
-
# so that a mixed list of both can be treated the same
|
78
|
-
# (for instance when ensuring uniqueness)
|
79
|
-
def target
|
80
|
-
self
|
81
|
-
end
|
82
|
-
|
83
|
-
def page?
|
84
|
-
false
|
85
|
-
end
|
86
|
-
alias_method :is_page?, :page?
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# terminate the supertype chain here
|
91
|
-
def self.supertype
|
92
|
-
nil
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.supertype?
|
96
|
-
!supertype.nil?
|
97
|
-
end
|
98
|
-
|
99
|
-
def start_inline_edit_marker
|
100
|
-
"spontaneous:previewedit:start:content id:#{id}"
|
101
|
-
end
|
102
|
-
|
103
|
-
def end_inline_edit_marker
|
104
|
-
"spontaneous:previewedit:end:content id:#{id}"
|
105
|
-
end
|
106
|
-
|
107
|
-
def to_s
|
108
|
-
%(#<#{self.class.name} id=#{id}>)
|
109
|
-
end
|
110
|
-
|
111
|
-
def each
|
112
|
-
iterable.each do |i|
|
113
|
-
yield i if block_given?
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def formats
|
118
|
-
return page.formats if page
|
119
|
-
[:html]
|
120
|
-
end
|
121
|
-
|
122
|
-
def log_sql(io = $stdout)
|
123
|
-
db.logger = ::Logger.new(io)
|
124
|
-
yield if block_given?
|
125
|
-
ensure
|
126
|
-
db.logger = nil
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module Spontaneous
|
4
|
-
module FieldTypes
|
5
|
-
class DateField < Field
|
6
|
-
include Spontaneous::Plugins::Field::EditorClass
|
7
|
-
|
8
|
-
DEFAULT_FORMAT = "%A, %-d %B, %Y"
|
9
|
-
|
10
|
-
def self.export(user)
|
11
|
-
super.merge({
|
12
|
-
:date_format => prototype.options[:format] || DEFAULT_FORMAT
|
13
|
-
})
|
14
|
-
end
|
15
|
-
|
16
|
-
def value(output = :html, *args)
|
17
|
-
return date if date.is_a?(String)
|
18
|
-
case output
|
19
|
-
when :html
|
20
|
-
date.strftime(html_format)
|
21
|
-
else
|
22
|
-
date.strftime(format)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def outputs
|
27
|
-
[:julian]
|
28
|
-
end
|
29
|
-
|
30
|
-
def preprocess(value)
|
31
|
-
return value if value.blank?
|
32
|
-
Date.parse(value)
|
33
|
-
end
|
34
|
-
|
35
|
-
def html_format
|
36
|
-
%(<time datetime="%Y-%m-%d">#{ format }</time>)
|
37
|
-
end
|
38
|
-
|
39
|
-
def generate_julian(date)
|
40
|
-
return date.jd if date.is_a?(Date)
|
41
|
-
date.to_s
|
42
|
-
end
|
43
|
-
|
44
|
-
def date
|
45
|
-
return "" if values[:julian].blank?
|
46
|
-
Date.jd values[:julian].to_i
|
47
|
-
end
|
48
|
-
|
49
|
-
def format
|
50
|
-
prototype.options[:format] || DEFAULT_FORMAT
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
DateField.register
|
55
|
-
end
|
56
|
-
end
|
@@ -1,302 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
module Spontaneous
|
5
|
-
module FieldTypes
|
6
|
-
class Field
|
7
|
-
extend Plugins
|
8
|
-
|
9
|
-
def self.register(*labels)
|
10
|
-
labels = self.labels if labels.empty?
|
11
|
-
# logger.debug("Registering #{self} as #{labels.join(", ")}")
|
12
|
-
FieldTypes.register(self, *labels)
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.labels
|
17
|
-
[self.name.demodulize.gsub(/Field$/, '').underscore]
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.inherited(subclass, real_caller = nil)
|
21
|
-
if self.respond_to?(:editor_class)
|
22
|
-
editor_class = self.editor_class
|
23
|
-
subclass.singleton_class.send(:define_method, :editor_class) do
|
24
|
-
editor_class
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.prototype=(prototype)
|
30
|
-
@prototype = prototype
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.prototype
|
34
|
-
@prototype
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.accepts
|
38
|
-
%w(text/.+)
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.accepts?(mime_type)
|
42
|
-
accepts.find do |pattern|
|
43
|
-
Regexp.new(pattern).match(mime_type)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
# Provides the ability for specific field types to customize the schema values
|
49
|
-
# they return to the UI
|
50
|
-
def self.export(user)
|
51
|
-
{}
|
52
|
-
end
|
53
|
-
|
54
|
-
attr_accessor :owner, :name, :unprocessed_value, :template_params, :version
|
55
|
-
attr_reader :processed_values
|
56
|
-
|
57
|
-
alias_method :values, :processed_values
|
58
|
-
|
59
|
-
|
60
|
-
def initialize(params={}, from_db=false)
|
61
|
-
@processed_values = {}
|
62
|
-
load(params, from_db)
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
def outputs
|
67
|
-
[:html, :plain]
|
68
|
-
end
|
69
|
-
|
70
|
-
def unprocessed_value=(v)
|
71
|
-
set_unprocessed_value(v)
|
72
|
-
unless @preprocessed
|
73
|
-
@modified = (@initial_value != v)
|
74
|
-
increment_version if @modified
|
75
|
-
self.processed_values = generate_outputs(@unprocessed_value)
|
76
|
-
owner.field_modified!(self) if owner
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def increment_version
|
81
|
-
self.version += 1
|
82
|
-
end
|
83
|
-
|
84
|
-
def version
|
85
|
-
@version ||= 0
|
86
|
-
end
|
87
|
-
|
88
|
-
# value used to show conflicts between the current value and the value they're attempting to enter
|
89
|
-
def conflicted_value
|
90
|
-
unprocessed_value
|
91
|
-
end
|
92
|
-
|
93
|
-
def generate_outputs(value)
|
94
|
-
values = {}
|
95
|
-
value = preprocess(value)
|
96
|
-
outputs.each do |output|
|
97
|
-
process_method = "generate_#{output}"
|
98
|
-
values[output] = \
|
99
|
-
if respond_to?(process_method)
|
100
|
-
send(process_method, value)
|
101
|
-
else
|
102
|
-
generate(output, value)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
values
|
106
|
-
end
|
107
|
-
|
108
|
-
# should be overwritten in subclasses that actually do something
|
109
|
-
# with the field value
|
110
|
-
def preprocess(value)
|
111
|
-
value
|
112
|
-
end
|
113
|
-
|
114
|
-
HTML_ESCAPE_TABLE = {
|
115
|
-
'&' => '&'
|
116
|
-
}
|
117
|
-
|
118
|
-
def escape_html(value)
|
119
|
-
value.to_s.gsub(%r{[#{HTML_ESCAPE_TABLE.keys.join}]}) { |s| HTML_ESCAPE_TABLE[s] }
|
120
|
-
end
|
121
|
-
|
122
|
-
def generate(output, value)
|
123
|
-
value
|
124
|
-
end
|
125
|
-
|
126
|
-
# attr_accessor :values
|
127
|
-
|
128
|
-
# override this to return custom values derived from (un)processed_value
|
129
|
-
# alias_method :value, :processed_value
|
130
|
-
def value(format=:html)
|
131
|
-
processed_values[format.to_sym] || unprocessed_value
|
132
|
-
end
|
133
|
-
alias_method :processed_value, :value
|
134
|
-
|
135
|
-
def image?
|
136
|
-
false
|
137
|
-
end
|
138
|
-
|
139
|
-
def indexable_value
|
140
|
-
unprocessed_value
|
141
|
-
end
|
142
|
-
|
143
|
-
def to_s(format = :html)
|
144
|
-
value(format).to_s
|
145
|
-
end
|
146
|
-
|
147
|
-
def render(format=:html, *args)
|
148
|
-
value(format)
|
149
|
-
end
|
150
|
-
|
151
|
-
def to_html(*args)
|
152
|
-
render(:html, *args)
|
153
|
-
end
|
154
|
-
|
155
|
-
def to_pdf(*args)
|
156
|
-
render(:pdf, *args)
|
157
|
-
end
|
158
|
-
|
159
|
-
def value=(value)
|
160
|
-
self.unprocessed_value = value
|
161
|
-
end
|
162
|
-
|
163
|
-
def mark_unmodified
|
164
|
-
@modified = nil
|
165
|
-
end
|
166
|
-
|
167
|
-
def modified?
|
168
|
-
@modified
|
169
|
-
end
|
170
|
-
|
171
|
-
attr_accessor :prototype
|
172
|
-
# def prototype
|
173
|
-
# self.class.prototype
|
174
|
-
# end
|
175
|
-
|
176
|
-
def schema_id
|
177
|
-
self.prototype.schema_id
|
178
|
-
end
|
179
|
-
|
180
|
-
|
181
|
-
def schema_name
|
182
|
-
self.prototype.schema_name
|
183
|
-
end
|
184
|
-
|
185
|
-
def schema_owner
|
186
|
-
self.prototype.owner
|
187
|
-
end
|
188
|
-
|
189
|
-
def owner_sid
|
190
|
-
schema_owner.schema_id
|
191
|
-
end
|
192
|
-
|
193
|
-
def serialize_db
|
194
|
-
S::FieldTypes.serialize_field(self)
|
195
|
-
end
|
196
|
-
|
197
|
-
def update(params={})
|
198
|
-
params.each do |property, value|
|
199
|
-
setter = "#{property}=".to_sym
|
200
|
-
if respond_to?(setter)
|
201
|
-
self.send(setter, value)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
# def start_inline_edit_marker
|
207
|
-
# "spontaneous:previewedit:start:field id:#{owner.id} name:#{self.name}"
|
208
|
-
# end
|
209
|
-
# def end_inline_edit_marker
|
210
|
-
# "spontaneous:previewedit:end:field id:#{owner.id} name:#{self.name}"
|
211
|
-
# end
|
212
|
-
|
213
|
-
def export(user)
|
214
|
-
{
|
215
|
-
:name => name.to_s,
|
216
|
-
:id => schema_id.to_s,
|
217
|
-
:unprocessed_value => unprocessed_value,
|
218
|
-
:processed_value => ui_preview_value,
|
219
|
-
:version => version
|
220
|
-
}
|
221
|
-
end
|
222
|
-
|
223
|
-
def ui_preview_value
|
224
|
-
value(:html)
|
225
|
-
end
|
226
|
-
|
227
|
-
def inspect
|
228
|
-
%(#<#{self.class.name}:#{self.object_id} #{self.serialize_db.inspect}>)
|
229
|
-
end
|
230
|
-
|
231
|
-
def blank?
|
232
|
-
unprocessed_value.blank?
|
233
|
-
end
|
234
|
-
|
235
|
-
alias_method :empty?, :blank?
|
236
|
-
|
237
|
-
|
238
|
-
def or(field)
|
239
|
-
return field if self.blank?
|
240
|
-
self
|
241
|
-
end
|
242
|
-
|
243
|
-
alias_method :'/', :or
|
244
|
-
alias_method :'|', :or
|
245
|
-
|
246
|
-
def versions
|
247
|
-
owner.field_versions(self)
|
248
|
-
end
|
249
|
-
|
250
|
-
def previous_version
|
251
|
-
versions.first
|
252
|
-
end
|
253
|
-
|
254
|
-
def create_version
|
255
|
-
Spontaneous::FieldVersion.create(
|
256
|
-
:content_id => owner.id,
|
257
|
-
:field_sid => self.schema_id.to_s,
|
258
|
-
:version => version,
|
259
|
-
:value => @initial_value,
|
260
|
-
:user => owner.current_editor)
|
261
|
-
end
|
262
|
-
|
263
|
-
protected
|
264
|
-
|
265
|
-
def load(params={}, from_db=false)
|
266
|
-
with_preprocessed_values(from_db) do
|
267
|
-
params.each do |property, value|
|
268
|
-
setter = "#{property}=".to_sym
|
269
|
-
if respond_to?(setter)
|
270
|
-
self.send(setter, value)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
def processed_values=(values)
|
277
|
-
@processed_values = values
|
278
|
-
end
|
279
|
-
|
280
|
-
def with_preprocessed_values(state=true)
|
281
|
-
@preprocessed = state
|
282
|
-
yield
|
283
|
-
ensure
|
284
|
-
@preprocessed = nil
|
285
|
-
end
|
286
|
-
|
287
|
-
def set_unprocessed_value(new_value)
|
288
|
-
# initial_value should only be set once so that it can act as a test for field modification
|
289
|
-
@initial_value ||= new_value
|
290
|
-
@unprocessed_value = new_value
|
291
|
-
end
|
292
|
-
|
293
|
-
def method_missing(method, *args)
|
294
|
-
if outputs.include?(method)
|
295
|
-
value(method)
|
296
|
-
else
|
297
|
-
super
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'tempfile'
|
4
|
-
|
5
|
-
module Spontaneous::FieldTypes
|
6
|
-
class FileField < Field
|
7
|
-
include Spontaneous::Plugins::Field::EditorClass
|
8
|
-
|
9
|
-
def outputs
|
10
|
-
[:html, :filesize, :filename]
|
11
|
-
end
|
12
|
-
|
13
|
-
def preprocess(image_path)
|
14
|
-
filename = mimetype = nil
|
15
|
-
case image_path
|
16
|
-
when Hash
|
17
|
-
mimetype = image_path[:type]
|
18
|
-
filename = image_path[:filename]
|
19
|
-
image_path = image_path[:tempfile].path
|
20
|
-
when String
|
21
|
-
filename = ::File.basename(image_path)
|
22
|
-
end
|
23
|
-
return image_path unless File.exist?(image_path)
|
24
|
-
|
25
|
-
media_file = Spontaneous::Media::File.new(owner, filename, mimetype)
|
26
|
-
media_file.copy(image_path)
|
27
|
-
set_unprocessed_value(filename)
|
28
|
-
media_file
|
29
|
-
end
|
30
|
-
|
31
|
-
def generate_filesize(input)
|
32
|
-
if input.respond_to?(:filesize)
|
33
|
-
input.filesize
|
34
|
-
else
|
35
|
-
if ::File.exist?(input)
|
36
|
-
::File.size(input)
|
37
|
-
else
|
38
|
-
0
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def generate_filename(input)
|
44
|
-
if input.respond_to?(:filename)
|
45
|
-
input.filename
|
46
|
-
else
|
47
|
-
::File.basename(input.to_s)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def generate_html(input)
|
52
|
-
return input if input.is_a?(String)
|
53
|
-
input.url
|
54
|
-
end
|
55
|
-
|
56
|
-
def export(user = nil)
|
57
|
-
super(user).merge({
|
58
|
-
:processed_value => processed_values
|
59
|
-
})
|
60
|
-
end
|
61
|
-
|
62
|
-
def path
|
63
|
-
value(:html)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
FileField.register
|
68
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'kramdown'
|
4
|
-
|
5
|
-
module Spontaneous
|
6
|
-
module FieldTypes
|
7
|
-
class MarkdownField < Field
|
8
|
-
include Spontaneous::Plugins::Field::EditorClass
|
9
|
-
|
10
|
-
def outputs
|
11
|
-
[:html]
|
12
|
-
end
|
13
|
-
|
14
|
-
def generate_html(input)
|
15
|
-
input.to_html
|
16
|
-
end
|
17
|
-
|
18
|
-
def preprocess(input)
|
19
|
-
# convert lines ending with newlines into a <br/>
|
20
|
-
# as official Markdown syntax isn't suitable for
|
21
|
-
# casual users
|
22
|
-
# code taken from:
|
23
|
-
# http://github.github.com/github-flavored-markdown/
|
24
|
-
output = input.gsub(/^[\w\<][^\n]*\n+/) do |x|
|
25
|
-
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
|
26
|
-
end
|
27
|
-
|
28
|
-
# prevent foo_bar_baz from ending up with an italic word in the middle
|
29
|
-
output.gsub!(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/) do |x|
|
30
|
-
x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__'
|
31
|
-
end
|
32
|
-
Kramdown::Document.new(output)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
MarkdownField.register(:markdown, :text, :richtext)
|
37
|
-
end
|
38
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module Spontaneous
|
4
|
-
module FieldTypes
|
5
|
-
class StringField < Field
|
6
|
-
include Spontaneous::Plugins::Field::EditorClass
|
7
|
-
|
8
|
-
def preprocess(value)
|
9
|
-
Spontaneous::Utils::SmartQuotes.smarten(value.to_s)
|
10
|
-
end
|
11
|
-
|
12
|
-
def generate_html(value)
|
13
|
-
escape_html(value)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
StringField.register :string, :title
|
18
|
-
end
|
19
|
-
end
|