middleman-dato 0.5.16.3 → 0.5.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.travis.yml +0 -1
  4. data/Gemfile +1 -0
  5. data/Rakefile +1 -0
  6. data/lib/middleman-dato.rb +2 -1
  7. data/lib/middleman_dato/meta_tags/article_modified_time.rb +1 -0
  8. data/lib/middleman_dato/meta_tags/article_publisher.rb +1 -0
  9. data/lib/middleman_dato/meta_tags/base.rb +3 -2
  10. data/lib/middleman_dato/meta_tags/description.rb +1 -0
  11. data/lib/middleman_dato/meta_tags/favicon.rb +7 -11
  12. data/lib/middleman_dato/meta_tags/image.rb +1 -0
  13. data/lib/middleman_dato/meta_tags/og_locale.rb +1 -0
  14. data/lib/middleman_dato/meta_tags/og_meta_tag.rb +1 -0
  15. data/lib/middleman_dato/meta_tags/og_site_name.rb +1 -0
  16. data/lib/middleman_dato/meta_tags/og_type.rb +1 -0
  17. data/lib/middleman_dato/meta_tags/robots.rb +1 -0
  18. data/lib/middleman_dato/meta_tags/title.rb +1 -0
  19. data/lib/middleman_dato/meta_tags/twitter_card.rb +1 -0
  20. data/lib/middleman_dato/meta_tags/twitter_meta_tag.rb +1 -0
  21. data/lib/middleman_dato/meta_tags/twitter_site.rb +1 -0
  22. data/lib/middleman_dato/meta_tags/url.rb +1 -0
  23. data/lib/middleman_dato/meta_tags_builder.rb +1 -0
  24. data/lib/middleman_dato/middleman_extension.rb +14 -5
  25. data/lib/middleman_dato/version.rb +2 -2
  26. data/middleman-dato.gemspec +3 -4
  27. data/spec/middleman_dato/meta_tags/article_modified_time_spec.rb +1 -0
  28. data/spec/middleman_dato/meta_tags/favicon_spec.rb +8 -7
  29. data/spec/middleman_dato/meta_tags/image_spec.rb +1 -0
  30. data/spec/middleman_dato/meta_tags/og_locale_spec.rb +1 -0
  31. data/spec/spec_helper.rb +7 -7
  32. data/spec/support/mock_builder.rb +1 -0
  33. metadata +8 -73
  34. data/lib/middleman_dato/client.rb +0 -68
  35. data/lib/middleman_dato/entities_repo.rb +0 -43
  36. data/lib/middleman_dato/field_type/boolean.rb +0 -9
  37. data/lib/middleman_dato/field_type/date.rb +0 -9
  38. data/lib/middleman_dato/field_type/date_time.rb +0 -9
  39. data/lib/middleman_dato/field_type/file.rb +0 -30
  40. data/lib/middleman_dato/field_type/float.rb +0 -9
  41. data/lib/middleman_dato/field_type/image.rb +0 -29
  42. data/lib/middleman_dato/field_type/integer.rb +0 -9
  43. data/lib/middleman_dato/field_type/lat_lon.rb +0 -20
  44. data/lib/middleman_dato/field_type/link.rb +0 -9
  45. data/lib/middleman_dato/field_type/links.rb +0 -9
  46. data/lib/middleman_dato/field_type/seo.rb +0 -21
  47. data/lib/middleman_dato/field_type/string.rb +0 -9
  48. data/lib/middleman_dato/field_type/text.rb +0 -9
  49. data/lib/middleman_dato/field_type/video.rb +0 -52
  50. data/lib/middleman_dato/item.rb +0 -121
  51. data/lib/middleman_dato/items_repo.rb +0 -107
  52. data/lib/middleman_dato/json_api_entity.rb +0 -75
  53. data/lib/middleman_dato/site.rb +0 -36
  54. data/spec/middleman_dato/entities_repo_spec.rb +0 -41
  55. data/spec/middleman_dato/field_type/file_spec.rb +0 -20
  56. data/spec/middleman_dato/field_type/image_spec.rb +0 -24
  57. data/spec/middleman_dato/field_type/lat_lon_spec.rb +0 -18
  58. data/spec/middleman_dato/field_type/seo_spec.rb +0 -31
  59. data/spec/middleman_dato/field_type/video_spec.rb +0 -32
  60. data/spec/middleman_dato/item_spec.rb +0 -188
  61. data/spec/middleman_dato/items_repo_spec.rb +0 -125
  62. data/spec/middleman_dato/json_api_entity_spec.rb +0 -123
@@ -1,68 +0,0 @@
1
- require 'faraday'
2
- require 'faraday_middleware'
3
- require 'json'
4
- require 'active_support/core_ext/hash/indifferent_access'
5
-
6
- module MiddlemanDato
7
- class Client
8
- def initialize(host, token)
9
- @host = host
10
- @token = token
11
- end
12
-
13
- def site
14
- include = [
15
- 'item_types',
16
- 'item_types.fields'
17
- ]
18
- get('site', include: include).body.with_indifferent_access
19
- end
20
-
21
- def items
22
- items_per_page = 500
23
- base_response = get('items', 'page[limit]' => 1).body.
24
- with_indifferent_access
25
-
26
- pages = (base_response[:meta][:total_count] / items_per_page.to_f).ceil
27
- base_response[:data] = []
28
-
29
- pages.times do |page|
30
- base_response[:data] += get(
31
- 'items',
32
- 'page[offset]' => items_per_page * page,
33
- 'page[limit]' => items_per_page
34
- ).body.with_indifferent_access[:data]
35
- end
36
-
37
- base_response
38
- end
39
-
40
- def get(*args)
41
- connection.get(*args)
42
- rescue Faraday::ClientError => e
43
- body = JSON.parse(e.response[:body])
44
- puts JSON.pretty_generate(body)
45
- raise e
46
- end
47
-
48
- def connection
49
- options = {
50
- url: @host,
51
- headers: {
52
- 'Content-Type' => 'application/json',
53
- 'Accept' => 'application/json',
54
- 'Authorization' => "Api-Key #{@token}",
55
- 'X-Reason' => 'dump',
56
- 'X-SSG' => 'middleman'
57
- }
58
- }
59
- @connection ||= Faraday.new(options) do |c|
60
- c.request :json
61
- c.response :json, item_type: /\bjson$/
62
- c.response :raise_error
63
- c.use FaradayMiddleware::FollowRedirects
64
- c.adapter :net_http
65
- end
66
- end
67
- end
68
- end
@@ -1,43 +0,0 @@
1
- require 'middleman_dato/json_api_entity'
2
-
3
- module MiddlemanDato
4
- class EntitiesRepo
5
- attr_reader :entities
6
-
7
- def initialize(*payloads)
8
- @entities = {}
9
-
10
- payloads.each do |payload|
11
- EntitiesRepo.payload_entities(payload).each do |entity_payload|
12
- object = JsonApiEntity.new(entity_payload, self)
13
- @entities[object.type] ||= {}
14
- @entities[object.type][object.id] = object
15
- end
16
- end
17
- end
18
-
19
- def find_entities_of_type(type)
20
- entities.fetch(type, {}).values
21
- end
22
-
23
- def find_entity(type, id)
24
- entities.fetch(type, {}).fetch(id, nil)
25
- end
26
-
27
- def self.payload_entities(payload)
28
- acc = []
29
-
30
- if payload[:data]
31
- acc = if payload[:data].is_a? Array
32
- acc + payload[:data]
33
- else
34
- acc + [payload[:data]]
35
- end
36
- end
37
-
38
- acc += payload[:included] if payload[:included]
39
-
40
- acc
41
- end
42
- end
43
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Boolean
4
- def self.parse(value, _repo)
5
- value
6
- end
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Date
4
- def self.parse(value, _repo)
5
- ::Date.parse(value)
6
- end
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class DateTime
4
- def self.parse(value, _repo)
5
- ::Time.parse(value)
6
- end
7
- end
8
- end
9
- end
@@ -1,30 +0,0 @@
1
- require 'imgix'
2
-
3
- module MiddlemanDato
4
- module FieldType
5
- class File
6
- attr_reader :path, :format, :size
7
-
8
- def self.parse(value, _repo)
9
- new(
10
- value[:path],
11
- value[:format],
12
- value[:size]
13
- )
14
- end
15
-
16
- def initialize(path, format, size)
17
- @path = path
18
- @format = format
19
- @size = size
20
- end
21
-
22
- def file
23
- Imgix::Client.new(
24
- host: 'www.datocms-assets.com',
25
- secure: true
26
- ).path(path)
27
- end
28
- end
29
- end
30
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Float
4
- def self.parse(value, _repo)
5
- value
6
- end
7
- end
8
- end
9
- end
@@ -1,29 +0,0 @@
1
- require 'middleman_dato/field_type/file'
2
-
3
- module MiddlemanDato
4
- module FieldType
5
- class Image < MiddlemanDato::FieldType::File
6
- attr_reader :width, :height
7
-
8
- def self.parse(value, _repo)
9
- new(
10
- value[:path],
11
- value[:format],
12
- value[:size],
13
- value[:width],
14
- value[:height]
15
- )
16
- end
17
-
18
- def initialize(path, format, size, width, height)
19
- super(path, format, size)
20
- @width = width
21
- @height = height
22
- end
23
-
24
- def file
25
- super.ch('DPR', 'Width').auto('compress')
26
- end
27
- end
28
- end
29
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Integer
4
- def self.parse(value, _repo)
5
- value
6
- end
7
- end
8
- end
9
- end
@@ -1,20 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class LatLon
4
- attr_reader :latitude, :longitude
5
-
6
- def self.parse(value, _repo)
7
- new(value[:latitude], value[:longitude])
8
- end
9
-
10
- def initialize(latitude, longitude)
11
- @latitude = latitude
12
- @longitude = longitude
13
- end
14
-
15
- def values
16
- [latitude, longitude]
17
- end
18
- end
19
- end
20
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Link
4
- def self.parse(value, repo)
5
- repo.find(value)
6
- end
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Links
4
- def self.parse(ids, repo)
5
- ids.map { |id| repo.find(id) }
6
- end
7
- end
8
- end
9
- end
@@ -1,21 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Seo
4
- attr_reader :title, :description
5
-
6
- def self.parse(value, _repo)
7
- new(value[:title], value[:description], value[:image])
8
- end
9
-
10
- def initialize(title, description, image)
11
- @title = title
12
- @description = description
13
- @image = image
14
- end
15
-
16
- def image
17
- @image && Image.parse(@image, nil)
18
- end
19
- end
20
- end
21
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class String
4
- def self.parse(value, _repo)
5
- value
6
- end
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module MiddlemanDato
2
- module FieldType
3
- class Text
4
- def self.parse(value, _repo)
5
- value
6
- end
7
- end
8
- end
9
- end
@@ -1,52 +0,0 @@
1
- require 'active_support/core_ext/hash/compact'
2
- require 'video_embed'
3
-
4
- module MiddlemanDato
5
- module FieldType
6
- class Video
7
- def self.parse(value, _repo)
8
- new(value)
9
- end
10
-
11
- def initialize(attributes)
12
- @attributes = attributes
13
- end
14
-
15
- def url
16
- @attributes[:url]
17
- end
18
-
19
- def thumbnail_url
20
- @attributes[:thumbnail_url]
21
- end
22
-
23
- def title
24
- @attributes[:title]
25
- end
26
-
27
- def width
28
- @attributes[:width]
29
- end
30
-
31
- def height
32
- @attributes[:height]
33
- end
34
-
35
- def provider
36
- @attributes[:provider]
37
- end
38
-
39
- def provider_url
40
- @attributes[:provider_url]
41
- end
42
-
43
- def provider_uid
44
- @attributes[:provider_uid]
45
- end
46
-
47
- def iframe_embed(width = nil, height = nil)
48
- VideoEmbed.embed(url, { width: width, height: height }.compact)
49
- end
50
- end
51
- end
52
- end
@@ -1,121 +0,0 @@
1
- require 'forwardable'
2
- require 'active_support/inflector/transliterate'
3
- require 'active_support/hash_with_indifferent_access'
4
-
5
- Dir[File.dirname(__FILE__) + '/field_type/*.rb'].each do |file|
6
- require file
7
- end
8
-
9
- module MiddlemanDato
10
- class Item
11
- extend Forwardable
12
-
13
- attr_reader :entity
14
- def_delegators :entity, :id, :type, :item_type
15
-
16
- def initialize(entity, items_repo)
17
- @entity = entity
18
- @items_repo = items_repo
19
- end
20
-
21
- def ==(item)
22
- item.is_a?(Item) && item.id == id
23
- end
24
-
25
- def slug
26
- if singleton?
27
- item_type.api_key.humanize.parameterize
28
- elsif title_attribute
29
- title = send(title_attribute)
30
- if title
31
- "#{id}-#{title.parameterize[0..50]}"
32
- else
33
- id.to_s
34
- end
35
- else
36
- id.to_s
37
- end
38
- end
39
-
40
- def singleton?
41
- item_type.singleton
42
- end
43
-
44
- def item_type
45
- @item_type ||= entity.item_type
46
- end
47
- alias_method :content_type, :item_type
48
-
49
- def fields
50
- @fields ||= item_type.fields.sort_by(&:position)
51
- end
52
-
53
- def attributes
54
- @attributes ||= fields.each_with_object(
55
- ActiveSupport::HashWithIndifferentAccess.new
56
- ) do |field, acc|
57
- acc[field.api_key.to_sym] = send(field.api_key)
58
- end
59
- end
60
-
61
- def position
62
- entity.position
63
- end
64
-
65
- def updated_at
66
- Time.parse(entity.updated_at)
67
- end
68
-
69
- def to_s
70
- api_key = item_type.api_key
71
- "#<Item id=#{id} item_type=#{api_key} attributes=#{attributes}>"
72
- end
73
- alias inspect to_s
74
-
75
- def title_attribute
76
- title_field = fields.find do |field|
77
- field.field_type == 'string' &&
78
- field.appeareance[:type] == 'title'
79
- end
80
- title_field && title_field.api_key
81
- end
82
-
83
- def respond_to?(method, include_private = false)
84
- field = fields.find { |f| f.api_key.to_sym == method }
85
- if field
86
- true
87
- else
88
- super
89
- end
90
- end
91
-
92
- private
93
-
94
- def read_attribute(method, field)
95
- field_type = field.field_type
96
- type_klass_name = "::MiddlemanDato::FieldType::#{field_type.camelize}"
97
- type_klass = type_klass_name.safe_constantize
98
-
99
- if type_klass
100
- value = if field.localized
101
- (entity.send(method) || {})[I18n.locale]
102
- else
103
- entity.send(method)
104
- end
105
-
106
- value && type_klass.parse(value, @items_repo)
107
- else
108
- raise "Cannot convert field `#{method}` of type `#{field_type}`"
109
- end
110
- end
111
-
112
- def method_missing(method, *arguments, &block)
113
- field = fields.find { |f| f.api_key.to_sym == method }
114
- if field && arguments.empty?
115
- read_attribute(method, field)
116
- else
117
- super
118
- end
119
- end
120
- end
121
- end