Skip to content
Snippets Groups Projects
Commit 85cd5d67 authored by 🙄 ✻'s avatar 🙄 ✻
Browse files

https://github.com/elmsln/HAXcms/issues/343 D7Webcomponents Normalization

parent 7cad06e5
Branches
Tags 7.x-3.1
No related merge requests found
## Usage
This should give you the dependencies you need to get going.
1. Enable the Web components module and any dependencies it requires.
2. The default is to serve JS assets up from a CDN. Should you need to change this
# Front end Developers
You may build Web components from source if needed. We default to use CDNs which will effectively point to
this directory or some mutation of it -- https://github.com/elmsln/HAXcms/tree/master/build
If you want to build everything from source, your welcome to use yarn / npm to do so though our
build routine effectively will end in the same net result. If you want to do custom build routines
such as rollup or webpack and not use our prebuilt copies / split build approaches, then your welcome
to check the box related to not loading front end assets in the settings page in order to tailor
the build to your specific needs.
## Getting dependencies
You need polymer cli (not polymer but the CLI library) in order to interface with web components in grav. Get polymer cli installed prior to usage of this (and (yarn)[https://yarnpkg.com/lang/en/docs/install/#mac-stable] / an npm client of some kind)
You need polymer cli (not polymer but the CLI library) in order to interface with web components in your site. Get polymer cli installed prior to usage of this (and (yarn)[https://yarnpkg.com/lang/en/docs/install/#mac-stable] / an npm client of some kind)
```bash
$ yarn global add polymer-cli
# or...
$ npm install -g polymer-cli
```
Perform this on your computer locally, this doesn't have to be installed on your server.
## Usage
Find the `CopyThisStuff` directory in `/sites/all/modues/webcomponents` and copy the files in there over to `/sites/all/libraries/webcomponents`.
- Find `CopyThisStuff` directory in `/sites/all/modules/webcomponents`.
- create a `/sites/all/libraries/webcomponents` directory
- copy the files from `CopyThisStuff` into `/sites/all/libraries/webcomponents`
Then run the following (from the directory you copied it over to) in order to get dependencies:
```bash
$ yarn install
# or...
$ npm install
```
Now run `polymer build` and you'll have files in `build/` which contain everything you'll need to get wired up to web components in your grav site. Modifying build.js or package.json can be used in order to get new elements and have them be implemented.
Now run `polymer build` and you'll have files in `build/` which contain everything you'll need to get wired up to web components in your site. Modifying build.js or package.json can be used in order to get new elements and have them be implemented.
### Shouldn't I put web components in my theme?
We don't think so. While it may seem counter intuitive, the theme layer should be effectively implementing what Grav is saying is available. If you think of standard HTML tags are being part of this (p, div, a, etc) then it makes a bit more sense. You don't want functional HTML components to ONLY be supplied if your theme is there, you want your theme to implement and leverage the components.
We don't think so. While it may seem counter intuitive, the theme layer should be effectively implementing what the site is saying is available. If you think of standard HTML tags are being part of this (p, div, a, etc) then it makes a bit more sense. You don't want functional HTML components to ONLY be supplied if your theme is there, you want your theme to implement and leverage the components.
## New to web components?
We built our own tooling to take the guess work out of creating, publishing and testing web components for HAX and other projects. We highly recommend you use this tooling though it's not required:
We built our own tooling to take the guess work out of creating, publishing and testing web components. We highly recommend you use this tooling though it's not required:
- https://open-wc.org - great, simple tooling and open community resource
- https://github.com/elmsln/wcfactory - Build your own web component library
- https://github.com/elmsln/lrnwebcomponents - Our invoking of this tooling to see what a filled out repo looks like
......
......@@ -26,12 +26,25 @@ function webcomponents_menu() {
* Set CDN if you want
*/
function webcomponents_admin_settings($form, &$form_state) {
$form['webcomponents_project_location'] = array(
$form['webcomponents_project_location'] = [
'#type' => 'select',
'#title' => t('Webcomponents Location'),
'#default_value' => variable_get('webcomponents_project_location', 'https://webcomponents.psu.edu/cdn/'),
'#options' => array(
'https://webcomponents.psu.edu/cdn/' => 'Penn State CDN',
'https://cdn.waxam.io/' => 'Waxam CDN',
'sites/all/libraries/webcomponents/' => 'Local libraries folder (sites/all/libraries/webcomponents/)',
'other' => t('Other'),
),
'#description' => t("Use this to point to CDNs or if you've installed your web components some place else. Start without a slash and end with a slash."),
];
$form['webcomponents_project_location_other'] = [
'#type' => 'textfield',
'#title' => t('CDN location'),
'#default_value' => variable_get('webcomponents_project_location', 'sites/all/libraries/webcomponents/'),
'#description' => t("Base path needs to start without a slach and end with a slash. This supports CDNs as well."),
);
'#title' => t('Other Location'),
'#default_value' => variable_get('webcomponents_project_location_other', ''),
'#maxlength' => 1000,
'#description' => t("Only use this if you need to use a source other than the above supported options."),
];
return system_settings_form($form);
}
......@@ -39,7 +52,10 @@ function webcomponents_admin_settings($form, &$form_state) {
* Implements hook_process_html().
*/
function webcomponents_process_html(&$variables) {
$location = variable_get('webcomponents_project_location', 'sites/all/libraries/webcomponents/');
$location = variable_get('webcomponents_project_location', 'https://webcomponents.psu.edu/cdn/');
if ($location == 'other') {
$location = variable_get('webcomponents_project_location_other', '');
}
// append base_path if this site has a url to start it
if (strpos($location, 'http') === FALSE) {
$location = base_path() . $location;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment