myobie-turbine-core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/turbine-core/importers/hash_importer.rb +14 -0
- data/lib/turbine-core/importers/json_importer.rb +4 -0
- data/lib/turbine-core/importers/{text_importer.rb → string_importer.rb} +1 -1
- data/lib/turbine-core/post_type.rb +38 -21
- data/lib/turbine-core/types/photo.rb +13 -1
- data/lib/turbine-core.rb +1 -1
- metadata +4 -3
data/VERSION.yml
CHANGED
@@ -99,6 +99,7 @@ class PostType
|
|
99
99
|
].flatten.uniq
|
100
100
|
end
|
101
101
|
|
102
|
+
# TODO: when setting an attr, we should also run it's special block if it has one
|
102
103
|
def set_attr(key, value)
|
103
104
|
key = key.make_attr
|
104
105
|
|
@@ -125,8 +126,11 @@ class PostType
|
|
125
126
|
get_attr(key).blank?
|
126
127
|
end
|
127
128
|
|
128
|
-
|
129
|
+
def get_attr?(key)
|
130
|
+
!blank_attr?(key)
|
131
|
+
end
|
129
132
|
|
133
|
+
# TODO: get_attr should return a default if it's blank
|
130
134
|
def get_attr(key, html = true)
|
131
135
|
key = key.make_attr
|
132
136
|
|
@@ -182,7 +186,7 @@ class PostType
|
|
182
186
|
end
|
183
187
|
|
184
188
|
def self.get_pairs(text)
|
185
|
-
|
189
|
+
StringImporter.new(self).import(text)
|
186
190
|
end
|
187
191
|
|
188
192
|
def self.get_pairs_count(text, fields)
|
@@ -202,18 +206,8 @@ class PostType
|
|
202
206
|
end
|
203
207
|
|
204
208
|
def content=(stuff) # !> method redefined; discarding old content=
|
205
|
-
|
206
|
-
|
207
|
-
@content = { :type => self.class.name.to_s }
|
208
|
-
import(stuff)
|
209
|
-
eval_specials
|
210
|
-
eval_defaults
|
211
|
-
parse_tags unless blank_attr?(:tags)
|
212
|
-
generate_slug if get_attr?(:slug)
|
213
|
-
when Hash
|
214
|
-
@content = stuff.merge(:type => self.class.name.to_s)
|
215
|
-
end
|
216
|
-
|
209
|
+
@content = { :type => self.class.name.to_s }
|
210
|
+
import(stuff)
|
217
211
|
@content
|
218
212
|
end#of content=
|
219
213
|
|
@@ -229,9 +223,9 @@ class PostType
|
|
229
223
|
v
|
230
224
|
end
|
231
225
|
|
232
|
-
def initialize(
|
233
|
-
if
|
234
|
-
self.content =
|
226
|
+
def initialize(stuff = nil)
|
227
|
+
if stuff
|
228
|
+
self.content = stuff
|
235
229
|
# sanitize_content_fields
|
236
230
|
end
|
237
231
|
end
|
@@ -246,10 +240,8 @@ class PostType
|
|
246
240
|
end
|
247
241
|
end
|
248
242
|
|
249
|
-
|
250
|
-
|
251
|
-
set_attr(:__original, stuff)
|
252
|
-
importer = Kernel.const_get(type.to_s.camel_case+'Importer').new(self.class)
|
243
|
+
def import(stuff)
|
244
|
+
importer = Kernel.const_get(stuff.class.name+'Importer').new(self.class)
|
253
245
|
|
254
246
|
# The result sent back by an importer is either:
|
255
247
|
# Array:
|
@@ -264,6 +256,11 @@ class PostType
|
|
264
256
|
when Hash
|
265
257
|
commit_hash(result)
|
266
258
|
end
|
259
|
+
|
260
|
+
eval_specials # this won't be needed once the set_attr takes care of it
|
261
|
+
eval_defaults # this won't be needed once the get_attr takes care of it
|
262
|
+
parse_tags unless blank_attr?(:tags) # TODO: parse_tags needs to be turned into a special block
|
263
|
+
generate_slug if get_attr?(:slug) # TODO: generate_slug should be turned into a default block
|
267
264
|
end
|
268
265
|
|
269
266
|
def commit_hash(pairs_hash)
|
@@ -319,6 +316,8 @@ class PostType
|
|
319
316
|
end
|
320
317
|
|
321
318
|
def generate_slug # OPTIMIZE: this slug generation is ugly
|
319
|
+
return unless blank_attr?(:slug)
|
320
|
+
|
322
321
|
result = ''
|
323
322
|
|
324
323
|
unless self.class.always_use_uuid
|
@@ -366,4 +365,22 @@ class PostType
|
|
366
365
|
UUID.timestamp_create.to_s
|
367
366
|
end
|
368
367
|
|
368
|
+
def to_s
|
369
|
+
fields_to_parse = self.class.fields_list - [self.class.primary_field]
|
370
|
+
|
371
|
+
result = fields_to_parse.map do |field|
|
372
|
+
unless blank_attr?(field)
|
373
|
+
|
374
|
+
"#{field}: #{get_attr(field)}"
|
375
|
+
|
376
|
+
# TODO: make a way to override this like string_for :content { "hello" }
|
377
|
+
|
378
|
+
end#unless
|
379
|
+
end.join("\n") << "\n"
|
380
|
+
|
381
|
+
result << get_attr(self.class.primary_field, false)
|
382
|
+
|
383
|
+
result.strip
|
384
|
+
end
|
385
|
+
|
369
386
|
end
|
@@ -1,8 +1,20 @@
|
|
1
1
|
class Photo < PostType
|
2
|
-
fields :photo_url, :caption
|
2
|
+
fields :photo_url, :caption
|
3
3
|
required :photo_url
|
4
4
|
primary :caption
|
5
5
|
|
6
|
+
# special :photo_url do |photo_url_content|
|
7
|
+
# if photo_url_content.blank? && !blank_attr?(:caption)
|
8
|
+
# possible_url = get_attr(:caption).match(/^(http:\/\/.+)\n/)
|
9
|
+
# unless possible_url.blank?
|
10
|
+
# possible_url = possible_url.captures.first
|
11
|
+
# if %w(jpg gif png).include?(possible_url[-3..-1])
|
12
|
+
# set_attr :photo_url, possible_url
|
13
|
+
# end#if
|
14
|
+
# end#unless
|
15
|
+
# end#if
|
16
|
+
# end#special
|
17
|
+
|
6
18
|
def self.detect?(text)
|
7
19
|
has_required? text
|
8
20
|
end
|
data/lib/turbine-core.rb
CHANGED
@@ -3,6 +3,6 @@ require 'extlib'
|
|
3
3
|
|
4
4
|
include FileUtils
|
5
5
|
|
6
|
-
%w( ext importers/json_importer importers/
|
6
|
+
%w( ext importers/hash_importer importers/json_importer importers/string_importer post_type types/article types/audio types/chat types/link types/photo types/quote types/review types/video ).each do |file|
|
7
7
|
require "#{File.dirname(__FILE__)}/turbine-core/#{file}.rb"
|
8
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myobie-turbine-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Herald
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,8 +26,9 @@ files:
|
|
26
26
|
- VERSION.yml
|
27
27
|
- lib/turbine-core.rb
|
28
28
|
- lib/turbine-core/ext.rb
|
29
|
+
- lib/turbine-core/importers/hash_importer.rb
|
29
30
|
- lib/turbine-core/importers/json_importer.rb
|
30
|
-
- lib/turbine-core/importers/
|
31
|
+
- lib/turbine-core/importers/string_importer.rb
|
31
32
|
- lib/turbine-core/post_type.rb
|
32
33
|
- lib/turbine-core/types/article.rb
|
33
34
|
- lib/turbine-core/types/audio.rb
|