amp-html 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/issue_template.md +16 -0
- data/.github/pull_request_template.md +21 -0
- data/.gitignore +13 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +302 -0
- data/CONTRIBUTING.md +1 -0
- data/DEPRECATIONS.md +9 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +162 -0
- data/INSTALL.md +1 -0
- data/LICENSE +21 -0
- data/OWNERS.yaml +1 -0
- data/README.md +192 -0
- data/Rakefile +6 -0
- data/amp-html.gemspec +29 -0
- data/bin/amp-html +4 -0
- data/lib/amp_html.rb +27 -0
- data/lib/amp_html/cli.rb +113 -0
- data/lib/amp_html/components/docs/README.md +101 -0
- data/lib/amp_html/components/docs/ad.md +83 -0
- data/lib/amp_html/components/docs/analytics.md +131 -0
- data/lib/amp_html/components/docs/anim.md +66 -0
- data/lib/amp_html/components/docs/fonts.md +63 -0
- data/lib/amp_html/components/docs/forms.md +79 -0
- data/lib/amp_html/components/docs/iframe.md +62 -0
- data/lib/amp_html/components/docs/javascript.md +71 -0
- data/lib/amp_html/components/docs/lists.md +168 -0
- data/lib/amp_html/components/docs/media.md +52 -0
- data/lib/amp_html/components/docs/mustache.md +46 -0
- data/lib/amp_html/components/docs/notifications.md +0 -0
- data/lib/amp_html/components/docs/schema.md +80 -0
- data/lib/amp_html/components/docs/service_worker.md +60 -0
- data/lib/amp_html/components/docs/social.md +130 -0
- data/lib/amp_html/components/docs/stylesheets.md +50 -0
- data/lib/amp_html/components/help.rb +19 -0
- data/lib/amp_html/components/install.rb +34 -0
- data/lib/amp_html/components/templates/ERROR.md +5 -0
- data/lib/amp_html/components/templates/README.md +12 -0
- data/lib/amp_html/configuration.rb +170 -0
- data/lib/amp_html/configuration/docs/README.md +0 -0
- data/lib/amp_html/configuration/help.rb +11 -0
- data/lib/amp_html/helpers/docs/README.md +98 -0
- data/lib/amp_html/helpers/docs/amp.md +0 -0
- data/lib/amp_html/helpers/docs/amp_ad.md +86 -0
- data/lib/amp_html/helpers/docs/amp_analytics.md +76 -0
- data/lib/amp_html/helpers/docs/amp_anim.md +68 -0
- data/lib/amp_html/helpers/docs/amp_audio.md +54 -0
- data/lib/amp_html/helpers/docs/amp_auto_ads.md +43 -0
- data/lib/amp_html/helpers/docs/amp_close_user_notification_button.md +0 -0
- data/lib/amp_html/helpers/docs/amp_css.md +37 -0
- 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 +86 -0
- data/lib/amp_html/helpers/docs/amp_facebook.md +70 -0
- data/lib/amp_html/helpers/docs/amp_fallback.md +47 -0
- 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 +23 -0
- data/lib/amp_html/root.rb +7 -0
- data/lib/amp_html/test.rb +169 -0
- data/lib/amp_html/test/help.rb +11 -0
- data/lib/amp_html/test/templates/README.md +43 -0
- data/lib/amp_html/test/templates/css/!important.md +1 -0
- data/lib/amp_html/test/templates/css/-amp-.md +1 -0
- data/lib/amp_html/test/templates/css/-moz-binding.md +1 -0
- data/lib/amp_html/test/templates/css/@import.md +1 -0
- data/lib/amp_html/test/templates/css/behavior.md +1 -0
- data/lib/amp_html/test/templates/css/filter.md +1 -0
- data/lib/amp_html/test/templates/css/i-amp-.md +1 -0
- data/lib/amp_html/test/templates/css/overflow.md +1 -0
- data/lib/amp_html/test/templates/html/applet.md +1 -0
- data/lib/amp_html/test/templates/html/audio.md +1 -0
- data/lib/amp_html/test/templates/html/base.md +1 -0
- data/lib/amp_html/test/templates/html/embed.md +1 -0
- data/lib/amp_html/test/templates/html/frame.md +1 -0
- data/lib/amp_html/test/templates/html/frameset.md +1 -0
- data/lib/amp_html/test/templates/html/http-equiv.md +1 -0
- data/lib/amp_html/test/templates/html/iframe.md +1 -0
- data/lib/amp_html/test/templates/html/img.md +1 -0
- data/lib/amp_html/test/templates/html/javascript_include_tag.md +1 -0
- data/lib/amp_html/test/templates/html/object.md +1 -0
- data/lib/amp_html/test/templates/html/onclick.md +1 -0
- data/lib/amp_html/test/templates/html/onmousehover.md +1 -0
- data/lib/amp_html/test/templates/html/param.md +1 -0
- data/lib/amp_html/test/templates/html/stylesheet_link_tag.md +1 -0
- data/lib/amp_html/test/templates/html/video.md +1 -0
- data/lib/amp_html/test/templates/markup/!doctype.md +1 -0
- data/lib/amp_html/test/templates/markup/amp_document_link.md +1 -0
- data/lib/amp_html/test/templates/markup/amp_head.md +1 -0
- data/lib/amp_html/test/templates/markup/amp_html_doctype.md +1 -0
- data/lib/amp_html/test/templates/markup/canonical_document_link.md +1 -0
- data/lib/amp_html/test/templates/markup/head_body.md +1 -0
- data/lib/amp_html/test/templates/markup/html.md +1 -0
- data/lib/amp_html/test/templates/markup/meta_viewport.md +1 -0
- data/lib/amp_html/validate.rb +46 -0
- data/lib/amp_html/validate/help.rb +11 -0
- data/lib/amp_html/validate/templates/README.md +32 -0
- data/lib/amp_html/version.rb +13 -0
- data/lib/generators/amphtml/assets_generator.rb +31 -0
- data/lib/generators/amphtml/bundle_generator.rb +50 -0
- data/lib/generators/amphtml/components_generator.rb +84 -0
- data/lib/generators/amphtml/helpers_generator.rb +32 -0
- data/lib/generators/amphtml/install_generator.rb +53 -0
- data/lib/generators/amphtml/views_generator.rb +62 -0
- data/lib/generators/templates/assets/README.md +0 -0
- data/lib/generators/templates/assets/stylesheets/application.scss +15 -0
- data/lib/generators/templates/components/README.md +0 -0
- data/lib/generators/templates/components/assets/javascripts/application.js +15 -0
- data/lib/generators/templates/components/helpers/ad_tag_helper.rb +83 -0
- data/lib/generators/templates/components/helpers/analytics_tag_helper.rb +30 -0
- data/lib/generators/templates/components/helpers/anim_tag_helper.rb +42 -0
- data/lib/generators/templates/components/helpers/iframe_tag_helper.rb +27 -0
- data/lib/generators/templates/components/helpers/javascript_tag_helper.rb +12 -0
- data/lib/generators/templates/components/helpers/lists_tag_helper.rb +82 -0
- data/lib/generators/templates/components/helpers/notification_tag_helper.rb +16 -0
- data/lib/generators/templates/components/helpers/serviceworker_tag_helper.rb +15 -0
- data/lib/generators/templates/components/helpers/social_tag_helper.rb +228 -0
- data/lib/generators/templates/components/public/remote.html +28 -0
- data/lib/generators/templates/components/views/_components.html.erb +141 -0
- data/lib/generators/templates/components/views/_google_analytics.html.erb +23 -0
- data/lib/generators/templates/helpers/README.md +1 -0
- data/lib/generators/templates/helpers/amp/fallback_tag_helper.rb +16 -0
- data/lib/generators/templates/helpers/amp/font_tag_helper.rb +37 -0
- data/lib/generators/templates/helpers/amp/link_tag_helper.rb +11 -0
- data/lib/generators/templates/helpers/amp/mustache_tag_helper.rb +13 -0
- data/lib/generators/templates/helpers/amp/noscript_tag_helper.rb +13 -0
- data/lib/generators/templates/helpers/amp/placeholder_tag_helper.rb +16 -0
- data/lib/generators/templates/helpers/amp/schema_tag_helper.rb +16 -0
- data/lib/generators/templates/helpers/amp/stylesheets_tag_helper.rb +21 -0
- data/lib/generators/templates/helpers/amp_tag_helper.rb.erb +65 -0
- data/lib/generators/templates/helpers/asset_tag_helper.rb.erb +119 -0
- data/lib/generators/templates/helpers/form_tag_helper.rb.erb +79 -0
- data/lib/generators/templates/install/README.md +1 -0
- data/lib/generators/templates/install/amphtml.rb.erb +19 -0
- data/lib/generators/templates/install/amphtml.yml.erb +189 -0
- data/lib/generators/templates/views/README.md +1 -0
- data/lib/generators/templates/views/application.html.erb +71 -0
- data/lib/generators/templates/views/application/_head.html.erb +47 -0
- data/lib/generators/templates/views/application/_resources.html.erb +16 -0
- data/lib/generators/templates/views/application/_schema.html.erb +6 -0
- data/lib/generators/templates/views/config/mime_types.rb +8 -0
- metadata +294 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
# [Helpers](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#amp-html-helpers) / `amp_facebook`
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Information
|
|
6
|
+
|
|
7
|
+
`amp_facebook` allows to easily embed ads with AMP, not hurting performance.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
### Quick info
|
|
12
|
+
|
|
13
|
+
#### Latest update: 0.6.2 (Pre-release) - 2017-03-20
|
|
14
|
+
|
|
15
|
+
[**Changelog for version 0.6.2**](https://github.com/slooob/amp-html/blob/master/CHANGELOG.md#062-pre-release---2017-03-20)
|
|
16
|
+
|
|
17
|
+
#### [DeepIntegration](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#deepintegration-helpers): Disabled
|
|
18
|
+
|
|
19
|
+
#### [Availability](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#availability-of-helpers): Installable with the [Social Component](https://github.com/slooob/amp-html/tree/master/lib/amp-html/components/docs/social.md)
|
|
20
|
+
|
|
21
|
+
#### [Takes a block?](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#takes-a-block): Yes
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## General
|
|
26
|
+
|
|
27
|
+
### Reference
|
|
28
|
+
|
|
29
|
+
[**AMP Reference**](https://www.ampproject.org/docs/reference/components/social/amp-facebook)
|
|
30
|
+
|
|
31
|
+
#### Required Parameters
|
|
32
|
+
|
|
33
|
+
* `href`
|
|
34
|
+
* `size` (or `width` & `height`)
|
|
35
|
+
|
|
36
|
+
#### Structure
|
|
37
|
+
|
|
38
|
+
<%= amp_facebook(href, options) %>
|
|
39
|
+
# <amp-facebook data-href=href layout="responsive"></amp-facebook>
|
|
40
|
+
|
|
41
|
+
**Note:** `layout` defaults to `responsive` if not explicitly permitted.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
Setting width & height:
|
|
47
|
+
|
|
48
|
+
<%= amp_facebook("https://www.facebook.com/zuck/posts/10102593740125791", width: 486, height: 657) %>
|
|
49
|
+
<%= amp_facebook("https://www.facebook.com/zuck/posts/10102593740125791", size: "486x657") %>
|
|
50
|
+
# <amp-facebook data-href="https://www.facebook.com/zuck/posts/1010259374012579"1 layout="responsive" width=486 height=657></amp-facebook>
|
|
51
|
+
|
|
52
|
+
Embedding a post:
|
|
53
|
+
|
|
54
|
+
<%= amp_facebook("https://www.facebook.com/zuck/posts/10102593740125791", width: 486, height: 657) %>
|
|
55
|
+
# <amp-facebook data-href="https://www.facebook.com/zuck/posts/10102593740125791" layout="responsive" width=400 height=300></amp-facebook>
|
|
56
|
+
|
|
57
|
+
Embedding a video:
|
|
58
|
+
|
|
59
|
+
<%= amp_facebook("https://www.facebook.com/zuck/posts/10102593740125791", type: "video", width: 486, height: 657 ) %>
|
|
60
|
+
# <amp-facebook data-href="https://www.facebook.com/zuck/posts/10102593740125791" data-embed-as="video" layout="responsive" width=400 height=300></amp-facebook>
|
|
61
|
+
|
|
62
|
+
`amp_facebook` also takes a block:
|
|
63
|
+
|
|
64
|
+
<%= amp_facebook("https://www.facebook.com/zuck/posts/10102593740125791", width: 486, height: 657) do %>
|
|
65
|
+
<%= amp_placeholder("blockquote", class: "facebook-post") do %>
|
|
66
|
+
<p>The story how I became what some people would call a frontend engineer and an exploration into what that even means</p>
|
|
67
|
+
<% end %>
|
|
68
|
+
<% end %>
|
|
69
|
+
|
|
70
|
+
**References:** [`amp_placeholder`](https://github.com/slooob/amp-html/blob/master/lib/amp-html/helpers/docs/amp_placeholder.md)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
# [Helpers](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#amp-html-helpers) / `amp_fallback`
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Information
|
|
6
|
+
|
|
7
|
+
`amp_fallback` allows to create AMP-HTML fallbacks for any HTML or AMP tag.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
### Quick info
|
|
12
|
+
|
|
13
|
+
#### Latest update: 0.5.0 (Pre-release) - 2017-03-18
|
|
14
|
+
|
|
15
|
+
[**Changelog for version 0.5.0**](https://github.com/slooob/amp-html/blob/master/CHANGELOG.md#050-pre-release---2017-03-18)
|
|
16
|
+
|
|
17
|
+
#### [DeepIntegration](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#deepintegration-helpers): Disabled
|
|
18
|
+
|
|
19
|
+
#### [Availability](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#availability-of-helpers): Build-in
|
|
20
|
+
|
|
21
|
+
#### [Takes a block?](https://github.com/slooob/amp-html/tree/master/lib/amp-html/helpers/docs#takes-a-block): Yes
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## General
|
|
26
|
+
|
|
27
|
+
### Reference
|
|
28
|
+
|
|
29
|
+
<!-- [**AMP Reference**](https://www.ampproject.org/docs/reference/components/ads/amp-ad) -->
|
|
30
|
+
|
|
31
|
+
#### Required Parameters
|
|
32
|
+
|
|
33
|
+
* `name`
|
|
34
|
+
|
|
35
|
+
#### Structure
|
|
36
|
+
|
|
37
|
+
<%= amp_fallback(name, options) %>
|
|
38
|
+
# <name fallback></name>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Examples
|
|
42
|
+
|
|
43
|
+
`amp_fallback` also takes a block:
|
|
44
|
+
|
|
45
|
+
<%= amp_fallback("div", layout: "nodisplay") do %>
|
|
46
|
+
<p>Hello AMP</p>
|
|
47
|
+
<% end %>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module AmpHtml
|
|
2
|
+
module Helpers
|
|
3
|
+
class Help
|
|
4
|
+
|
|
5
|
+
def self.all
|
|
6
|
+
puts IO.read File.join AmpHtml.root, 'amp_html', 'helpers', 'docs', 'README.md'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.helper name
|
|
10
|
+
begin
|
|
11
|
+
if name == 'amp?'
|
|
12
|
+
puts IO.read File.join AmpHtml.root, 'amp_html', 'helpers', 'docs', 'amp.md'
|
|
13
|
+
else
|
|
14
|
+
puts IO.read File.join AmpHtml.root, 'amp_html', 'helpers', 'docs', "#{name}.md"
|
|
15
|
+
end
|
|
16
|
+
rescue Exception
|
|
17
|
+
warn 'Helper is not available'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
module AmpHtml
|
|
2
|
+
class Test
|
|
3
|
+
|
|
4
|
+
def self.all
|
|
5
|
+
markup
|
|
6
|
+
html
|
|
7
|
+
css
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.markup
|
|
11
|
+
strings = ['<!doctype', '<html', 'amp_html_doctype', '<head', '<body', 'canonical_document_link', 'amp_document_link', 'amp_head', '<meta name="viewport" content="width=device-width,minimum-scale=1']
|
|
12
|
+
|
|
13
|
+
results = search_files_in_dir_for File.join('app', 'views'), strings
|
|
14
|
+
test1 = markup_test results
|
|
15
|
+
|
|
16
|
+
if test1
|
|
17
|
+
puts 'AMP-HTML TEST: MARKUP tests executed without exceptions'
|
|
18
|
+
else
|
|
19
|
+
puts 'AMP-HTML TEST: MARKUP tests have failed. Learn more about the required markup of AMP pages: https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#required-markup'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.html
|
|
24
|
+
strings = ['javascript_include_tag', 'stylesheet_link_tag', '<base', '<img', '<video', '<audio', '<iframe', '<frame', '<frameset', '<object', '<param', '<applet', '<embed', "<input type='image'", "<input type='button'", "<input type='password'", "<input type='file'", 'http-equiv', 'onclick', 'onmouseover']
|
|
25
|
+
|
|
26
|
+
results = search_files_in_dir_for File.join('app', 'views'), strings
|
|
27
|
+
test1 = html_test results
|
|
28
|
+
|
|
29
|
+
if test1
|
|
30
|
+
puts 'AMP-HTML TEST: HTML tests executed without exceptions'
|
|
31
|
+
else
|
|
32
|
+
puts 'AMP-HTML TEST: HTML tests have failed. Learn more about AMP format restrictions in HTML: https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#html-tags'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.css
|
|
37
|
+
strings = ['@import', '!important', '-amp-', 'i-amp-', 'behavior', '-moz-binding', 'filter', 'overflow: auto', 'overflow: scroll', 'overflow-x: auto', 'overflow-x: scroll', 'overflow-y: auto', 'overflow-y: scroll']
|
|
38
|
+
|
|
39
|
+
results = search_files_in_dir_for File.join('app', 'views'), strings
|
|
40
|
+
test1 = css_test results
|
|
41
|
+
|
|
42
|
+
results = search_files_in_dir_for File.join('app', 'assets', 'stylesheets', 'amp'), strings
|
|
43
|
+
test2 = css_test results
|
|
44
|
+
|
|
45
|
+
if test1 && test2
|
|
46
|
+
puts 'AMP-HTML TEST: CSS tests executed without exceptions'
|
|
47
|
+
else
|
|
48
|
+
puts 'AMP-HTML TEST: CSS tests have failed. Learn more about AMP format restrictions in CSS: https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#stylesheets'
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def self.search_files_in_dir_for dir, strings
|
|
55
|
+
|
|
56
|
+
# ## OLD SOLUTION
|
|
57
|
+
#
|
|
58
|
+
# @results = {}
|
|
59
|
+
# Dir.foreach(dir) do |file|
|
|
60
|
+
# complete_path = File.join(dir, file)
|
|
61
|
+
# next if file == '.' or file == '..'
|
|
62
|
+
# if File.file?(complete_path)
|
|
63
|
+
# # puts "AMP-HTML TEST: Testing '#{complete_path}'"
|
|
64
|
+
# line_number = 0
|
|
65
|
+
# IO.foreach(complete_path) do |line|
|
|
66
|
+
# line_number = line_number + 1
|
|
67
|
+
# if strings.any? { |string| line.include?(string) }
|
|
68
|
+
# string = strings.detect { |string| line.include?(string) }
|
|
69
|
+
# source = "=> " + complete_path + ":" + line_number.to_s
|
|
70
|
+
# @results[source] = string
|
|
71
|
+
# end
|
|
72
|
+
# end
|
|
73
|
+
# else
|
|
74
|
+
# # Search child directories
|
|
75
|
+
# search_files_in_dir_for(complete_path, strings)
|
|
76
|
+
# end
|
|
77
|
+
# end
|
|
78
|
+
|
|
79
|
+
require 'pathname'
|
|
80
|
+
@results = {}
|
|
81
|
+
|
|
82
|
+
files, dirs = Pathname.glob(File.join(dir, '**/*')).partition &:file?
|
|
83
|
+
|
|
84
|
+
files.each do |file|
|
|
85
|
+
# puts "AMP-HTML TEST: Testing '#{file}'"
|
|
86
|
+
line_number = 0
|
|
87
|
+
IO.foreach(file) do |line|
|
|
88
|
+
line_number = line_number + 1
|
|
89
|
+
if strings.any? { |string| line.include?(string) }
|
|
90
|
+
string = strings.detect { |string| line.include?(string) }
|
|
91
|
+
source = '=> ' + [file, line_number].join(':')
|
|
92
|
+
@results[source] = string
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
if @results.present?
|
|
98
|
+
return @results
|
|
99
|
+
else
|
|
100
|
+
return nil
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def self.markup_test results
|
|
107
|
+
if results.present?
|
|
108
|
+
puts check1 = IO.read(File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'markup', 'meta_viewport.md') unless results.has_value? '<meta name="viewport" content="width=device-width,minimum-scale=1'
|
|
109
|
+
puts check2 = IO.read(File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'markup', 'head_body.md') unless results.has_value?('<head') || results.has_value? '<body'
|
|
110
|
+
puts check3 = IO.read(File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'markup', 'amp_html_doctype.md') unless results.has_value? 'amp_html_doctype'
|
|
111
|
+
puts check4 = IO.read(File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'markup', 'canonical_document_link.md') unless results.has_value? 'canonical_document_link'
|
|
112
|
+
puts check5 = IO.read(File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'markup', 'amp_head.md') unless results.has_value? 'amp_head'
|
|
113
|
+
puts check6 = IO.read(File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'markup', 'canonical_document_link.md') if AmpHtml.split_view && results.has_value?('amp_document_link') == false
|
|
114
|
+
end
|
|
115
|
+
unless check1 && check2 && check3 && check4 && check5 && check6
|
|
116
|
+
return true
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
return nil
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def self.html_test results
|
|
124
|
+
if results.present?
|
|
125
|
+
results.each do |source, string|
|
|
126
|
+
case string
|
|
127
|
+
when "<input type='image'" || "<input type='button'" || "<input type='password'" || "<input type='file'"
|
|
128
|
+
puts IO.read File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'html', 'input.md'
|
|
129
|
+
puts source
|
|
130
|
+
else
|
|
131
|
+
puts IO.read(File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'html', "#{string.gsub('<', '')}.md")
|
|
132
|
+
puts source
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
else
|
|
136
|
+
return true
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
return nil
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def self.css_test results
|
|
144
|
+
if results.present?
|
|
145
|
+
results.each do |source, string|
|
|
146
|
+
case string
|
|
147
|
+
when 'overflow: auto' || 'overflow: scroll' || 'overflow-x: auto' || 'overflow-x: scroll' || 'overflow-y: auto' || 'overflow-y: scroll'
|
|
148
|
+
puts IO.read File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'css', 'overflow.md'
|
|
149
|
+
puts source
|
|
150
|
+
when '-amp-'
|
|
151
|
+
unless source.include? 'application/amp/_resources.html'
|
|
152
|
+
puts IO.read File.join AmpHtml.root, 'amp_html', 'test', "templates', 'css', "#{string}.md"
|
|
153
|
+
puts source
|
|
154
|
+
end
|
|
155
|
+
else
|
|
156
|
+
puts IO.read File.join AmpHtml.root, 'amp_html', 'test', 'templates', 'css', "#{string}.md"
|
|
157
|
+
puts source
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
return true if results.keys.size == 1 && results[results.keys.first] == '-amp-' && results.keys.first.include? 'application/amp/_resources.html'
|
|
161
|
+
else
|
|
162
|
+
return true
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
return nil
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
end
|
|
169
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
# AMP-HTML Tests
|
|
3
|
+
|
|
4
|
+
Test the integration of AMP in your application.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
amp-html test NAME
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Options
|
|
13
|
+
|
|
14
|
+
`--split` or `-s`: Run tests with `split` if you are using SplitView.
|
|
15
|
+
|
|
16
|
+
`--help` or `-h`: Run tests with `help` to get additional information on AMP-HTML tests.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Arguments
|
|
21
|
+
|
|
22
|
+
### all
|
|
23
|
+
Running all tests available.
|
|
24
|
+
|
|
25
|
+
amp-html test all
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### markup
|
|
29
|
+
Testing the markup requirements of AMP.
|
|
30
|
+
|
|
31
|
+
amp-html test markup
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### html
|
|
35
|
+
Testing the format specifications of HTML tags in AMP.
|
|
36
|
+
|
|
37
|
+
amp-html test html
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### css
|
|
41
|
+
Testing the AMP format specifications on CSS stylesheets.
|
|
42
|
+
|
|
43
|
+
amp-html test css
|