api.add_files is missing a file in Meteor package - javascript

I'm adding three files for the client in my Meteor package like so:
api.add_files([
'lib/client/newsletter_banner.html',
'lib/client/newsletter_banner.css',
'lib/client/templates.js'
], ['client']);
newsletter_banner.html defines a template which is not available when I load the site. If I look through the sources in Devtools, I can see that the CSS and JS files are available, but the HTML file is not. Why is this? I've confirmed that the filename is correct and even changed it thinking that name might be unavailable to me for whatever reason, but the file is still not included.

Html files are loaded by the templating package, so you need to add it to your package as well:
api.use(['templating', 'spacebars', 'ui'], 'client');

Related

Why is eleventy trying to parse a file in a passthrough copy?

I added a "scripts" folder as a passthrough copy to my Eleventy site and installed some npm dependencies inside it for scripts to be run on the page load.
So my .eleventy.js has some lines like this:
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("scripts");
eleventyConfig.addPassthroughCopy("css");
But when I run npx eleventy, I get a build error that says,
Language does not exist: sh
Problem writing Eleventy templates: (more in DEBUG output)
> Having trouble rendering liquid (and markdown) template ./scripts/wb-service-worker/node_modules/bs-fetch/README.md
Why is it trying to "render liquid" in a passthrough copy? (I thought the whole point of passthrough copies is it doesn't try to parse them.) How do I get it to stop?
addPassthroughCopy will copy the files through without parsing, but if the file is also in the input directory, eleventy will process it in its normal way too.
You should keep the assets that you want to be passthrough-copied in a seperate folder to the src files that you are inputting to eleventy for processing.
See these docs for more help:
Input Directory
Ignoring Files
Passthrough's handling of input files

How to modify CSS or JS file from "materialize:materialize" package in Meteor

Currently I am using the package materialize:materialize on my project. I wish to customize the style and modify the CSS and JS file in the package, however, I am not sure what is the best way to modify the files.
I found the CSS and JS files in .meteor/local/build/programs/, when I change the codes there, I can find the change in my site. But when I run the meteor again, it seems that the package load the files to the original version and new codes are changed back.
Thanks for helping me to get the solution.
Best
You can create a folder under the folder client/ or justwith a new css file, and start overwriting the classes of the materialize css.
something like client/styles/mycustom.css
mycustom.css
.someclass {
whatever: whatever
}
you shouldn't modify anything inside of the package folder since you don't have complete control and might be overwrite by meteor.

Yii2: Registering Asset Bundle vs registering external Js file

Hi I wanted to know the advantage of registering Asset Bundle following the process described in the docs like
Process one
in AppAsset.php
public $js = [
'js/myjsfile.js'
];
then in the view file
adding Namespace like
namespace app\assets;
and then adding the use statement like
use app\assets\AppAsset;
AppAsset::register($this);
Instead of doing all this if I use
Process Two
$this->registerJs('js/myjsfile.js', $this::POS_READY);
it works fine.
So why should I use Process One.
Any advantage and reason for this will be greatly appreciated.
If I follow the process one Do I need to add all the js files in
AppAsset.php individually.
Thanks.
Asset Bundles have some advantages over normal registering. Apart from what #deacs said in his/her answer here are others:
Assets Bundles can publish the file to assets if its not in web accessible directory
Assets Bundle can deal with less files (in case of CSS) as well as compressing the assets.
Makes Code Elegant especially in solving dependencies and hence reusability
All the features that makes bundles shine are found in docs
One of the main reasons for using an Asset Bundle is that your assets' paths will always be correct. Consider:
$this->registerJsFile('js/myjsfile.js', ['position'=>$this::POS_READY]);
will generate something like:
<script src="js/myjsfile.js"></script>
Which works great for non urlManager enabled urls, e.g. http://localhost/yiiproject/index.php?r=user/update&id=8 because your browser looks for the js file at: /yiiproject/js/myjsfile.js
But if you enable urlManager, your url will look like http://localhost/yiiproject/user/update/8, which means your browser will look for your js file at: /yiiproject/user/update/8/js/myjsfile.js.
You could overcome this problem by using:
$this->registerJsFile(Yii::$app->request->baseUrl.'/js/myjsfile.js', ['position'=>$this::POS_READY]);
But the Asset Bundle basicly does that for you.
Using Asset Bundles, you can also get the latest version from 'vendor' folder, so if you need to update some lib you don't need to manually do this since composer already do this.

Listing files of a directory in a static webpage

Is there any way to list the files of a directory in a static webpage with the link to view the file?
I would like to upload some PDF files to a certain directory of my static website (it uses HTML and JS), and want to show the list of the files in a page with the link to view the pdf files. That way, if I upload new files, I don't have to modify the HTML page every time. Is there any way to do that?
If you are using Apache as a web-server and have configured mod-autoindex for the directory you upload pdf files then you should probalby see somethink like this when navigation to that url:
This auto-generated page can be easily parsed by js using jquery:
var pdfFilesDirectory = '/uploads/pdf/';
// get auto-generated page
$.ajax({url: pdfFilesDirectory}).then(function(html) {
// create temporary DOM element
var document = $(html);
// find all links ending with .pdf
document.find('a[href$=.pdf]').each(function() {
var pdfName = $(this).text();
var pdfUrl = $(this).attr('href');
// do what you want here
})
});
You need to have a server-side implementation, you could do this by using PHP for example. You cannot do this with JavaScript, because it is run on the client-side, and cannot access the files on the server.
I made a node module to automate the task of getting all files and folders: mddir
Usage
node mddir "../relative/path/"
To install: npm install mddir -g
To generate markdown for current directory: mddir
To generate for any absolute path: mddir /absolute/path
To generate for a relative path: mddir ~/Documents/whatever.
The md file gets generated in your working directory.
Currently ignores node_modules, and .git folders.
Troubleshooting
If you receive the error 'node\r: No such file or directory', the issue is that your operating system uses different line endings and mddir can't parse them without you explicitly setting the line ending style to Unix. This usually affects Windows, but also some versions of Linux. Setting line endings to Unix style has to be performed within the mddir npm global bin folder.
Line endings fix
Get npm bin folder path with:
npm config get prefix
Cd into that folder
brew install dos2unix
dos2unix lib/node_modules/mddir/src/mddir.js
This converts line endings to Unix instead of Dos
Then run as normal with: node mddir "../relative/path/".
I made another node module call agd, to generate a tree view based on the other module: https://github.com/JohnByrneRepo/agd.
Auto generated documentation (Alpha)
Functionality so far:
Generates a tree folder structure in node, that is rendered as a treegrid in the browser. Click on a file (non-root level) to populate main view.
Coming soon:
Generates a documentation guide including function names and parameters, function dependencies, and more. Initially compatible with jQuery and plain JavaScript function namespacing, soon to be compatible with React, Redux, Angular 1, Angular 2 and other frameworks on request.
Usage
node agd relativePath
e.g. node agd '../../'
Generated code.json.
Run 'node http-server' then open the browser to view the file structure rendered in the sidebar. Larger projects can take up to a minute or two to render.
See code.json for example generated data.
To-do: Add code content for top level files. Move tree html generation into node.
Contact html5css3#outlook.com
MIT License
Example generated tree structure
Open a browser
Navigate to the folder you want listed
If you see a list of the files, continue
If you don't see a list of the files, Take a look at this: Is it possible to get a list of files under a directory of a website? How? to figure out how to do that.
Make an ajax call to that folder (example below)
response will be the html of the listing page
You can parse that out to get the file listing
Example:
// This is in angular, but you can use whatever
$http.get('folder_to_list/').success(function(response) {
console.log(response);
});
Instead of JavaScript, which runs only on the client side, you should consider using PHP or other server language, to crawl your directory of files and list them inside an HTML file/template. PHP for example has scandir function, which can list files in a dicrectory
You need a combination of javascript and PHP. You could call the PHP file through Javascript, by using an AJAX call.
try this PHP file which should return an Json object:
$directory = "/directory/path";
$pdffiles = glob($directory . "*.pdf");
$files = array();
foreach($pdffiles as $pdffile)
{
$files[] = "<a href=$pdffile>".basename($pdffile)."</a>";
}
echo json_encode($files);
Now you just need to loop through the Json object to list the Url's.
Something like:
$.getJSON( "file.php", function( data ) {
var items = [];
$.each( data, function(val ) {
items.push(val);
});
$( "body" ).append( items );
});
Did not test it, but something like this should work.
Be simple. Put all your files in a directory and don't make a homepage of that directory. Then, in the page you want, add an Iframe that shows that directory. Then you will see the list of files you uploaded, all in hyperlinks. When you click on the links, the Iframe will show the PDF files.
I have the same problem.
I used to use an apache webserver with its 'fancy directory listings' and had everything setup that way, complete with headers, footers, color schemes, etc.
Then I migrated to gitlab webservers which is pure static pages only. NO Directory listings. Arrggghh...
My solution...
I continue to have the pages served in a local apache server (not world accessable), then I download the "index.html" file it generates, before uploading the index page to gitlab.
Example page generated from apache fancy directory listing...
https://antofthy.gitlab.io/info/www/
I do the same for a set of pages that used Server-Side Includes (shtml), having apache expand the page to static HTML.
Example apache SSI generated page...
https://antofthy.gitlab.io/graphics/polyhedra/
Of course this does not work with pages that rely on executable output, or CGI scripts, but for directory listings it is just fine.
Of course I would prefer to find a SSG that knows apache fancy directory listing, SSI, or even basic directory listings, that isn't over kill. BUt that is an on going search.

DOJO include files a directory back

I have dojo files in resources/js/dojo1.6/dojo/dojo.js
I have another file here resources/js/pages/file1.js
This file requires another file which is located at resources/js/folder/file2.js
This is how I am including it dojo.require('folder.file2');
So these three folder are in hirarchy
dojo1.6, pages and folder
When I run application
I got the following error
File not found: /resources/js/dojo1.6/folder/file2.js
How can I overcome this error.
You need to tell Dojo where your modules can be found, relative to dojo.js, using dojo.registerModulePath:
dojo.registerModulePath("pages", "../../pages");
dojo.registerModulePath("folder", "../../folder");
See http://dojotoolkit.org/reference-guide/dojo/registerModulePath.html for a more detailed explanation.

Categories