amp-html 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/.github/issue_template.md +16 -0
  3. data/.github/pull_request_template.md +21 -0
  4. data/.gitignore +13 -0
  5. data/.travis.yml +4 -0
  6. data/CHANGELOG.md +302 -0
  7. data/CONTRIBUTING.md +1 -0
  8. data/DEPRECATIONS.md +9 -0
  9. data/Gemfile +12 -0
  10. data/Gemfile.lock +162 -0
  11. data/INSTALL.md +1 -0
  12. data/LICENSE +21 -0
  13. data/OWNERS.yaml +1 -0
  14. data/README.md +192 -0
  15. data/Rakefile +6 -0
  16. data/amp-html.gemspec +29 -0
  17. data/bin/amp-html +4 -0
  18. data/lib/amp_html.rb +27 -0
  19. data/lib/amp_html/cli.rb +113 -0
  20. data/lib/amp_html/components/docs/README.md +101 -0
  21. data/lib/amp_html/components/docs/ad.md +83 -0
  22. data/lib/amp_html/components/docs/analytics.md +131 -0
  23. data/lib/amp_html/components/docs/anim.md +66 -0
  24. data/lib/amp_html/components/docs/fonts.md +63 -0
  25. data/lib/amp_html/components/docs/forms.md +79 -0
  26. data/lib/amp_html/components/docs/iframe.md +62 -0
  27. data/lib/amp_html/components/docs/javascript.md +71 -0
  28. data/lib/amp_html/components/docs/lists.md +168 -0
  29. data/lib/amp_html/components/docs/media.md +52 -0
  30. data/lib/amp_html/components/docs/mustache.md +46 -0
  31. data/lib/amp_html/components/docs/notifications.md +0 -0
  32. data/lib/amp_html/components/docs/schema.md +80 -0
  33. data/lib/amp_html/components/docs/service_worker.md +60 -0
  34. data/lib/amp_html/components/docs/social.md +130 -0
  35. data/lib/amp_html/components/docs/stylesheets.md +50 -0
  36. data/lib/amp_html/components/help.rb +19 -0
  37. data/lib/amp_html/components/install.rb +34 -0
  38. data/lib/amp_html/components/templates/ERROR.md +5 -0
  39. data/lib/amp_html/components/templates/README.md +12 -0
  40. data/lib/amp_html/configuration.rb +170 -0
  41. data/lib/amp_html/configuration/docs/README.md +0 -0
  42. data/lib/amp_html/configuration/help.rb +11 -0
  43. data/lib/amp_html/helpers/docs/README.md +98 -0
  44. data/lib/amp_html/helpers/docs/amp.md +0 -0
  45. data/lib/amp_html/helpers/docs/amp_ad.md +86 -0
  46. data/lib/amp_html/helpers/docs/amp_analytics.md +76 -0
  47. data/lib/amp_html/helpers/docs/amp_anim.md +68 -0
  48. data/lib/amp_html/helpers/docs/amp_audio.md +54 -0
  49. data/lib/amp_html/helpers/docs/amp_auto_ads.md +43 -0
  50. data/lib/amp_html/helpers/docs/amp_close_user_notification_button.md +0 -0
  51. data/lib/amp_html/helpers/docs/amp_css.md +37 -0
  52. data/lib/amp_html/helpers/docs/amp_css_link.md +0 -0
  53. data/lib/amp_html/helpers/docs/amp_custom_ad.md +0 -0
  54. data/lib/amp_html/helpers/docs/amp_document_link.md +0 -0
  55. data/lib/amp_html/helpers/docs/amp_embed.md +86 -0
  56. data/lib/amp_html/helpers/docs/amp_facebook.md +70 -0
  57. data/lib/amp_html/helpers/docs/amp_fallback.md +47 -0
  58. data/lib/amp_html/helpers/docs/amp_font.md +0 -0
  59. data/lib/amp_html/helpers/docs/amp_font_link.md +0 -0
  60. data/lib/amp_html/helpers/docs/amp_form.md +0 -0
  61. data/lib/amp_html/helpers/docs/amp_form_response.md +0 -0
  62. data/lib/amp_html/helpers/docs/amp_gfycat.md +0 -0
  63. data/lib/amp_html/helpers/docs/amp_global_css.md +0 -0
  64. data/lib/amp_html/helpers/docs/amp_google_analytics.md +0 -0
  65. data/lib/amp_html/helpers/docs/amp_google_font.md +0 -0
  66. data/lib/amp_html/helpers/docs/amp_head.md +0 -0
  67. data/lib/amp_html/helpers/docs/amp_html_doctype.md +0 -0
  68. data/lib/amp_html/helpers/docs/amp_iframe.md +0 -0
  69. data/lib/amp_html/helpers/docs/amp_image.md +0 -0
  70. data/lib/amp_html/helpers/docs/amp_input.md +0 -0
  71. data/lib/amp_html/helpers/docs/amp_instagram.md +0 -0
  72. data/lib/amp_html/helpers/docs/amp_js.md +0 -0
  73. data/lib/amp_html/helpers/docs/amp_link.md +0 -0
  74. data/lib/amp_html/helpers/docs/amp_list.md +0 -0
  75. data/lib/amp_html/helpers/docs/amp_live_list.md +0 -0
  76. data/lib/amp_html/helpers/docs/amp_live_list_items.md +0 -0
  77. data/lib/amp_html/helpers/docs/amp_live_list_pagination.md +0 -0
  78. data/lib/amp_html/helpers/docs/amp_live_list_update.md +0 -0
  79. data/lib/amp_html/helpers/docs/amp_mustache.md +0 -0
  80. data/lib/amp_html/helpers/docs/amp_pin_it.md +0 -0
  81. data/lib/amp_html/helpers/docs/amp_pin_widget.md +0 -0
  82. data/lib/amp_html/helpers/docs/amp_pinterest_follow.md +0 -0
  83. data/lib/amp_html/helpers/docs/amp_pixel.md +0 -0
  84. data/lib/amp_html/helpers/docs/amp_placeholder.md +0 -0
  85. data/lib/amp_html/helpers/docs/amp_reddit.md +0 -0
  86. data/lib/amp_html/helpers/docs/amp_resources.md +0 -0
  87. data/lib/amp_html/helpers/docs/amp_selector.md +0 -0
  88. data/lib/amp_html/helpers/docs/amp_serviceworker.md +0 -0
  89. data/lib/amp_html/helpers/docs/amp_social_share.md +0 -0
  90. data/lib/amp_html/helpers/docs/amp_soundcloud.md +0 -0
  91. data/lib/amp_html/helpers/docs/amp_twitter.md +0 -0
  92. data/lib/amp_html/helpers/docs/amp_user_notification.md +0 -0
  93. data/lib/amp_html/helpers/docs/amp_video.md +0 -0
  94. data/lib/amp_html/helpers/docs/amp_video_ad.md +0 -0
  95. data/lib/amp_html/helpers/docs/amp_vine.md +0 -0
  96. data/lib/amp_html/helpers/docs/amp_youtube.md +0 -0
  97. data/lib/amp_html/helpers/docs/audio_tag.md +0 -0
  98. data/lib/amp_html/helpers/docs/canonical_document_link.md +0 -0
  99. data/lib/amp_html/helpers/docs/form_tag.md +0 -0
  100. data/lib/amp_html/helpers/docs/image_tag.md +0 -0
  101. data/lib/amp_html/helpers/docs/input_tag.md +0 -0
  102. data/lib/amp_html/helpers/docs/javascript_include_tag.md +0 -0
  103. data/lib/amp_html/helpers/docs/noscript_tag.md +0 -0
  104. data/lib/amp_html/helpers/docs/schema_tag.md +0 -0
  105. data/lib/amp_html/helpers/docs/stylesheet_link_tag.md +0 -0
  106. data/lib/amp_html/helpers/docs/video_tag.md +0 -0
  107. data/lib/amp_html/helpers/help.rb +23 -0
  108. data/lib/amp_html/root.rb +7 -0
  109. data/lib/amp_html/test.rb +169 -0
  110. data/lib/amp_html/test/help.rb +11 -0
  111. data/lib/amp_html/test/templates/README.md +43 -0
  112. data/lib/amp_html/test/templates/css/!important.md +1 -0
  113. data/lib/amp_html/test/templates/css/-amp-.md +1 -0
  114. data/lib/amp_html/test/templates/css/-moz-binding.md +1 -0
  115. data/lib/amp_html/test/templates/css/@import.md +1 -0
  116. data/lib/amp_html/test/templates/css/behavior.md +1 -0
  117. data/lib/amp_html/test/templates/css/filter.md +1 -0
  118. data/lib/amp_html/test/templates/css/i-amp-.md +1 -0
  119. data/lib/amp_html/test/templates/css/overflow.md +1 -0
  120. data/lib/amp_html/test/templates/html/applet.md +1 -0
  121. data/lib/amp_html/test/templates/html/audio.md +1 -0
  122. data/lib/amp_html/test/templates/html/base.md +1 -0
  123. data/lib/amp_html/test/templates/html/embed.md +1 -0
  124. data/lib/amp_html/test/templates/html/frame.md +1 -0
  125. data/lib/amp_html/test/templates/html/frameset.md +1 -0
  126. data/lib/amp_html/test/templates/html/http-equiv.md +1 -0
  127. data/lib/amp_html/test/templates/html/iframe.md +1 -0
  128. data/lib/amp_html/test/templates/html/img.md +1 -0
  129. data/lib/amp_html/test/templates/html/javascript_include_tag.md +1 -0
  130. data/lib/amp_html/test/templates/html/object.md +1 -0
  131. data/lib/amp_html/test/templates/html/onclick.md +1 -0
  132. data/lib/amp_html/test/templates/html/onmousehover.md +1 -0
  133. data/lib/amp_html/test/templates/html/param.md +1 -0
  134. data/lib/amp_html/test/templates/html/stylesheet_link_tag.md +1 -0
  135. data/lib/amp_html/test/templates/html/video.md +1 -0
  136. data/lib/amp_html/test/templates/markup/!doctype.md +1 -0
  137. data/lib/amp_html/test/templates/markup/amp_document_link.md +1 -0
  138. data/lib/amp_html/test/templates/markup/amp_head.md +1 -0
  139. data/lib/amp_html/test/templates/markup/amp_html_doctype.md +1 -0
  140. data/lib/amp_html/test/templates/markup/canonical_document_link.md +1 -0
  141. data/lib/amp_html/test/templates/markup/head_body.md +1 -0
  142. data/lib/amp_html/test/templates/markup/html.md +1 -0
  143. data/lib/amp_html/test/templates/markup/meta_viewport.md +1 -0
  144. data/lib/amp_html/validate.rb +46 -0
  145. data/lib/amp_html/validate/help.rb +11 -0
  146. data/lib/amp_html/validate/templates/README.md +32 -0
  147. data/lib/amp_html/version.rb +13 -0
  148. data/lib/generators/amphtml/assets_generator.rb +31 -0
  149. data/lib/generators/amphtml/bundle_generator.rb +50 -0
  150. data/lib/generators/amphtml/components_generator.rb +84 -0
  151. data/lib/generators/amphtml/helpers_generator.rb +32 -0
  152. data/lib/generators/amphtml/install_generator.rb +53 -0
  153. data/lib/generators/amphtml/views_generator.rb +62 -0
  154. data/lib/generators/templates/assets/README.md +0 -0
  155. data/lib/generators/templates/assets/stylesheets/application.scss +15 -0
  156. data/lib/generators/templates/components/README.md +0 -0
  157. data/lib/generators/templates/components/assets/javascripts/application.js +15 -0
  158. data/lib/generators/templates/components/helpers/ad_tag_helper.rb +83 -0
  159. data/lib/generators/templates/components/helpers/analytics_tag_helper.rb +30 -0
  160. data/lib/generators/templates/components/helpers/anim_tag_helper.rb +42 -0
  161. data/lib/generators/templates/components/helpers/iframe_tag_helper.rb +27 -0
  162. data/lib/generators/templates/components/helpers/javascript_tag_helper.rb +12 -0
  163. data/lib/generators/templates/components/helpers/lists_tag_helper.rb +82 -0
  164. data/lib/generators/templates/components/helpers/notification_tag_helper.rb +16 -0
  165. data/lib/generators/templates/components/helpers/serviceworker_tag_helper.rb +15 -0
  166. data/lib/generators/templates/components/helpers/social_tag_helper.rb +228 -0
  167. data/lib/generators/templates/components/public/remote.html +28 -0
  168. data/lib/generators/templates/components/views/_components.html.erb +141 -0
  169. data/lib/generators/templates/components/views/_google_analytics.html.erb +23 -0
  170. data/lib/generators/templates/helpers/README.md +1 -0
  171. data/lib/generators/templates/helpers/amp/fallback_tag_helper.rb +16 -0
  172. data/lib/generators/templates/helpers/amp/font_tag_helper.rb +37 -0
  173. data/lib/generators/templates/helpers/amp/link_tag_helper.rb +11 -0
  174. data/lib/generators/templates/helpers/amp/mustache_tag_helper.rb +13 -0
  175. data/lib/generators/templates/helpers/amp/noscript_tag_helper.rb +13 -0
  176. data/lib/generators/templates/helpers/amp/placeholder_tag_helper.rb +16 -0
  177. data/lib/generators/templates/helpers/amp/schema_tag_helper.rb +16 -0
  178. data/lib/generators/templates/helpers/amp/stylesheets_tag_helper.rb +21 -0
  179. data/lib/generators/templates/helpers/amp_tag_helper.rb.erb +65 -0
  180. data/lib/generators/templates/helpers/asset_tag_helper.rb.erb +119 -0
  181. data/lib/generators/templates/helpers/form_tag_helper.rb.erb +79 -0
  182. data/lib/generators/templates/install/README.md +1 -0
  183. data/lib/generators/templates/install/amphtml.rb.erb +19 -0
  184. data/lib/generators/templates/install/amphtml.yml.erb +189 -0
  185. data/lib/generators/templates/views/README.md +1 -0
  186. data/lib/generators/templates/views/application.html.erb +71 -0
  187. data/lib/generators/templates/views/application/_head.html.erb +47 -0
  188. data/lib/generators/templates/views/application/_resources.html.erb +16 -0
  189. data/lib/generators/templates/views/application/_schema.html.erb +6 -0
  190. data/lib/generators/templates/views/config/mime_types.rb +8 -0
  191. metadata +294 -0
@@ -0,0 +1,62 @@
1
+ require 'rails/generators/base'
2
+ require 'thor'
3
+
4
+ module AmpHtml
5
+ module Generators
6
+
7
+ class ViewsGenerator < Rails::Generators::Base
8
+
9
+ source_root File.expand_path '../../templates/views', __FILE__
10
+ desc 'Updates views to ensure compatibility with AMP. Run with --split to keep a version without AMP.'
11
+
12
+ class_option :only_resources, desc: 'Only generate resources', type: :boolean, default: false
13
+
14
+
15
+ class_option :split, desc: 'Keep an application layout without AMP', type: :boolean, default: false, aliases: '-s'
16
+ class_option :format, desc: 'Set the views format. Defaults to `html`', type: :string, aliases: '-f'
17
+
18
+
19
+ # DEEP INTEGRATION COMPONENTS
20
+ class_option :all, desc: 'Install all AMP-HTML components', type: :boolean, default: false, aliases: '-a'
21
+
22
+ class_option :analytics, desc: 'Install the AMP-HTML Analytics Component', type: :boolean, default: false
23
+ class_option :javascript, desc: 'Install the AMP-HTML Javascript Component', type: :boolean, default: false
24
+
25
+
26
+
27
+
28
+ def create_views
29
+ template 'application/_resources.html.erb', "app/views/application/amp/_resources.#{pick_format}.erb"
30
+ template 'application/_head.html.erb', "app/views/application/amp/_head.#{pick_format}.erb" unless options[:only_resources]
31
+ template 'application/_schema.html.erb', "app/views/application/amp/_schema.#{pick_format}.erb" unless options[:only_resources]
32
+ template 'application.html.erb', "app/views/layouts/application.#{pick_format}.erb" unless options[:only_resources]
33
+ end
34
+
35
+ def create_mime_types
36
+ template 'config/mime_types.rb', 'config/initializers/mime_types.rb' unless options[:only_resources]
37
+ end
38
+
39
+ def show_readme
40
+ readme 'README.md'
41
+ end
42
+
43
+
44
+ private
45
+
46
+
47
+ def pick_format
48
+ if options[:format]
49
+ options[:format]
50
+ else
51
+ if options[:split]
52
+ 'amp'
53
+ else
54
+ 'html'
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
6
+ * vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
5
+ // vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require turbolinks
15
+ //= require_tree .
@@ -0,0 +1,83 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::AdTagHelper
3
+
4
+ def amp_ad network = AmpHtml.ad_default_network, options = {}, &block
5
+ options = options.symbolize_keys
6
+
7
+ options[:type] = network
8
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
9
+ warn 'WARNING (AMP): specify width and height of amp-ad tags.' unless options[:width] && options[:height]
10
+
11
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
12
+ content_tag('amp-ad', options)
13
+
14
+ if block_given?
15
+ content_tag 'amp-ad', capture(&block), options
16
+ else
17
+ if options[:sticky] == true
18
+ options.delete :sticky
19
+ sticky = {}
20
+ sticky[:layout] = 'nodisplay'
21
+ content_tag('amp-sticky-ad', sticky) do
22
+ content_tag 'amp-ad', options
23
+ end
24
+ elsif options[:placeholder]
25
+ placeholder = options[:placeholder]
26
+ options.delete :placeholder
27
+ content_tag('amp-ad', options) do
28
+ placeholder = options[:src] = path_to_image source, skip_pipeline: options.delete(:skip_pipeline)
29
+ amp_placeholder 'amp-img', options
30
+ end
31
+ elsif options[:fallback]
32
+ fallback = options[:fallback]
33
+ options.delete :fallback
34
+ content_tag('amp-ad', options) do
35
+ fallback = options[:src] = path_to_image source, skip_pipeline: options.delete(:skip_pipeline)
36
+ amp_fallback 'amp-img', options
37
+ end
38
+ else
39
+ content_tag 'amp-ad', nil, options
40
+ end
41
+ end
42
+ end
43
+
44
+ def amp_embed network = AmpHtml.ad_default_network, options = {}, &block
45
+ amp_ad network, options, capture(&block)
46
+ end
47
+
48
+ def amp_auto_ads network = AmpHtml.auto_ads_default_network, options = {}
49
+ options = options.symbolize_keys
50
+
51
+ options[:type] = network
52
+ content_tag 'amp-auto-ads', options
53
+ end
54
+
55
+ # ## Removed because it depends on Iframe Component
56
+ # ## Propably moving into Iframe Component
57
+ # def amp_video_ad(source, poster, options = {})
58
+ # options = options.symbolize_keys
59
+ #
60
+ # options[:poster] = poster
61
+ # amp_iframe(source, options)
62
+ # end
63
+
64
+ def amp_custom_ad name
65
+ options = {}
66
+ options[:name] = name
67
+ options[:content] = request.original_url + '/remote.html'
68
+ tag 'meta', options
69
+ end
70
+
71
+ private
72
+
73
+ def extract_dimensions size
74
+ size = size.to_s
75
+ if /\A\d+x\d+\z/.match? size
76
+ size.split("x")
77
+ elsif /\A\d+\z/.match? size
78
+ [size, size]
79
+ end
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,30 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::AnalyticsTagHelper
3
+
4
+ def amp_analytics vendor = AmpHtml.analytics_default_vendor, options = {}, &block
5
+ options = options.symbolize_keys
6
+ options[:type] = vendor if vendor
7
+ if block_given?
8
+ content_tag 'amp-analytics', capture(&block), options
9
+ else
10
+ content_tag 'amp-analytics', nil, options
11
+ end
12
+ end
13
+ def amp_google_analytics options = {}
14
+ options = options.symbolize_keys
15
+
16
+ options[:type] = 'googleanalytics'
17
+ triggers = options[:triggers]
18
+ content_tag('amp-analytics', options) do
19
+ render 'application/amp/components/google_analytics', triggers: triggers
20
+ end
21
+ end
22
+
23
+ def amp_pixel src
24
+ options = {}
25
+ options[:src] = src
26
+ content_tag 'amp-pixel', options
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::AnimTagHelper
3
+
4
+ def amp_anim(source, options = {}, &block)
5
+ options = options.symbolize_keys
6
+
7
+ source = options[:src] = path_to_image(source, skip_pipeline: options.delete(:skip_pipeline))
8
+
9
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
10
+ warn "WARNING (AMP): specify width and height of amp-anim tags." unless options[:width] && options[:height]
11
+
12
+ options[:layout] = "responsive" unless options[:layout] != "responsive"
13
+
14
+ if block_given?
15
+ content_tag("amp-anim", capture(&block), options)
16
+ else
17
+ if options[:placeholder]
18
+ placeholder = options[:placeholder]
19
+ options.delete(:placeholder)
20
+ content_tag("amp-anim", options) do
21
+ placeholder = options[:src] = path_to_image(source, skip_pipeline: options.delete(:skip_pipeline))
22
+ amp_placeholder("amp-img", options)
23
+ end
24
+ else
25
+ content_tag("amp-anim", options)
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def extract_dimensions(size)
33
+ size = size.to_s
34
+ if /\A\d+x\d+\z/.match?(size)
35
+ size.split("x")
36
+ elsif /\A\d+\z/.match?(size)
37
+ [size, size]
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::IframeTagHelper
3
+
4
+ def amp_iframe(source, options = {})
5
+ options = options.symbolize_keys
6
+
7
+ options[:src] = source
8
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
9
+ warn "WARNING (AMP): specify width and height of amp-iframe tags." unless options[:width] && options[:height]
10
+
11
+ options[:layout] = "responsive" unless options[:layout] != "responsive"
12
+ content_tag("amp-iframe", options)
13
+ end
14
+
15
+ private
16
+
17
+ def extract_dimensions(size)
18
+ size = size.to_s
19
+ if /\A\d+x\d+\z/.match?(size)
20
+ size.split("x")
21
+ elsif /\A\d+\z/.match?(size)
22
+ [size, size]
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::JavascriptTagHelper
3
+
4
+ def amp_js(source = asset_url("amp/application.js"))
5
+ options = {}
6
+ options[:src] = src
7
+ options[:sandbox] = "allow-scripts allow-same-origin"
8
+ content_tag("amp-iframe", options)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,82 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::ListsTagHelper
3
+
4
+ def amp_list(source, options = {}, &block)
5
+ options = options.symbolize_keys
6
+
7
+ options[:src] = source
8
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
9
+ warn "WARNING (AMP): specify width and height of amp-list tags." unless options[:width] && options[:height]
10
+
11
+ options[:layout] = "responsive" unless options[:layout] != "responsive"
12
+ if block_given?
13
+ content_tag("amp-list", capture(&block), options)
14
+ else
15
+ content_tag("amp-list", options)
16
+ end
17
+ end
18
+
19
+ def amp_live_list(id, max_items_per_page = "20", interval = "15000", options = {}, &block)
20
+ options = options.symbolize_keys
21
+
22
+ options[:id] = id
23
+ options[:"data-poll-interval"] = interval
24
+ options[:"data-max-items-per-page"] = max_items_per_page
25
+
26
+ if block_given?
27
+ content_tag("amp-live-list", capture(&block), options)
28
+ else
29
+ content_tag("amp-live-list", options)
30
+ end
31
+ end
32
+
33
+ def amp_live_list_update(name = "div", list_id = nil, options = {}, &block)
34
+ options = options.symbolize_keys
35
+
36
+ options[:update] = ""
37
+
38
+ options[:on] = "tap:" + list_id + ".update" if list_id
39
+ if block_given?
40
+ content_tag(name, capture(&block), options)
41
+ else
42
+ content_tag(name, options)
43
+ end
44
+ end
45
+
46
+ def amp_live_list_items(options = {}, &block)
47
+ options = options.symbolize_keys
48
+
49
+ options[:items] = ""
50
+
51
+ if block_given?
52
+ content_tag("div", capture(&block), options)
53
+ else
54
+ content_tag("div", options)
55
+ end
56
+ end
57
+
58
+ def amp_live_list_pagination(options = {}, &block)
59
+ options = options.symbolize_keys
60
+
61
+ options[:pagination] = ""
62
+
63
+ if block_given?
64
+ content_tag("div", capture(&block), options)
65
+ else
66
+ content_tag("div", options)
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def extract_dimensions(size)
73
+ size = size.to_s
74
+ if /\A\d+x\d+\z/.match?(size)
75
+ size.split("x")
76
+ elsif /\A\d+\z/.match?(size)
77
+ [size, size]
78
+ end
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,16 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::NotificationTagHelper
3
+
4
+ def amp_user_notification(id)
5
+ options[:id] = id
6
+ options[:layout] = "nodisplay"
7
+ content_tag("amp-user-notification", options)
8
+ end
9
+
10
+ def amp_close_user_notification_button(id)
11
+ options[:on] = "tap:" + id + ".dismiss"
12
+ content_tag("button", options)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::ServiceworkerTagHelper
3
+
4
+ def amp_serviceworker(register_url, install_url, options = {})
5
+ options = options.symbolize_keys
6
+
7
+ options[:src] = register_url
8
+ options[:"data-iframe-src"] = install_url
9
+ options[:layout] = "nodisplay"
10
+
11
+ content_tag("amp-install-serviceworker", options)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,228 @@
1
+ module ApplicationHelper
2
+ module Amp::Components::SocialTagHelper
3
+
4
+ def amp_twitter tweet_id, options = {}, &block
5
+ options = options.symbolize_keys
6
+
7
+ options[:"data-tweetid"] = tweet_id
8
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
9
+ warn 'WARNING (AMP): specify width and height of amp-twitter tags.' unless options[:width] && options[:height]
10
+
11
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
12
+
13
+ if block_given?
14
+ content_tag 'amp-twitter', capture(&block), options
15
+ else
16
+ content_tag 'amp-twitter', nil, options
17
+ end
18
+ end
19
+
20
+ def amp_instagram shortcode, options = {}, &block
21
+ options = options.symbolize_keys
22
+
23
+ options[:"data-shortcode"] = shortcode
24
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
25
+ warn 'WARNING (AMP): specify width and height of amp-instagram tags.' unless options[:width] && options[:height]
26
+
27
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
28
+
29
+ if block_given?
30
+ content_tag 'amp-instagram', capture(&block), options
31
+ else
32
+ content_tag 'amp-instagram', nil, options
33
+ end
34
+ end
35
+
36
+ def amp_facebook href, options = {}, &block
37
+ options = options.symbolize_keys
38
+
39
+ options[:"data-href"] = href
40
+
41
+ if options[:type]
42
+ options[:"data-embed-as"] = options[:type]
43
+ options.delete :type
44
+ end
45
+
46
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
47
+ warn 'WARNING (AMP): specify width and height of amp-facebook tags.' unless options[:width] && options[:height]
48
+
49
+ if options[:video]
50
+ options[:"data-embed-as"] = 'video'
51
+ options.delete :video
52
+ end
53
+
54
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
55
+
56
+ if block_given?
57
+ content_tag 'amp-facebook', capture(&block), options
58
+ else
59
+ content_tag 'amp-facebook', nil, options
60
+ end
61
+ end
62
+
63
+ def amp_youtube video_id, options = {}, &block
64
+ options = options.symbolize_keys
65
+
66
+ options[:"data-videoid"] = video_id
67
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
68
+ warn 'WARNING (AMP): specify width and height of amp-youtube tags.' unless options[:width] && options[:height]
69
+
70
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
71
+
72
+ if block_given?
73
+ content_tag 'amp-youtube', capture(&block), options
74
+ else
75
+ content_tag 'amp-youtube', nil, options
76
+ end
77
+ end
78
+
79
+ def amp_reddit src, type, options = {}, &block
80
+ options = options.symbolize_keys
81
+
82
+ options[:"data-embedtype"] = type
83
+ options[:"data-src"] = src
84
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
85
+ warn 'WARNING (AMP): specify width and height of amp-reddit tags.' unless options[:width] && options[:height]
86
+
87
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
88
+
89
+ if block_given?
90
+ content_tag 'amp-reddit', capture(&block), options
91
+ else
92
+ content_tag 'amp-reddit', nil, options
93
+ end
94
+ end
95
+
96
+ def amp_social_share type = AmpHtml.social_share_default_provider, options = {}, &block
97
+ options = options.symbolize_keys
98
+
99
+ options[:type] = type if type
100
+ options[:"data-share-endpoint"] = AmpHtml.default_data_share_endpoint if AmpHtml.default_data_share_endpoint
101
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
102
+ warn 'WARNING (AMP): specify width and height of amp-social-share tags.' unless options[:width] && options[:height]
103
+
104
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
105
+
106
+ if block_given?
107
+ content_tag 'amp-social-share', capture(&block), options
108
+ else
109
+ content_tag 'amp-social-share', nil, options
110
+ end
111
+ end
112
+
113
+ def amp_soundcloud track_id, options = {}, &block
114
+ options = options.symbolize_keys
115
+
116
+ options[:"data-trackid"] = track_id
117
+
118
+ if options[:type].downcase == 'visual'
119
+ options[:"data-visual"] = true
120
+ end
121
+ options.delete :type
122
+
123
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
124
+ warn 'WARNING (AMP): specify width and height of amp-soundcloud tags.' unless options[:width] && options[:height]
125
+
126
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
127
+
128
+ if block_given?
129
+ content_tag 'amp-soundcloud', capture(&block), options
130
+ else
131
+ content_tag 'amp-soundcloud', nil, options
132
+ end
133
+ end
134
+
135
+ def amp_vine vine_id, options = {}, &block
136
+ options = options.symbolize_keys
137
+
138
+ options[:"data-vineid"] = vine_id
139
+
140
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
141
+ warn 'WARNING (AMP): specify width and height of amp-vine tags.' unless options[:width] && options[:height]
142
+
143
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
144
+
145
+ if block_given?
146
+ content_tag 'amp-vine', capture(&block), options
147
+ else
148
+ content_tag 'amp-vine', nil, options
149
+ end
150
+ end
151
+
152
+ def amp_gfycat gfy_id, autoplay, options = {}, &block
153
+ options = options.symbolize_keys
154
+
155
+ options[:"data-gfyid"] = gfy_id
156
+ options[:noautoplay] = true if autoplay == false
157
+
158
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
159
+ warn 'WARNING (AMP): specify width and height of amp-gfycat tags.' unless options[:width] && options[:height]
160
+
161
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
162
+
163
+ if block_given?
164
+ content_tag 'amp-gfycat', capture(&block), options
165
+ else
166
+ content_tag 'amp-gfycat', nil, options
167
+ end
168
+ end
169
+
170
+ def amp_pin_it url, media, description, options = {}, &block
171
+ options = options.symbolize_keys
172
+
173
+ options[:"data-do"] = 'buttonPin'
174
+ options[:"data-url"] = url
175
+ options[:"data-media"] = media
176
+ options[:"data-description"] = description
177
+
178
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
179
+ warn 'WARNING (AMP): specify width and height of amp-pinterest tags.' unless options[:width] && options[:height]
180
+
181
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
182
+
183
+ if block_given?
184
+ content_tag 'amp-pinterest', capture(&block), options
185
+ else
186
+ content_tag 'amp-pinterest', nil, options
187
+ end
188
+ end
189
+
190
+ def amp_pin_widget url, options = {}, &block
191
+ options = options.symbolize_keys
192
+
193
+ options[:"data-do"] = 'embedPin'
194
+ options[:"data-url"] = url
195
+
196
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
197
+ warn 'WARNING (AMP): specify width and height of amp-pinterest tags.' unless options[:width] && options[:height]
198
+
199
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
200
+
201
+ if block_given?
202
+ content_tag 'amp-pinterest', capture(&block), options
203
+ else
204
+ content_tag 'amp-pinterest', nil, options
205
+ end
206
+ end
207
+
208
+ def amp_pinterest_follow label, href, options = {}, &block
209
+ options = options.symbolize_keys
210
+
211
+ options[:"data-do"] = 'buttonFollow'
212
+ options[:"data-label"] = label
213
+ options[:"data-href"] = href
214
+
215
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
216
+ warn 'WARNING (AMP): specify width and height of amp-pinterest tags.' unless options[:width] && options[:height]
217
+
218
+ options[:layout] = 'responsive' unless options[:layout] != 'responsive'
219
+
220
+ if block_given?
221
+ content_tag 'amp-pinterest', capture(&block), options
222
+ else
223
+ content_tag 'amp-pinterest', nil, options
224
+ end
225
+ end
226
+
227
+ end
228
+ end