middleman-dato 0.5.12 → 0.5.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/lib/middleman_dato/client.rb +8 -8
- data/lib/middleman_dato/{record.rb → item.rb} +15 -14
- data/lib/middleman_dato/{records_repo.rb → items_repo.rb} +24 -24
- data/lib/middleman_dato/meta_tags/article_modified_time.rb +2 -2
- data/lib/middleman_dato/meta_tags/article_publisher.rb +1 -1
- data/lib/middleman_dato/meta_tags/base.rb +13 -13
- data/lib/middleman_dato/meta_tags/image.rb +1 -1
- data/lib/middleman_dato/meta_tags/og_type.rb +2 -2
- data/lib/middleman_dato/meta_tags/title.rb +2 -2
- data/lib/middleman_dato/middleman_extension.rb +15 -15
- data/lib/middleman_dato/{space.rb → site.rb} +7 -7
- data/lib/middleman_dato/version.rb +1 -1
- data/middleman-dato.gemspec +2 -2
- data/spec/middleman_dato/entities_repo_spec.rb +6 -6
- data/spec/middleman_dato/{record_spec.rb → item_spec.rb} +28 -28
- data/spec/middleman_dato/{records_repo_spec.rb → items_repo_spec.rb} +32 -32
- data/spec/middleman_dato/meta_tags/article_modified_time_spec.rb +5 -5
- data/spec/middleman_dato/meta_tags/image_spec.rb +4 -4
- data/spec/middleman_dato/meta_tags/og_locale_spec.rb +3 -3
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e514bf545d59aaa6843c2ee8d0259a36e8897b40
|
4
|
+
data.tar.gz: 78f3d9cdc1f73b51ab35b82f8e5c0930c1dd02a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2548e31a5d023fcf633b3b037fe330c1e3cc6de150920a94e17b0e532b79f28d038e66e724073ba152150981b7b04cf31776ec951dd3681a9ca48b6c33847f2a
|
7
|
+
data.tar.gz: c7888a2cadf22659e248f4031a04a00aaee8cb45be7ed9d080c2618540f8cecf748703a15e0029fca4804148872c516b79c8a5315a2a9651d37f3b454d0c150b
|
data/README.md
CHANGED
@@ -21,18 +21,18 @@ activate :dato,
|
|
21
21
|
|
22
22
|
### `dato`
|
23
23
|
|
24
|
-
Using this helper you can access to any
|
25
|
-
That is, if your
|
26
|
-
the complete array of
|
24
|
+
Using this helper you can access to any item stored in your site by item type.
|
25
|
+
That is, if your site has an Item Type with `article` as API identifier, you can get
|
26
|
+
the complete array of items with `dato.articles` (yep, the identifier pluralized).
|
27
27
|
|
28
|
-
If a
|
29
|
-
a call to `dato.about_page` directly returns the
|
28
|
+
If a Item Type is marked as Singleton (ie. `about_page`) you don't need to pluralize and
|
29
|
+
a call to `dato.about_page` directly returns the Item (or `nil`, if still hasn't been created
|
30
30
|
within the backend).
|
31
31
|
|
32
|
-
You can query any
|
32
|
+
You can query any Item field value with a method called like the field API identifier.
|
33
33
|
|
34
|
-
If a
|
35
|
-
returning a slugified version of the title itself (or the
|
34
|
+
If a Item Type has a String field with Title appeareance, than the item responds to `.slug`,
|
35
|
+
returning a slugified version of the title itself (or the item identifier, if the title is empty).
|
36
36
|
|
37
37
|
You can use this helper within Middleman `config.rb`, as well as within your views:
|
38
38
|
|
@@ -61,7 +61,7 @@ Please [refer to the code](https://github.com/datocms/middleman-dato/tree/master
|
|
61
61
|
|
62
62
|
### `dato_meta_tags`
|
63
63
|
|
64
|
-
This helper takes any
|
64
|
+
This helper takes any item with a SEO field and generates SEO, Facebook OpenGraph and Twitter card meta tags based on it:
|
65
65
|
|
66
66
|
```ruby
|
67
67
|
<%= dato_meta_tags(dato.homepage) %>
|
@@ -91,7 +91,7 @@ This helper takes any record with a SEO field and generates SEO, Facebook OpenGr
|
|
91
91
|
|
92
92
|
### `dato_favicon_meta_tags`
|
93
93
|
|
94
|
-
This helper generates meta tags based on the Favicon image specified within the
|
94
|
+
This helper generates meta tags based on the Favicon image specified within the Site:
|
95
95
|
|
96
96
|
```ruby
|
97
97
|
<%= dato_favicon_meta_tags(theme_color: '#D97C5F') %>
|
@@ -11,16 +11,16 @@ module MiddlemanDato
|
|
11
11
|
@token = token
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def site
|
15
15
|
include = [
|
16
|
-
'
|
17
|
-
'
|
16
|
+
'item_types',
|
17
|
+
'item_types.fields'
|
18
18
|
]
|
19
|
-
get('
|
19
|
+
get('site', include: include).body.with_indifferent_access
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
get('
|
22
|
+
def items
|
23
|
+
get('items', 'page[limit]' => 10_000).body.with_indifferent_access
|
24
24
|
end
|
25
25
|
|
26
26
|
def get(*args)
|
@@ -37,13 +37,13 @@ module MiddlemanDato
|
|
37
37
|
headers: {
|
38
38
|
'Content-Type' => 'application/json',
|
39
39
|
'Accept' => 'application/json',
|
40
|
-
'X-
|
40
|
+
'X-Site-Domain' => @domain,
|
41
41
|
'Authorization' => "Api-Key #{@token}"
|
42
42
|
}
|
43
43
|
}
|
44
44
|
@connection ||= Faraday.new(options) do |c|
|
45
45
|
c.request :json
|
46
|
-
c.response :json,
|
46
|
+
c.response :json, item_type: /\bjson$/
|
47
47
|
c.response :raise_error
|
48
48
|
c.adapter :net_http
|
49
49
|
end
|
@@ -7,24 +7,24 @@ Dir[File.dirname(__FILE__) + '/field_type/*.rb'].each do |file|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module MiddlemanDato
|
10
|
-
class
|
10
|
+
class Item
|
11
11
|
extend Forwardable
|
12
12
|
|
13
13
|
attr_reader :entity
|
14
|
-
def_delegators :entity, :id, :type, :
|
14
|
+
def_delegators :entity, :id, :type, :item_type
|
15
15
|
|
16
|
-
def initialize(entity,
|
16
|
+
def initialize(entity, items_repo)
|
17
17
|
@entity = entity
|
18
|
-
@
|
18
|
+
@items_repo = items_repo
|
19
19
|
end
|
20
20
|
|
21
|
-
def ==(
|
22
|
-
|
21
|
+
def ==(item)
|
22
|
+
item.is_a?(Item) && item.id == id
|
23
23
|
end
|
24
24
|
|
25
25
|
def slug
|
26
26
|
if singleton?
|
27
|
-
|
27
|
+
item_type.api_key.humanize.parameterize
|
28
28
|
elsif title_attribute
|
29
29
|
title = send(title_attribute)
|
30
30
|
if title
|
@@ -38,15 +38,16 @@ module MiddlemanDato
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def singleton?
|
41
|
-
|
41
|
+
item_type.singleton
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
45
|
-
@
|
44
|
+
def item_type
|
45
|
+
@item_type ||= entity.item_type
|
46
46
|
end
|
47
|
+
alias_method :content_type, :item_type
|
47
48
|
|
48
49
|
def fields
|
49
|
-
@fields ||=
|
50
|
+
@fields ||= item_type.fields.sort_by(&:position)
|
50
51
|
end
|
51
52
|
|
52
53
|
def attributes
|
@@ -66,8 +67,8 @@ module MiddlemanDato
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def to_s
|
69
|
-
api_key =
|
70
|
-
"#<
|
70
|
+
api_key = item_type.api_key
|
71
|
+
"#<Item id=#{id} item_type=#{api_key} attributes=#{attributes}>"
|
71
72
|
end
|
72
73
|
alias inspect to_s
|
73
74
|
|
@@ -102,7 +103,7 @@ module MiddlemanDato
|
|
102
103
|
entity.send(method)
|
103
104
|
end
|
104
105
|
|
105
|
-
value && type_klass.parse(value, @
|
106
|
+
value && type_klass.parse(value, @items_repo)
|
106
107
|
else
|
107
108
|
raise "Cannot convert field `#{method}` of type `#{field_type}`"
|
108
109
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'active_support/core_ext/string'
|
2
|
-
require 'middleman_dato/
|
2
|
+
require 'middleman_dato/item'
|
3
3
|
|
4
4
|
module MiddlemanDato
|
5
|
-
class
|
5
|
+
class ItemsRepo
|
6
6
|
attr_reader :entities_repo, :collections_by_type
|
7
7
|
|
8
8
|
def initialize(entities_repo)
|
9
9
|
@entities_repo = entities_repo
|
10
10
|
@collections_by_type = {}
|
11
|
-
@
|
11
|
+
@items_by_id = {}
|
12
12
|
|
13
13
|
build_cache!
|
14
14
|
end
|
15
15
|
|
16
16
|
def find(id)
|
17
|
-
@
|
17
|
+
@items_by_id[id]
|
18
18
|
end
|
19
19
|
|
20
20
|
def respond_to?(method, include_private = false)
|
@@ -27,9 +27,9 @@ module MiddlemanDato
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
31
|
-
api_key =
|
32
|
-
if
|
30
|
+
def item_type_key(item_type)
|
31
|
+
api_key = item_type.api_key
|
32
|
+
if item_type.singleton
|
33
33
|
[api_key.to_sym, true]
|
34
34
|
else
|
35
35
|
[api_key.pluralize.to_sym, false]
|
@@ -37,35 +37,35 @@ module MiddlemanDato
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def build_cache!
|
40
|
-
|
41
|
-
key, singleton =
|
40
|
+
item_type_entities.each do |item_type|
|
41
|
+
key, singleton = item_type_key(item_type)
|
42
42
|
@collections_by_type[key] = if singleton
|
43
43
|
nil
|
44
44
|
else
|
45
|
-
|
45
|
+
ItemCollection.new
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
item_entities.each do |item_entity|
|
50
|
+
item = Item.new(item_entity, self)
|
51
51
|
|
52
|
-
key, singleton =
|
52
|
+
key, singleton = item_type_key(item_entity.item_type)
|
53
53
|
if singleton
|
54
|
-
@collections_by_type[key] =
|
54
|
+
@collections_by_type[key] = item
|
55
55
|
else
|
56
|
-
@collections_by_type[key].push
|
56
|
+
@collections_by_type[key].push item
|
57
57
|
end
|
58
58
|
|
59
|
-
@
|
59
|
+
@items_by_id[item.id] = item
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
64
|
-
entities_repo.find_entities_of_type('
|
63
|
+
def item_type_entities
|
64
|
+
entities_repo.find_entities_of_type('item_type')
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
68
|
-
entities_repo.find_entities_of_type('
|
67
|
+
def item_entities
|
68
|
+
entities_repo.find_entities_of_type('item')
|
69
69
|
end
|
70
70
|
|
71
71
|
def method_missing(method, *arguments, &block)
|
@@ -76,11 +76,11 @@ module MiddlemanDato
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
class
|
79
|
+
class ItemCollection < Array
|
80
80
|
def each(&block)
|
81
81
|
if block && block.arity == 2
|
82
|
-
each_with_object({}) do |
|
83
|
-
acc[
|
82
|
+
each_with_object({}) do |item, acc|
|
83
|
+
acc[item.id] = item
|
84
84
|
end.each(&block)
|
85
85
|
else
|
86
86
|
super(&block)
|
@@ -89,7 +89,7 @@ module MiddlemanDato
|
|
89
89
|
|
90
90
|
def [](id)
|
91
91
|
if id.is_a? String
|
92
|
-
find { |
|
92
|
+
find { |item| item.id == id }
|
93
93
|
else
|
94
94
|
super(id)
|
95
95
|
end
|
@@ -5,7 +5,7 @@ module MiddlemanDato
|
|
5
5
|
module MetaTags
|
6
6
|
class ArticleModifiedTime < OgMetaTag
|
7
7
|
def buildable?
|
8
|
-
|
8
|
+
item && !item.singleton?
|
9
9
|
end
|
10
10
|
|
11
11
|
def name
|
@@ -13,7 +13,7 @@ module MiddlemanDato
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def value
|
16
|
-
|
16
|
+
item.updated_at.iso8601
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -4,17 +4,17 @@ require 'middleman_dato/field_type/seo'
|
|
4
4
|
module MiddlemanDato
|
5
5
|
module MetaTags
|
6
6
|
class Base
|
7
|
-
attr_reader :builder, :base_url, :
|
7
|
+
attr_reader :builder, :base_url, :site, :item_type, :item
|
8
8
|
|
9
|
-
def initialize(builder, base_url,
|
10
|
-
@
|
9
|
+
def initialize(builder, base_url, site, item)
|
10
|
+
@site = site
|
11
11
|
@base_url = base_url
|
12
|
-
@
|
12
|
+
@item = item
|
13
13
|
@builder = builder
|
14
14
|
end
|
15
15
|
|
16
16
|
def seo_field_with_fallback(attribute, alternative = nil, &block)
|
17
|
-
seo =
|
17
|
+
seo = first_item_field_of_type(:seo)
|
18
18
|
|
19
19
|
alternatives = []
|
20
20
|
|
@@ -33,21 +33,21 @@ module MiddlemanDato
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def no_index?
|
36
|
-
|
36
|
+
site && site.no_index
|
37
37
|
end
|
38
38
|
|
39
39
|
def global_seo_field(attribute)
|
40
40
|
global_seo[attribute] if global_seo
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
return nil unless
|
43
|
+
def first_item_field_of_type(type)
|
44
|
+
return nil unless item
|
45
45
|
|
46
|
-
field =
|
46
|
+
field = item.fields.detect do |f|
|
47
47
|
f.field_type == type.to_s
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
item.send(field.api_key) if field
|
51
51
|
end
|
52
52
|
|
53
53
|
def fallback_seo
|
@@ -58,9 +58,9 @@ module MiddlemanDato
|
|
58
58
|
|
59
59
|
def global_seo
|
60
60
|
@global_seo ||= begin
|
61
|
-
if
|
62
|
-
global_seo =
|
63
|
-
if
|
61
|
+
if site && site.global_seo
|
62
|
+
global_seo = site.global_seo
|
63
|
+
if site.locales.size > 1
|
64
64
|
global_seo[I18n.locale]
|
65
65
|
else
|
66
66
|
global_seo
|
@@ -2,16 +2,16 @@ require 'middleman-core'
|
|
2
2
|
require 'middleman-core/version'
|
3
3
|
require 'semantic'
|
4
4
|
require 'middleman_dato/meta_tags_builder'
|
5
|
-
require 'middleman_dato/
|
5
|
+
require 'middleman_dato/site'
|
6
6
|
require 'middleman_dato/meta_tags/favicon'
|
7
7
|
|
8
8
|
module MiddlemanDato
|
9
9
|
class MiddlemanExtension < ::Middleman::Extension
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :site
|
11
11
|
|
12
|
-
option :domain, nil, '
|
13
|
-
option :token, nil, '
|
14
|
-
option :api_host, 'http://api.datocms.com', '
|
12
|
+
option :domain, nil, 'Site domain'
|
13
|
+
option :token, nil, 'Site API token'
|
14
|
+
option :api_host, 'http://site-api.datocms.com', 'Site API host'
|
15
15
|
option :base_url, nil, 'Website base URL'
|
16
16
|
|
17
17
|
if Semantic::Version.new(Middleman::VERSION).major >= 4
|
@@ -21,11 +21,11 @@ module MiddlemanDato
|
|
21
21
|
def initialize(app, options_hash = {}, &block)
|
22
22
|
super
|
23
23
|
|
24
|
-
@
|
25
|
-
@
|
24
|
+
@site = site = MiddlemanDato::Site.new(options)
|
25
|
+
@site.refresh!
|
26
26
|
|
27
27
|
app.before do
|
28
|
-
|
28
|
+
site.refresh! if !build? && !ENV.fetch('DISABLE_DATO_REFRESH', false)
|
29
29
|
true
|
30
30
|
end
|
31
31
|
|
@@ -35,26 +35,26 @@ module MiddlemanDato
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def dato
|
38
|
-
|
38
|
+
site.items_repo
|
39
39
|
end
|
40
40
|
|
41
41
|
module InstanceMethods
|
42
42
|
def dato
|
43
|
-
extensions[:dato].
|
43
|
+
extensions[:dato].site.items_repo
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
helpers do
|
48
48
|
def dato
|
49
|
-
extensions[:dato].
|
49
|
+
extensions[:dato].site.items_repo
|
50
50
|
end
|
51
51
|
|
52
|
-
def dato_meta_tags(
|
52
|
+
def dato_meta_tags(item)
|
53
53
|
builder = MetaTagsBuilder.new(
|
54
54
|
self,
|
55
55
|
extensions[:dato].options[:base_url],
|
56
|
-
extensions[:dato].
|
57
|
-
|
56
|
+
extensions[:dato].site.entity,
|
57
|
+
item
|
58
58
|
)
|
59
59
|
builder.meta_tags
|
60
60
|
end
|
@@ -64,7 +64,7 @@ module MiddlemanDato
|
|
64
64
|
options[:app_name] ||= ''
|
65
65
|
favicon_builder = MetaTags::Favicon.new(
|
66
66
|
self,
|
67
|
-
extensions[:dato].
|
67
|
+
extensions[:dato].site.entity,
|
68
68
|
options[:theme_color]
|
69
69
|
)
|
70
70
|
favicon_builder.build
|
@@ -1,27 +1,27 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'middleman_dato/client'
|
3
3
|
require 'middleman_dato/entities_repo'
|
4
|
-
require 'middleman_dato/
|
4
|
+
require 'middleman_dato/items_repo'
|
5
5
|
|
6
6
|
module MiddlemanDato
|
7
|
-
class
|
7
|
+
class Site
|
8
8
|
attr_reader :options
|
9
9
|
attr_reader :entities_repo
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :items_repo
|
11
11
|
|
12
12
|
def initialize(options)
|
13
13
|
@options = options
|
14
14
|
@entities_repo = EntitiesRepo.new
|
15
|
-
@
|
15
|
+
@items_repo = ItemsRepo.new(@entities_repo)
|
16
16
|
end
|
17
17
|
|
18
18
|
def refresh!
|
19
|
-
@entities_repo = EntitiesRepo.new(client.
|
20
|
-
@
|
19
|
+
@entities_repo = EntitiesRepo.new(client.site, client.items)
|
20
|
+
@items_repo = ItemsRepo.new(@entities_repo)
|
21
21
|
end
|
22
22
|
|
23
23
|
def entity
|
24
|
-
@entities_repo.find_entities_of_type('
|
24
|
+
@entities_repo.find_entities_of_type('site').first
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
data/middleman-dato.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ['Stefano Verna']
|
10
10
|
s.email = ['s.verna@cantierecreativo.net']
|
11
11
|
s.homepage = 'http://cantierecreativo.net'
|
12
|
-
s.summary = 'Fetches data from a Dato
|
13
|
-
s.description = 'Fetches data from a Dato
|
12
|
+
s.summary = 'Fetches data from a Dato site'
|
13
|
+
s.description = 'Fetches data from a Dato site'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -8,32 +8,32 @@ module MiddlemanDato
|
|
8
8
|
context 'a payload with a data key' do
|
9
9
|
context 'object' do
|
10
10
|
let(:payload) do
|
11
|
-
{ data: { id: 'bar', type: '
|
11
|
+
{ data: { id: 'bar', type: 'item' } }
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'inserts the object into entities' do
|
15
|
-
expect(source.entities['
|
15
|
+
expect(source.entities['item']['bar']).to be_a JsonApiEntity
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'array' do
|
20
20
|
let(:payload) do
|
21
|
-
{ data: [{ id: 'bar', type: '
|
21
|
+
{ data: [{ id: 'bar', type: 'item' }] }
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'inserts the objects into entities' do
|
25
|
-
expect(source.entities['
|
25
|
+
expect(source.entities['item']['bar']).to be_a JsonApiEntity
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'a payload with an included key' do
|
31
31
|
let(:payload) do
|
32
|
-
{ included: [{ id: 'bar', type: '
|
32
|
+
{ included: [{ id: 'bar', type: 'item' }] }
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'inserts the objects into entities' do
|
36
|
-
expect(source.entities['
|
36
|
+
expect(source.entities['item']['bar']).to be_a JsonApiEntity
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module MiddlemanDato
|
2
|
-
RSpec.describe
|
3
|
-
subject(:
|
2
|
+
RSpec.describe Item do
|
3
|
+
subject(:item) { described_class.new(entity, repo) }
|
4
4
|
let(:entity) do
|
5
5
|
double(
|
6
|
-
'MiddlemanDato::JsonApiEntity(
|
6
|
+
'MiddlemanDato::JsonApiEntity(Item)',
|
7
7
|
id: '14',
|
8
|
-
|
8
|
+
item_type: item_type,
|
9
9
|
title: "My titlè with àccents",
|
10
10
|
body: 'Hi there',
|
11
11
|
position: 2,
|
@@ -13,9 +13,9 @@ module MiddlemanDato
|
|
13
13
|
)
|
14
14
|
end
|
15
15
|
let(:repo) do
|
16
|
-
instance_double('MiddlemanDato::
|
16
|
+
instance_double('MiddlemanDato::ItemsRepo')
|
17
17
|
end
|
18
|
-
let(:
|
18
|
+
let(:item_type) do
|
19
19
|
double(
|
20
20
|
'MiddlemanDato::JsonApiEntity(Content Type)',
|
21
21
|
singleton: is_singleton,
|
@@ -50,7 +50,7 @@ module MiddlemanDato
|
|
50
50
|
let(:is_singleton) { true }
|
51
51
|
|
52
52
|
it 'returns the parameterized content type api key' do
|
53
|
-
expect(
|
53
|
+
expect(item.slug).to eq 'work-item'
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -58,13 +58,13 @@ module MiddlemanDato
|
|
58
58
|
let(:fields) { [] }
|
59
59
|
|
60
60
|
it 'returns the ID' do
|
61
|
-
expect(
|
61
|
+
expect(item.slug).to eq '14'
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'non singleton, title field' do
|
66
66
|
it 'returns the ID + title' do
|
67
|
-
expect(
|
67
|
+
expect(item.slug).to eq '14-my-title-with-accents'
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -75,35 +75,35 @@ module MiddlemanDato
|
|
75
75
|
'title' => "My titlè with àccents",
|
76
76
|
'body' => 'Hi there'
|
77
77
|
}
|
78
|
-
expect(
|
78
|
+
expect(item.attributes).to eq expected_attributes
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe 'position' do
|
83
83
|
it 'returns the entity position field' do
|
84
|
-
expect(
|
84
|
+
expect(item.position).to eq 2
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
describe 'updated_at' do
|
89
89
|
it 'returns the entity updated_at field' do
|
90
|
-
expect(
|
90
|
+
expect(item.updated_at).to be_a Time
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
describe 'dynamic methods' do
|
95
95
|
context 'existing field' do
|
96
96
|
it 'returns the field value' do
|
97
|
-
expect(
|
98
|
-
expect(
|
97
|
+
expect(item.respond_to?(:body)).to be_truthy
|
98
|
+
expect(item.body).to eq 'Hi there'
|
99
99
|
end
|
100
100
|
|
101
101
|
context 'localized field' do
|
102
102
|
let(:entity) do
|
103
103
|
double(
|
104
|
-
'MiddlemanDato::JsonApiEntity(
|
104
|
+
'MiddlemanDato::JsonApiEntity(Item)',
|
105
105
|
id: '14',
|
106
|
-
|
106
|
+
item_type: item_type,
|
107
107
|
title: { it: 'Foo', en: 'Bar' }
|
108
108
|
)
|
109
109
|
end
|
@@ -123,14 +123,14 @@ module MiddlemanDato
|
|
123
123
|
|
124
124
|
it 'returns the value for the current locale' do
|
125
125
|
I18n.with_locale(:it) do
|
126
|
-
expect(
|
126
|
+
expect(item.title).to eq 'Foo'
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
130
|
context 'non existing value' do
|
131
131
|
it 'raises nil' do
|
132
132
|
I18n.with_locale(:ru) do
|
133
|
-
expect(
|
133
|
+
expect(item.title).to eq nil
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -139,8 +139,8 @@ module MiddlemanDato
|
|
139
139
|
|
140
140
|
context 'non existing field' do
|
141
141
|
it 'raises NoMethodError' do
|
142
|
-
expect(
|
143
|
-
expect {
|
142
|
+
expect(item.respond_to?(:qux)).to be_falsy
|
143
|
+
expect { item.qux }.to raise_error NoMethodError
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -158,30 +158,30 @@ module MiddlemanDato
|
|
158
158
|
end
|
159
159
|
|
160
160
|
it 'raises RuntimeError' do
|
161
|
-
expect {
|
161
|
+
expect { item.title }.to raise_error RuntimeError
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
166
|
context 'equality' do
|
167
|
-
subject(:
|
167
|
+
subject(:same_item) { described_class.new(entity, repo) }
|
168
168
|
|
169
|
-
subject(:
|
169
|
+
subject(:another_item) { described_class.new(another_entity, repo) }
|
170
170
|
let(:another_entity) do
|
171
171
|
double(
|
172
|
-
'MiddlemanDato::JsonApiEntity(
|
172
|
+
'MiddlemanDato::JsonApiEntity(Item)',
|
173
173
|
id: '15'
|
174
174
|
)
|
175
175
|
end
|
176
176
|
|
177
177
|
|
178
|
-
it 'two
|
179
|
-
expect(
|
178
|
+
it 'two items are equal if their id is the same' do
|
179
|
+
expect(item).to eq same_item
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'else they\'re not' do
|
183
|
-
expect(
|
184
|
-
expect(
|
183
|
+
expect(item).not_to eq another_item
|
184
|
+
expect(item).not_to eq "foobar"
|
185
185
|
end
|
186
186
|
end
|
187
187
|
end
|
@@ -1,67 +1,67 @@
|
|
1
|
-
require 'middleman_dato/
|
1
|
+
require 'middleman_dato/items_repo'
|
2
2
|
|
3
3
|
module MiddlemanDato
|
4
|
-
RSpec.describe
|
4
|
+
RSpec.describe ItemsRepo do
|
5
5
|
subject(:repo) { described_class.new(entities_repo) }
|
6
6
|
let(:entities_repo) do
|
7
7
|
instance_double('MiddlemanDato::EntitiesRepo')
|
8
8
|
end
|
9
|
-
let(:
|
9
|
+
let(:item_type) do
|
10
10
|
double('MiddlemanDato::JsonApiEntity', api_key: 'post', singleton: false)
|
11
11
|
end
|
12
|
-
let(:
|
12
|
+
let(:singleton_item_type) do
|
13
13
|
double('MiddlemanDato::JsonApiEntity', api_key: 'homepage', singleton: true)
|
14
14
|
end
|
15
|
-
let(:
|
16
|
-
double('MiddlemanDato::JsonApiEntity',
|
15
|
+
let(:item_entity) do
|
16
|
+
double('MiddlemanDato::JsonApiEntity', item_type: item_type)
|
17
17
|
end
|
18
|
-
let(:
|
19
|
-
double('MiddlemanDato::JsonApiEntity',
|
18
|
+
let(:singleton_item_entity) do
|
19
|
+
double('MiddlemanDato::JsonApiEntity', item_type: singleton_item_type)
|
20
20
|
end
|
21
|
-
let(:
|
22
|
-
instance_double('MiddlemanDato::
|
21
|
+
let(:item) do
|
22
|
+
instance_double('MiddlemanDato::Item', id: '14')
|
23
23
|
end
|
24
|
-
let(:
|
25
|
-
instance_double('MiddlemanDato::
|
24
|
+
let(:singleton_item) do
|
25
|
+
instance_double('MiddlemanDato::Item', id: '22')
|
26
26
|
end
|
27
27
|
|
28
28
|
before do
|
29
|
-
allow(entities_repo).to receive(:find_entities_of_type).with('
|
30
|
-
[
|
29
|
+
allow(entities_repo).to receive(:find_entities_of_type).with('item_type') do
|
30
|
+
[item_type, singleton_item_type]
|
31
31
|
end
|
32
32
|
|
33
|
-
allow(entities_repo).to receive(:find_entities_of_type).with('
|
34
|
-
[
|
33
|
+
allow(entities_repo).to receive(:find_entities_of_type).with('item') do
|
34
|
+
[item_entity, singleton_item_entity]
|
35
35
|
end
|
36
36
|
|
37
|
-
allow(
|
38
|
-
|
37
|
+
allow(Item).to receive(:new).with(item_entity, anything) do
|
38
|
+
item
|
39
39
|
end
|
40
40
|
|
41
|
-
allow(
|
42
|
-
|
41
|
+
allow(Item).to receive(:new).with(singleton_item_entity, anything) do
|
42
|
+
singleton_item
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe '#find' do
|
47
|
-
it 'returns the specified
|
48
|
-
expect(repo.find('14')).to eq
|
49
|
-
expect(repo.find('22')).to eq
|
47
|
+
it 'returns the specified item' do
|
48
|
+
expect(repo.find('14')).to eq item
|
49
|
+
expect(repo.find('22')).to eq singleton_item
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
describe '
|
53
|
+
describe 'item_types' do
|
54
54
|
describe 'singleton' do
|
55
|
-
it 'returns the associated
|
55
|
+
it 'returns the associated item' do
|
56
56
|
expect(repo.respond_to?(:homepage)).to be_truthy
|
57
|
-
expect(repo.homepage).to eq
|
57
|
+
expect(repo.homepage).to eq singleton_item
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
describe 'non-singleton' do
|
62
|
-
it 'returns the associated
|
62
|
+
it 'returns the associated items' do
|
63
63
|
expect(repo.respond_to?(:posts)).to be_truthy
|
64
|
-
expect(repo.posts).to eq [
|
64
|
+
expect(repo.posts).to eq [item]
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -73,16 +73,16 @@ module MiddlemanDato
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
describe
|
76
|
+
describe ItemsRepo::ItemCollection do
|
77
77
|
subject(:collection) { described_class.new(items) }
|
78
78
|
let(:items) do
|
79
79
|
[foo]
|
80
80
|
end
|
81
81
|
|
82
|
-
let(:foo) { double('MiddlemanDato::
|
82
|
+
let(:foo) { double('MiddlemanDato::Item', id: '1', name: 'Foo') }
|
83
83
|
|
84
84
|
describe '#[]' do
|
85
|
-
it 'returns the
|
85
|
+
it 'returns the item with the specified id or index' do
|
86
86
|
expect(collection['1']).to eq foo
|
87
87
|
expect(collection[0]).to eq foo
|
88
88
|
end
|
@@ -96,7 +96,7 @@ module MiddlemanDato
|
|
96
96
|
|
97
97
|
describe '#each' do
|
98
98
|
context 'with arity == 2' do
|
99
|
-
it 'iterates with id and
|
99
|
+
it 'iterates with id and item' do
|
100
100
|
collection.each do |a, b|
|
101
101
|
expect(a).to eq '1'
|
102
102
|
expect(b).to eq foo
|
@@ -3,16 +3,16 @@ require 'spec_helper'
|
|
3
3
|
module MiddlemanDato
|
4
4
|
module MetaTags
|
5
5
|
RSpec.describe ArticleModifiedTime do
|
6
|
-
subject(:meta_tag) { described_class.new(builder, base_url,
|
6
|
+
subject(:meta_tag) { described_class.new(builder, base_url, site, item) }
|
7
7
|
let(:builder) { ::MockBuilder.new }
|
8
8
|
let(:base_url) { nil }
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
double('
|
9
|
+
let(:site) { nil }
|
10
|
+
let(:item) do
|
11
|
+
double('Item', updated_at: Time.now, singleton?: false)
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '.value' do
|
15
|
-
context 'if
|
15
|
+
context 'if item is not singleton' do
|
16
16
|
it 'returns an ISO 8601 time representation' do
|
17
17
|
expect(meta_tag.value).not_to be_nil
|
18
18
|
end
|
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
module MiddlemanDato
|
4
4
|
module MetaTags
|
5
5
|
RSpec.describe Image do
|
6
|
-
subject(:meta_tag) { described_class.new(builder, base_url,
|
6
|
+
subject(:meta_tag) { described_class.new(builder, base_url, site, item) }
|
7
7
|
let(:builder) { ::MockBuilder.new }
|
8
8
|
let(:base_url) { nil }
|
9
|
-
let(:
|
10
|
-
let(:
|
9
|
+
let(:site) { nil }
|
10
|
+
let(:item) do
|
11
11
|
double(
|
12
|
-
'MiddlemanDato::
|
12
|
+
'MiddlemanDato::Item',
|
13
13
|
fields: [double('MiddlemanDato::JsonApiEntity', api_key: 'foo', field_type: 'image')],
|
14
14
|
foo: image,
|
15
15
|
singleton?: false
|
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
module MiddlemanDato
|
4
4
|
module MetaTags
|
5
5
|
RSpec.describe OgLocale do
|
6
|
-
subject(:meta_tag) { described_class.new(builder, base_url,
|
6
|
+
subject(:meta_tag) { described_class.new(builder, base_url, site, item) }
|
7
7
|
let(:builder) { ::MockBuilder.new }
|
8
8
|
let(:base_url) { nil }
|
9
|
-
let(:
|
10
|
-
let(:
|
9
|
+
let(:site) { nil }
|
10
|
+
let(:item) { nil }
|
11
11
|
|
12
12
|
describe '#value' do
|
13
13
|
it 'returns the current locale' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-dato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: Fetches data from a Dato
|
97
|
+
description: Fetches data from a Dato site
|
98
98
|
email:
|
99
99
|
- s.verna@cantierecreativo.net
|
100
100
|
executables: []
|
@@ -125,6 +125,8 @@ files:
|
|
125
125
|
- lib/middleman_dato/field_type/string.rb
|
126
126
|
- lib/middleman_dato/field_type/text.rb
|
127
127
|
- lib/middleman_dato/field_type/video.rb
|
128
|
+
- lib/middleman_dato/item.rb
|
129
|
+
- lib/middleman_dato/items_repo.rb
|
128
130
|
- lib/middleman_dato/json_api_entity.rb
|
129
131
|
- lib/middleman_dato/meta_tags/article_modified_time.rb
|
130
132
|
- lib/middleman_dato/meta_tags/article_publisher.rb
|
@@ -144,9 +146,7 @@ files:
|
|
144
146
|
- lib/middleman_dato/meta_tags/url.rb
|
145
147
|
- lib/middleman_dato/meta_tags_builder.rb
|
146
148
|
- lib/middleman_dato/middleman_extension.rb
|
147
|
-
- lib/middleman_dato/
|
148
|
-
- lib/middleman_dato/records_repo.rb
|
149
|
-
- lib/middleman_dato/space.rb
|
149
|
+
- lib/middleman_dato/site.rb
|
150
150
|
- lib/middleman_dato/version.rb
|
151
151
|
- middleman-dato.gemspec
|
152
152
|
- spec/middleman_dato/entities_repo_spec.rb
|
@@ -155,13 +155,13 @@ files:
|
|
155
155
|
- spec/middleman_dato/field_type/lat_lon_spec.rb
|
156
156
|
- spec/middleman_dato/field_type/seo_spec.rb
|
157
157
|
- spec/middleman_dato/field_type/video_spec.rb
|
158
|
+
- spec/middleman_dato/item_spec.rb
|
159
|
+
- spec/middleman_dato/items_repo_spec.rb
|
158
160
|
- spec/middleman_dato/json_api_entity_spec.rb
|
159
161
|
- spec/middleman_dato/meta_tags/article_modified_time_spec.rb
|
160
162
|
- spec/middleman_dato/meta_tags/favicon_spec.rb
|
161
163
|
- spec/middleman_dato/meta_tags/image_spec.rb
|
162
164
|
- spec/middleman_dato/meta_tags/og_locale_spec.rb
|
163
|
-
- spec/middleman_dato/record_spec.rb
|
164
|
-
- spec/middleman_dato/records_repo_spec.rb
|
165
165
|
- spec/spec_helper.rb
|
166
166
|
- spec/support/mock_builder.rb
|
167
167
|
homepage: http://cantierecreativo.net
|
@@ -186,7 +186,7 @@ rubyforge_project:
|
|
186
186
|
rubygems_version: 2.5.1
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
|
-
summary: Fetches data from a Dato
|
189
|
+
summary: Fetches data from a Dato site
|
190
190
|
test_files:
|
191
191
|
- spec/middleman_dato/entities_repo_spec.rb
|
192
192
|
- spec/middleman_dato/field_type/file_spec.rb
|
@@ -194,13 +194,13 @@ test_files:
|
|
194
194
|
- spec/middleman_dato/field_type/lat_lon_spec.rb
|
195
195
|
- spec/middleman_dato/field_type/seo_spec.rb
|
196
196
|
- spec/middleman_dato/field_type/video_spec.rb
|
197
|
+
- spec/middleman_dato/item_spec.rb
|
198
|
+
- spec/middleman_dato/items_repo_spec.rb
|
197
199
|
- spec/middleman_dato/json_api_entity_spec.rb
|
198
200
|
- spec/middleman_dato/meta_tags/article_modified_time_spec.rb
|
199
201
|
- spec/middleman_dato/meta_tags/favicon_spec.rb
|
200
202
|
- spec/middleman_dato/meta_tags/image_spec.rb
|
201
203
|
- spec/middleman_dato/meta_tags/og_locale_spec.rb
|
202
|
-
- spec/middleman_dato/record_spec.rb
|
203
|
-
- spec/middleman_dato/records_repo_spec.rb
|
204
204
|
- spec/spec_helper.rb
|
205
205
|
- spec/support/mock_builder.rb
|
206
206
|
has_rdoc:
|