amp-html 0.7.18 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +82 -77
- data/README.md +61 -75
- data/app/helpers/amp_html/asset_helper.rb +11 -0
- data/app/helpers/amp_html/base_helper.rb +14 -0
- data/app/helpers/amp_html/dynamic_content_helper.rb +14 -0
- data/app/helpers/amp_html/layouts_helper.rb +11 -0
- data/app/helpers/amp_html/media_helper.rb +15 -0
- data/app/views/mozaic/amp/_amp-link.html.erb +1 -0
- data/app/views/mozaic/amp/_audio.html.erb +11 -0
- data/app/views/mozaic/amp/_canonical-link.html.erb +1 -0
- data/app/views/mozaic/amp/_components.html.erb +6 -0
- data/app/views/mozaic/amp/_doctype.html.erb +4 -0
- data/app/views/mozaic/amp/_font.html.erb +2 -0
- data/app/views/mozaic/amp/_form-response.html.erb +5 -0
- data/app/views/mozaic/amp/_form.html.erb +3 -0
- data/app/views/mozaic/amp/_head.html.erb +13 -0
- data/app/views/mozaic/amp/_img.html.erb +1 -0
- data/app/views/mozaic/amp/_input.html.erb +1 -0
- data/app/views/mozaic/amp/_mustache.html.erb +3 -0
- data/app/views/mozaic/amp/_selector.html.erb +3 -0
- data/app/views/mozaic/amp/_video.html.erb +11 -0
- data/lib/amp-html.rb +4 -20
- data/lib/amp-html/configuration.rb +13 -158
- data/lib/amp-html/engine.rb +6 -0
- data/lib/amp-html/railtie.rb +109 -0
- data/lib/amp-html/version.rb +1 -9
- data/lib/generators/amp_html_generator.rb +27 -0
- data/lib/generators/templates/{assets/stylesheets/application.scss → application.css} +1 -1
- data/lib/generators/templates/initializer.rb +14 -0
- data/lib/generators/templates/layout.html.erb +15 -0
- metadata +53 -204
- data/.github/issue_template.md +0 -16
- data/.github/pull_request_template.md +0 -21
- data/.gitignore +0 -13
- data/.travis.yml +0 -4
- data/CODE_OF_CONDUCT.md +0 -46
- data/CONTRIBUTING.md +0 -1
- data/DEPRECATIONS.md +0 -9
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -164
- data/INSTALL.md +0 -2
- data/OWNERS.yaml +0 -1
- data/Rakefile +0 -6
- data/amp-html.gemspec +0 -30
- data/bin/amp-html +0 -4
- data/lib/amp-html/cli.rb +0 -113
- data/lib/amp-html/components/docs/README.md +0 -101
- data/lib/amp-html/components/docs/ad.md +0 -83
- data/lib/amp-html/components/docs/analytics.md +0 -131
- data/lib/amp-html/components/docs/anim.md +0 -66
- data/lib/amp-html/components/docs/fonts.md +0 -63
- data/lib/amp-html/components/docs/forms.md +0 -79
- data/lib/amp-html/components/docs/iframe.md +0 -62
- data/lib/amp-html/components/docs/javascript.md +0 -71
- data/lib/amp-html/components/docs/lists.md +0 -168
- data/lib/amp-html/components/docs/media.md +0 -52
- data/lib/amp-html/components/docs/mustache.md +0 -46
- data/lib/amp-html/components/docs/notifications.md +0 -0
- data/lib/amp-html/components/docs/schema.md +0 -80
- data/lib/amp-html/components/docs/service_worker.md +0 -60
- data/lib/amp-html/components/docs/social.md +0 -130
- data/lib/amp-html/components/docs/stylesheets.md +0 -50
- data/lib/amp-html/components/help.rb +0 -19
- data/lib/amp-html/components/install.rb +0 -34
- data/lib/amp-html/components/templates/ERROR.md +0 -5
- data/lib/amp-html/components/templates/README.md +0 -12
- data/lib/amp-html/configuration/docs/README.md +0 -0
- data/lib/amp-html/configuration/help.rb +0 -11
- data/lib/amp-html/helpers/docs/README.md +0 -98
- data/lib/amp-html/helpers/docs/amp.md +0 -0
- data/lib/amp-html/helpers/docs/amp_ad.md +0 -86
- data/lib/amp-html/helpers/docs/amp_analytics.md +0 -76
- data/lib/amp-html/helpers/docs/amp_anim.md +0 -68
- data/lib/amp-html/helpers/docs/amp_audio.md +0 -54
- data/lib/amp-html/helpers/docs/amp_auto_ads.md +0 -43
- data/lib/amp-html/helpers/docs/amp_close_user_notification_button.md +0 -0
- data/lib/amp-html/helpers/docs/amp_css.md +0 -37
- data/lib/amp-html/helpers/docs/amp_css_link.md +0 -0
- data/lib/amp-html/helpers/docs/amp_custom_ad.md +0 -0
- data/lib/amp-html/helpers/docs/amp_document_link.md +0 -0
- data/lib/amp-html/helpers/docs/amp_embed.md +0 -86
- data/lib/amp-html/helpers/docs/amp_facebook.md +0 -70
- data/lib/amp-html/helpers/docs/amp_fallback.md +0 -47
- data/lib/amp-html/helpers/docs/amp_font.md +0 -0
- data/lib/amp-html/helpers/docs/amp_font_link.md +0 -0
- data/lib/amp-html/helpers/docs/amp_form.md +0 -0
- data/lib/amp-html/helpers/docs/amp_form_response.md +0 -0
- data/lib/amp-html/helpers/docs/amp_gfycat.md +0 -0
- data/lib/amp-html/helpers/docs/amp_global_css.md +0 -0
- data/lib/amp-html/helpers/docs/amp_google_analytics.md +0 -0
- data/lib/amp-html/helpers/docs/amp_google_font.md +0 -0
- data/lib/amp-html/helpers/docs/amp_head.md +0 -0
- data/lib/amp-html/helpers/docs/amp_html_doctype.md +0 -0
- data/lib/amp-html/helpers/docs/amp_iframe.md +0 -0
- data/lib/amp-html/helpers/docs/amp_image.md +0 -0
- data/lib/amp-html/helpers/docs/amp_input.md +0 -0
- data/lib/amp-html/helpers/docs/amp_instagram.md +0 -0
- data/lib/amp-html/helpers/docs/amp_js.md +0 -0
- data/lib/amp-html/helpers/docs/amp_link.md +0 -0
- data/lib/amp-html/helpers/docs/amp_list.md +0 -0
- data/lib/amp-html/helpers/docs/amp_live_list.md +0 -0
- data/lib/amp-html/helpers/docs/amp_live_list_items.md +0 -0
- data/lib/amp-html/helpers/docs/amp_live_list_pagination.md +0 -0
- data/lib/amp-html/helpers/docs/amp_live_list_update.md +0 -0
- data/lib/amp-html/helpers/docs/amp_mustache.md +0 -0
- data/lib/amp-html/helpers/docs/amp_pin_it.md +0 -0
- data/lib/amp-html/helpers/docs/amp_pin_widget.md +0 -0
- data/lib/amp-html/helpers/docs/amp_pinterest_follow.md +0 -0
- data/lib/amp-html/helpers/docs/amp_pixel.md +0 -0
- data/lib/amp-html/helpers/docs/amp_placeholder.md +0 -0
- data/lib/amp-html/helpers/docs/amp_reddit.md +0 -0
- data/lib/amp-html/helpers/docs/amp_resources.md +0 -0
- data/lib/amp-html/helpers/docs/amp_selector.md +0 -0
- data/lib/amp-html/helpers/docs/amp_serviceworker.md +0 -0
- data/lib/amp-html/helpers/docs/amp_social_share.md +0 -0
- data/lib/amp-html/helpers/docs/amp_soundcloud.md +0 -0
- data/lib/amp-html/helpers/docs/amp_twitter.md +0 -0
- data/lib/amp-html/helpers/docs/amp_user_notification.md +0 -0
- data/lib/amp-html/helpers/docs/amp_video.md +0 -0
- data/lib/amp-html/helpers/docs/amp_video_ad.md +0 -0
- data/lib/amp-html/helpers/docs/amp_vine.md +0 -0
- data/lib/amp-html/helpers/docs/amp_youtube.md +0 -0
- data/lib/amp-html/helpers/docs/audio_tag.md +0 -0
- data/lib/amp-html/helpers/docs/canonical_document_link.md +0 -0
- data/lib/amp-html/helpers/docs/form_tag.md +0 -0
- data/lib/amp-html/helpers/docs/image_tag.md +0 -0
- data/lib/amp-html/helpers/docs/input_tag.md +0 -0
- data/lib/amp-html/helpers/docs/javascript_include_tag.md +0 -0
- data/lib/amp-html/helpers/docs/noscript_tag.md +0 -0
- data/lib/amp-html/helpers/docs/schema_tag.md +0 -0
- data/lib/amp-html/helpers/docs/stylesheet_link_tag.md +0 -0
- data/lib/amp-html/helpers/docs/video_tag.md +0 -0
- data/lib/amp-html/helpers/help.rb +0 -23
- data/lib/amp-html/root.rb +0 -7
- data/lib/amp-html/test.rb +0 -169
- data/lib/amp-html/test/help.rb +0 -11
- data/lib/amp-html/test/templates/README.md +0 -43
- data/lib/amp-html/test/templates/css/!important.md +0 -1
- data/lib/amp-html/test/templates/css/-amp-.md +0 -1
- data/lib/amp-html/test/templates/css/-moz-binding.md +0 -1
- data/lib/amp-html/test/templates/css/@import.md +0 -1
- data/lib/amp-html/test/templates/css/behavior.md +0 -1
- data/lib/amp-html/test/templates/css/filter.md +0 -1
- data/lib/amp-html/test/templates/css/i-amp-.md +0 -1
- data/lib/amp-html/test/templates/css/overflow.md +0 -1
- data/lib/amp-html/test/templates/html/applet.md +0 -1
- data/lib/amp-html/test/templates/html/audio.md +0 -1
- data/lib/amp-html/test/templates/html/base.md +0 -1
- data/lib/amp-html/test/templates/html/embed.md +0 -1
- data/lib/amp-html/test/templates/html/frame.md +0 -1
- data/lib/amp-html/test/templates/html/frameset.md +0 -1
- data/lib/amp-html/test/templates/html/http-equiv.md +0 -1
- data/lib/amp-html/test/templates/html/iframe.md +0 -1
- data/lib/amp-html/test/templates/html/img.md +0 -1
- data/lib/amp-html/test/templates/html/javascript_include_tag.md +0 -1
- data/lib/amp-html/test/templates/html/object.md +0 -1
- data/lib/amp-html/test/templates/html/onclick.md +0 -1
- data/lib/amp-html/test/templates/html/onmousehover.md +0 -1
- data/lib/amp-html/test/templates/html/param.md +0 -1
- data/lib/amp-html/test/templates/html/stylesheet_link_tag.md +0 -1
- data/lib/amp-html/test/templates/html/video.md +0 -1
- data/lib/amp-html/test/templates/markup/!doctype.md +0 -1
- data/lib/amp-html/test/templates/markup/amp_document_link.md +0 -1
- data/lib/amp-html/test/templates/markup/amp_head.md +0 -1
- data/lib/amp-html/test/templates/markup/amp_html_doctype.md +0 -1
- data/lib/amp-html/test/templates/markup/canonical_document_link.md +0 -1
- data/lib/amp-html/test/templates/markup/head_body.md +0 -1
- data/lib/amp-html/test/templates/markup/html.md +0 -1
- data/lib/amp-html/test/templates/markup/meta_viewport.md +0 -1
- data/lib/amp-html/validate.rb +0 -46
- data/lib/amp-html/validate/help.rb +0 -11
- data/lib/amp-html/validate/templates/README.md +0 -32
- data/lib/generators/amp_html/assets_generator.rb +0 -31
- data/lib/generators/amp_html/bundle_generator.rb +0 -50
- data/lib/generators/amp_html/components_generator.rb +0 -84
- data/lib/generators/amp_html/helpers_generator.rb +0 -32
- data/lib/generators/amp_html/install_generator.rb +0 -53
- data/lib/generators/amp_html/views_generator.rb +0 -62
- data/lib/generators/templates/assets/README.md +0 -0
- data/lib/generators/templates/components/README.md +0 -0
- data/lib/generators/templates/components/views/_components.html.erb +0 -141
- data/lib/generators/templates/components/views/_google_analytics.html.erb +0 -23
- data/lib/generators/templates/helpers/README.md +0 -0
- data/lib/generators/templates/helpers/amp/fallback_tag_helper.rb +0 -16
- data/lib/generators/templates/helpers/amp/font_tag_helper.rb +0 -37
- data/lib/generators/templates/helpers/amp/link_tag_helper.rb +0 -11
- data/lib/generators/templates/helpers/amp/mustache_tag_helper.rb +0 -13
- data/lib/generators/templates/helpers/amp/noscript_tag_helper.rb +0 -13
- data/lib/generators/templates/helpers/amp/placeholder_tag_helper.rb +0 -16
- data/lib/generators/templates/helpers/amp/schema_tag_helper.rb +0 -16
- data/lib/generators/templates/helpers/amp/stylesheets_tag_helper.rb +0 -21
- data/lib/generators/templates/helpers/amp_tag_helper.rb.erb +0 -65
- data/lib/generators/templates/helpers/asset_tag_helper.rb.erb +0 -119
- data/lib/generators/templates/helpers/form_tag_helper.rb.erb +0 -79
- data/lib/generators/templates/install/README.md +0 -0
- data/lib/generators/templates/install/amp-html.rb.erb +0 -19
- data/lib/generators/templates/install/amp-html.yml.erb +0 -189
- data/lib/generators/templates/views/README.md +0 -0
- data/lib/generators/templates/views/application.html.erb +0 -71
- data/lib/generators/templates/views/application/_head.html.erb +0 -47
- data/lib/generators/templates/views/application/_resources.html.erb +0 -16
- data/lib/generators/templates/views/application/_schema.html.erb +0 -6
- data/lib/generators/templates/views/config/mime_types.rb +0 -8
@@ -0,0 +1,15 @@
|
|
1
|
+
module AmpHtml
|
2
|
+
module MediaHelper
|
3
|
+
|
4
|
+
def image_tag source, options = {}
|
5
|
+
amp? ? component('amp/img', options.merge(src: source)) : super
|
6
|
+
end
|
7
|
+
def video_tag *sources
|
8
|
+
amp? ? component('amp/video', options.merge(sources: sources)) : super
|
9
|
+
end
|
10
|
+
def audio_tag *sources
|
11
|
+
amp? ? component('amp/audio', options.merge(sources: sources)) : super
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= tag 'link', options %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% sources = options.delete(:sources) %>
|
2
|
+
<% fallback = options.delete(:fallback) %>
|
3
|
+
|
4
|
+
<%= content_tag 'amp-audio', options do %>
|
5
|
+
<% if sources %>
|
6
|
+
<% sources.each do |source| %>
|
7
|
+
<source src="<%= source[:src] %>" type="<%= source[:type] %>" />
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<% if fallback %><div fallback><p><%= fallback %></p></div><% end %>
|
11
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= tag 'link', options %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% if options[:components]&.include? :form %><script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
|
2
|
+
<% elsif options[:components]&.include? :mustache %><script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
|
3
|
+
<% elsif options[:components]&.include? :selector %><script async custom-element="amp-selector" src="https://cdn.ampproject.org/v0/amp-selector-0.1.js"></script>
|
4
|
+
<% elsif options[:components]&.include? :audio %><script async custom-element="amp-audio" src="https://cdn.ampproject.org/v0/amp-audio-0.1.js"></script>
|
5
|
+
<% elsif options[:components]&.include? :video %><script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>
|
6
|
+
<% elsif options[:components]&.include? :font %><script async custom-element="amp-font" src="https://cdn.ampproject.org/v0/amp-font-0.1.js"></script><% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<meta charset="utf-8">
|
2
|
+
<script async src="https://cdn.ampproject.org/v0.js"></script>
|
3
|
+
|
4
|
+
<%= area :components do %>
|
5
|
+
<%= component 'amp/components', components: options[:components] %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
|
9
|
+
<style amp-custom>
|
10
|
+
<%= Rails.application.assets['application.css'] if AmpHtml.configuration.inherit_stylesheets %>
|
11
|
+
<%= Rails.application.assets['amp/application.css'] %>
|
12
|
+
<%= area :css %>
|
13
|
+
</style>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= tag 'amp-img', options %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= tag 'input', options %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% sources = options.delete(:sources) %>
|
2
|
+
<% fallback = options.delete(:fallback) %>
|
3
|
+
|
4
|
+
<%= content_tag 'amp-video', options do %>
|
5
|
+
<% if sources %>
|
6
|
+
<% sources.each do |source| %>
|
7
|
+
<source src="<%= source[:src] %>" type="<%= source[:type] %>" />
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<% if fallback %><div fallback><p><%= fallback %></p></div><% end %>
|
11
|
+
<% end %>
|
data/lib/amp-html.rb
CHANGED
@@ -1,27 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
rescue Exception => e
|
4
|
-
warn 'Ensure you are in a Ruby on Rails environment'
|
5
|
-
end
|
1
|
+
require 'mozaic'
|
2
|
+
require 'amp-html/version'
|
6
3
|
|
7
4
|
module AmpHtml
|
8
5
|
|
9
|
-
require 'amp-html/root'
|
10
|
-
require 'amp-html/version'
|
11
|
-
|
12
|
-
require 'amp-html/cli'
|
13
|
-
|
14
6
|
require 'amp-html/configuration'
|
15
|
-
require 'amp-html/configuration/help'
|
16
|
-
|
17
|
-
require 'amp-html/test'
|
18
|
-
require 'amp-html/validate'
|
19
|
-
|
20
|
-
require 'amp-html/components/install'
|
21
7
|
|
22
|
-
require 'amp-html/
|
23
|
-
require 'amp-html/
|
24
|
-
require 'amp-html/test/help'
|
25
|
-
require 'amp-html/validate/help'
|
8
|
+
require 'amp-html/railtie'
|
9
|
+
require 'amp-html/engine'
|
26
10
|
|
27
11
|
end
|
@@ -1,170 +1,25 @@
|
|
1
1
|
module AmpHtml
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
if config.key(:default_format)
|
6
|
-
config[:default_format]
|
7
|
-
else
|
8
|
-
'amp'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
def self.raw_format
|
12
|
-
config = get_config
|
13
|
-
config[:default_format]
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.fallback_format
|
17
|
-
config = get_config
|
18
|
-
config[:fallback_format]
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
def self.components
|
23
|
-
config = get_config
|
24
|
-
if config.key(:components)
|
25
|
-
config[:components]
|
26
|
-
else
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def self.split_view
|
33
|
-
config = get_config
|
34
|
-
if config.key(:split_view)
|
35
|
-
config[:split_view]
|
36
|
-
else
|
37
|
-
false
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def self.assets_only_amp
|
43
|
-
config = get_config
|
44
|
-
if config.key(:assets) && config[:assets].key(:only_amp)
|
45
|
-
config[:assets][:only_amp]
|
46
|
-
else
|
47
|
-
if AmpHtml.split_view
|
48
|
-
false
|
49
|
-
else
|
50
|
-
true
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
def self.application_name
|
57
|
-
config = get_config
|
58
|
-
if config.key(:application) && config[:application].key(:name)
|
59
|
-
config[:application][:name]
|
60
|
-
else
|
61
|
-
Rails.application.class.parent
|
62
|
-
end
|
63
|
-
end
|
64
|
-
def self.application_type
|
65
|
-
config = get_config
|
66
|
-
if config.key(:application) && config[:application].key(:type)
|
67
|
-
config[:application][:type]
|
68
|
-
else
|
69
|
-
nil
|
70
|
-
end
|
71
|
-
end
|
72
|
-
def self.application_date_published
|
73
|
-
config = get_config
|
74
|
-
if config.key(:application) && config[:application].key(:date_published)
|
75
|
-
config[:application][:date_published]
|
76
|
-
else
|
77
|
-
DateTime.now
|
78
|
-
end
|
79
|
-
end
|
80
|
-
def self.application_image
|
81
|
-
config = get_config
|
82
|
-
if config.key(:application) && config[:application].key(:image)
|
83
|
-
config[:application][:image]
|
84
|
-
else
|
85
|
-
nil
|
86
|
-
end
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
87
5
|
end
|
88
6
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if config.key(:forms) && config[:forms].key(:amp_selector)
|
93
|
-
config[:forms][:amp_selector]
|
94
|
-
else
|
95
|
-
false
|
96
|
-
end
|
7
|
+
def self.configure
|
8
|
+
self.configuration ||= Configuration.new
|
9
|
+
yield configuration
|
97
10
|
end
|
98
11
|
|
12
|
+
class Configuration
|
99
13
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
config[:analytics][:default_vendor]
|
104
|
-
else
|
105
|
-
nil
|
106
|
-
end
|
107
|
-
end
|
14
|
+
attr_accessor :inherit_stylesheets
|
15
|
+
attr_accessor :split_view
|
16
|
+
attr_accessor :split_view_default
|
108
17
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
else
|
114
|
-
nil
|
18
|
+
def initialize
|
19
|
+
@inherit_stylesheets = false
|
20
|
+
@split_view = false
|
21
|
+
@split_view_default = 'amp'
|
115
22
|
end
|
116
|
-
end
|
117
|
-
|
118
23
|
|
119
|
-
def self.ad_default_network
|
120
|
-
config = get_config
|
121
|
-
if config.key(:ad) && config[:ad].key(:default_network)
|
122
|
-
config[:ad][:default_network]
|
123
|
-
else
|
124
|
-
nil
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.auto_ads_default_network
|
129
|
-
config = get_config
|
130
|
-
if config.key(:ad) && config[:ad].key(:auto_ads) && config[:ad][:auto_ads].key(:default_network)
|
131
|
-
config[:ad][:auto_ads][:default_network]
|
132
|
-
else
|
133
|
-
nil
|
134
|
-
end
|
135
24
|
end
|
136
|
-
|
137
|
-
|
138
|
-
def self.social_share_default_provider
|
139
|
-
config = get_config
|
140
|
-
if config.key(:social) && config[:social].key(:share) && config[:social][:share].key(:default_provider)
|
141
|
-
config[:social][:share][:default_provider]
|
142
|
-
else
|
143
|
-
nil
|
144
|
-
end
|
145
|
-
end
|
146
|
-
def self.social_share_default_data_share_endpoint
|
147
|
-
config = get_config
|
148
|
-
if config.key(:social) && config[:social].key(:share) && config[:social][:share].key(:default_data_share_endpoint)
|
149
|
-
config[:social][:share][:default_data_share_endpoint]
|
150
|
-
else
|
151
|
-
nil
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
private
|
157
|
-
|
158
|
-
|
159
|
-
def self.get_config
|
160
|
-
require 'yaml'
|
161
|
-
|
162
|
-
begin
|
163
|
-
YAML.load_file 'config/amp-html.yml'
|
164
|
-
rescue Exception => e
|
165
|
-
warn 'WARNING (AMP): You need to run `rails g amp_html:bundle` first.'
|
166
|
-
exit
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
25
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module AmpHtml
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
|
6
|
+
initializer 'amp-html.mozaic' do
|
7
|
+
Mozaic.configure do |config|
|
8
|
+
|
9
|
+
|
10
|
+
### Base
|
11
|
+
|
12
|
+
config.define_component 'amp/doctype'
|
13
|
+
config.define_component 'amp/amp-link', rel: 'amphtml' do |options|
|
14
|
+
return false unless AmpHtml.configuration.split_view
|
15
|
+
options[:href] = options[:href].split('?').first
|
16
|
+
unless AmpHtml.configuration.split_view_default == 'amp'
|
17
|
+
options[:href] = "#{options[:href]}?#{{ amp: true }.to_query}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
config.define_component 'amp/canonical-link', rel: 'canonical' do |options|
|
21
|
+
return false unless AmpHtml.configuration.split_view
|
22
|
+
options[:href] = options[:href].split('?').first
|
23
|
+
if AmpHtml.configuration.split_view_default == 'amp'
|
24
|
+
options[:href] = "#{options[:href]}?#{{ amp: false }.to_query}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
config.define_component 'amp/head'
|
28
|
+
config.define_component 'amp/components'
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
### Media
|
33
|
+
|
34
|
+
config.define_component 'amp/img', layout: 'responsive' do |options|
|
35
|
+
options[:src] = image_url options[:src]
|
36
|
+
end
|
37
|
+
config.define_component 'amp/video', layout: 'responsive' do |options|
|
38
|
+
options[:poster] = image_url(options[:poster]) if options.has_key?(:poster)
|
39
|
+
options[:src] = asset_url(options[:src]) if options.has_key?(:src)
|
40
|
+
if options.has_key?(:sources)
|
41
|
+
options[:sources].each do |source|
|
42
|
+
source[:src] = asset_url options[:src]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
config.define_component 'amp/audio' do |options|
|
47
|
+
options[:src] = asset_url(options[:src]) if options.has_key?(:src)
|
48
|
+
if options.has_key?(:sources)
|
49
|
+
options[:sources].each do |source|
|
50
|
+
source[:src] = asset_url options[:src]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
### Presentation
|
58
|
+
|
59
|
+
config.define_component 'amp/font', layout: 'nodisplay'
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
### Dynamic content
|
64
|
+
|
65
|
+
config.define_component 'amp/form', method: :post, target: '_top' do |options|
|
66
|
+
unless options[:method].to_sym == :get
|
67
|
+
options[:"action-xhr"] = options[:action]
|
68
|
+
end
|
69
|
+
options[:on] = "#{options[:on] + ';' if options[:on]}
|
70
|
+
#{'submit:' + options[:submit] + ';' if options[:submit]}
|
71
|
+
#{'submit-success:' + options[:success] + ';' if options[:success]}
|
72
|
+
#{'submit-error:' + options[:error] + ';' if options[:error]}
|
73
|
+
#{'valid:' + options[:valid] + ';' if options[:valid]}
|
74
|
+
#{'invalid:' + options[:invalid] + ';' if options[:invalid]}"
|
75
|
+
options = options.except(:submit, :success, :error, :valid, :invalid)
|
76
|
+
end
|
77
|
+
config.define_component 'amp/form-response', type: :success do |options|
|
78
|
+
options[:"submit-#{options.delete(:type)}"] = true
|
79
|
+
end
|
80
|
+
config.define_component 'amp/input' do |options|
|
81
|
+
options[:on] = "#{options[:on] + ';' if options[:on]}
|
82
|
+
#{'onchange:' + options[:onchange] + ';' if options[:onchange]}"
|
83
|
+
options = options.except(:onchange)
|
84
|
+
end
|
85
|
+
config.define_component 'amp/selector', layout: 'container' do |options|
|
86
|
+
options[:on] = "#{options[:on] + ';' if options[:on]}
|
87
|
+
#{'onchange:' + options[:onchange] + ';' if options[:onchange]}"
|
88
|
+
options = options.except(:onchange)
|
89
|
+
end
|
90
|
+
config.define_component 'amp/mustache' do |options|
|
91
|
+
options[:type] = 'amp-mustache'
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
initializer 'amp-html.assets' do
|
99
|
+
Rails.application.config.assets.precompile += ['amp/application.css']
|
100
|
+
end
|
101
|
+
|
102
|
+
initializer 'amp-html.action_controller' do
|
103
|
+
ActiveSupport.on_load :action_controller do
|
104
|
+
include AmpHtml::BaseHelper
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|