I am attempting to include my Polymer tools in my template page but the server is not properly routing to the files. I have put the files in their respective paths, but I get a 404 when I click on the live links.
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-pages/iron-pages.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-ajax/iron-ajax.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-meta/iron-meta.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-iconset-svg/iron-iconset-svg.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-iconset/iron-iconset.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-flex-layout/iron-flex-layout.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-icons/iron-icons.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-icons/maps-icons.html") %>"/>
<link rel="import" href="<%= static_path(#conn, "/assets/polymer/iron-elements/iron-icons/social-icons.html") %>"/>
You may use vulcanize to build a single file from multiple dependencies. Here is example setup for following elements:
<paper-dropdown-menu label="Your favourite pastry">
<paper-menu class="dropdown-content">
<paper-item>Croissant</paper-item>
<paper-item>Donut</paper-item>
<paper-item>Financier</paper-item>
<paper-item>Madeleine</paper-item>
</paper-menu>
</paper-dropdown-menu>
Create target.html:
<link rel=import href=bower_components/paper-dropdown-menu/paper-dropdown-menu.html>
<link rel=import href=bower_components/paper-menu/paper-menu.html>
<link rel=import href=bower_components/paper-item/paper-item.html>
Vulcanize elements:
vulcanize --inline-scripts --inline-css target.html > web/static/assets/polymer/rubber.html
Start serving polymer assets by adding into endpoint.ex:
only: ~w(css fonts images js favicon.ico robots.txt polymer)
Add HTML import for the bundle:
<link rel="import" href="<%= static_path(#conn, "/polymer/rubber.html") %>">
Most probably you would like to serve polyfill library also. Copy webcomponents-lite.js under web/static/vendor/ for this.
NOTE: brunch produces following error:
Component JSON file "bower_components/paper-elements/.bower.json" must have main property.
and stop processing other bower_components AFAICS. To prevent it you may work with bower/vulcanize from within some sub-folder of you project root. Moreover there is no need to process polymer's bower_components with brunch while you are using vulcanize.
See also a question about Polymer CDN - it may be possibly to load elements from CDN.
You most likely have your static asset path incorrect. I believe if you change it to:
"/polymer/iron-elements/..."
(notice the removal of "/assets"). You should be good to go.
Related
I get the following error using Polymer CDN (Polygit.org):
https://polygit.org/components/promise-polyfill/promise-polyfill-lite.html Failed to load resource: the server responded with a status of 404 ()
My head tag has the following:
<base href="https://polygit.org/components/" />
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="promise-polyfill/promise-polyfill-lite.html">
<link rel="import" href="iron-ajax/iron-ajax.html">
<link rel="import" href="iron-image/iron-image.html">
<link rel="import" href="paper-styles/demo-pages.html">
This is because polygit.org serves taylorhakes/promise-polyfill and not the fork maintained by PolymerLabs as its promise-polyfill component.
This can be verified by comparing the polygit.org/components/promise-polyfill/bower.json manifest to the one found in the taylorhakes/promise-polyfill repository.
As was stated by danielx you have to include promise-polyfill from PolymerLabs.
The following line will tell polygit to pull the latest release of promise-polyfill from polymerlabs organisation from github:
<link href="https://polygit.org/promise-polyfill+polymerlabs+*/components/"
rel="import">
Summary
I'm working on a Polymer project based off the Polymer starter kit, and I ran into a problem where icons from the default icon set aren't appearing. Their size and style is calculated correctly, but there's no SVG within the tag when I use inspect element. I've tried icons from maps and social which all work, but the ones from icons just don't have an image.
I've tried various different solutions:
Following this Stack Overflow question here, I did the accepted solution with no results.
I deleted all of my Polymer components and did a fresh bower install + bower update. Still no go.
I saw somewhere that the Polymer Starter Kit has a conflict with the my-icons.html file, so I renamed it to custom-icons.html. This also didn't work.
This is very confusing and frustrating because the problem seemed to pop up out of nowhere. One day the default iron-icons were working, and the next they weren't.
My imports
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/app-layout/app-drawer/app-drawer.html">
<link rel="import" href="../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html">
<link rel="import" href="../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../bower_components/app-layout/app-header-layout/app-header-layout.html">
<link rel="import" href="../bower_components/app-layout/app-scroll-effects/app-scroll-effects.html">
<link rel="import" href="../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../bower_components/app-route/app-location.html">
<link rel="import" href="../bower_components/app-route/app-route.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/iron-icons/maps-icons.html">
<link rel="import" href="../bower_components/iron-icon/iron-icon.html">
<link rel="import" href="../bower_components/iron-localstorage/iron-localstorage.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-item/paper-icon-item.html">
<link rel="import" href="app-data.html">
<link rel="import" href="log-out.html">
<link rel="import" href="custom-icons.html">
Utilization
<a href="/#/home-quotes" tabindex="-1">
<paper-icon-item>
<iron-icon icon="icons:settings" item-icon></iron-icon> <!-- This doesn't work -->
Home
</paper-icon-item>
</a>
<a href="/#/secret-quotes" hidden$="[[!storedUser.loggedin]]" tabindex="-1">
<paper-icon-item>
<iron-icon icon="maps:add-location" item-icon></iron-icon> <!-- This works? -->
Secret Quotes
</paper-icon-item>
</a>
UPDATE The bug has been fixed in Polymer Starter Kit 2.1.1. Now when you run polymer init starter-kit, the generated codebase will include the fix.
I suspect the problem is a naming conflict with your iconset (Issue #934), which was recently fixed.
Before the fix, the name of the custom iconset in Polymer Starter Kit was icons, which is unfortunately also the name of the default iconset from <iron-icons>. Since your custom-icons.html import occurs after iron-icons.html, your iconset takes precedence.
The fix is to rename your custom icons to avoid the name conflict, allowing for both iconsets to coexist. That is, change the iconset's name attribute in your custom-icons.html to something like this:
<iron-iconset-svg name="my-custom-icons" size="24">
I have seen this go back and forth in starter kits and I was wondering what is the best practice for importing element bower elements?
Should each element import the same bower packages redudntly? Or should there be be just one html sheet that imports all the bower elements?
Also, why is <link rel="import" href="../bower_components/polymer/polymer.html"> always imported in each element regardless?
example- each element imports it's own elements, sometimes redudently(other elements may import these also):
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-card/paper-card.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/iron-image/iron-image.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<dom-module id="my-view1">
Or one html sheet importing all elements:
<!-- Iron elements -->
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/iron-icons/maps-icons.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="../bower_components/iron-form/iron-form.html">
<link rel="import" href="../bower_components/google-map/google-map.html">
<link rel="import" href="../bower_components/google-map/google-map-poly.html">
<link rel="import" href="../bower_components/google-map/google-map-marker.html">
<link rel="import" href="../bower_components/google-map/google-map-directions.html">
<!-- Paper elements -->
<link rel="import" href="../bower_components/paper-drawer-panel/paper-drawer-panel.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
<link rel="import" href="../bower_components/paper-material/paper-material.html">
<link rel="import" href="../bower_components/paper-menu/paper-menu.html">
<link rel="import" href="../bower_components/paper-scroll-header-panel/paper-scroll-header-panel.html">
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-styles/typography.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../bower_components/paper-toolbar/paper-toolbar.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="../bower_components/paper-input/paper-textarea.html">
<link rel="import" href="../bower_components/paper-radio-group/paper-radio-group.html">
I believe that with the establishment of the PPL pattern which got announced at Google I/) 2016, and the Polymer build mechanism, a basic structure emerged driven by Polymer CLI.
What I do depends on whether I am attempting to build a re-useable element or just one component which might be re-useable. In a re-useable alement I always import polymer and just those elements that I have used within the element. I reference everything via ../import-element/import-element.html
With my own application I have a rule that tries to lazy load everything via this.importHref except that which is going to be on display when that element initially loads. I have build a behavior for elements that include iron-pages so support that. In this case I import polymer, any elements that will initially be on display. I don't import the rest
html imports are de-duped by Polymer, so it doesn't matter if you attempt to load things more than once, they will only be loaded once.
In this case I reference the bower component elements with an absolute url /bower_components/import-element/import-element.html and for those in my app with relative urls. I currently store ALL custom element for my app in the same directory, so to reference them I am using just import-element.html. I think this last paragraph is not accepted practice, but I just find it easier not having to effectively map two physical directories to the same url.
TL;DR;
I don't that solid best practice has emerged yet.
Longer read
My personal opinion is that import links are generally not a good idea at all, because you will run into trouble when bundling. Unless you want to bundle your entire application, in which case imports' location doesn't matter.
You may want to bundle related elements. For example there can be <app-page-admin-panel>m <app-page-user-profile>, etc. Each of them could be lazy-loaded the first time they are required. Bundled HTML imports don't give you such flexibility AFAIK.
If you bundle everything, there will be nothing to lazy-load of course.
If you create a bundle for each element loaded on-demand is a step forward but what about common elements? If both admin panel and user profile elements import <paper-button> would you include it in each bundle? This is probably safe, albeit wasteful wrt bandwidth. Polymer itself, however, cannot be imported multiple times. Thus importing it in each element is probably not a good idea.
Possible future solution - ES6 module imports
Personally I very much hope for ES6 imports. With import "polymer" you are safe, because bundled or not, it will be guaranteed by the module loader (and browser in the future) that you will only ever import it once. You may want to see my answer to that other question: Modules in Polymer.
I'm using Polymer in one of my web projects. In the index.html page, I included the script and include tags in the following way:
<link rel="import" href="bower_components/core-item/core-item.html">
<link rel="import" href="bower_components/paper-button/paper-button.html">
<script src="scripts/jquery.min.js"></script>
<link href="styles/css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="styles/mycss.css">
In the body tag, I'm using a paper-button the following way:
<paper-button class="blue-ripple" role="button" tabindex="0">Hello</paper-button>
It is rendering perfectly on Chrome (40.0.2214.111 m) but the ripple style is not working on Firefox (35.0.1). I've checked the console and there seem to be no conflicts or warnings or errors.
You need to load the polyfills:
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
See https://www.polymer-project.org/docs/start/platform.html
In the third link tag your href point to styles/css.
This could be the problem.
On my web page, I attempt to import the paper-toast element from the same directory as the other two Polymer elements. All have been installed with Bower and all have the same privileges.
<html>
<head>
<title>New Movement Entertainment</title>
<link rel=stylesheet href=css/home.css type=text/css>
<link rel="import" href="bower_components/paper-shadow/paper-shadow.html">
<link rel="import" href="bower_components/paper-input/paper-input.html">
<link rel="import" href="bower_components/paper-toast/paper-toast.html">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<script src=scripts/jquery.js></script>
However, upon page load I am greeted with a 404 Not Found for the paper-toast import. I have tried reinstalling the element and even putting its folder in the paper-input directory (which I know imports fine). Does anyone have any ideas?