How to write w3c-conform Angular-Material applications? - angular-material

I am writing a web application using AngularJS and Angular Material. I'd like to write valid HTML code (according to the w3c-validator).
I already know that I can write valid AngularJS directives like this:
<body data-ng-app="myApplication" data-ng-cloak>
However, AngularJS uses a lot of custom tags, such as:
<md-content></md-content>
I already tried several search queries on Duckduckgo, Google, and Stackoverflow but I can't find an answer on how to rewrite these tags in order to create valid HTML code.

Related

Performance difference between plain HTML and Rails/ERB helper templates

I am new to rails and trying to understand this concept, as there are many things which we write using helpers(erb/rails tags) can also be written using simple plain html , is there any other advantage to using rails/erb helper than enabling to write more simple and readable code.
As the end result of writing the erb/rails template is always going to be a plain html , so initially by writing plain html do we reduce load on server or reduce servers efforts of converting the rails/erb templates into plain html.
Note: I am specifically asking for more of static templates e.g web forms , links , form contents,etc.
Here're some of merits.
Ability to Collaborate with models and helpers
It automatically generates post url and form labels etc. So, say you're changing the name of a model or url, if you were writing plain html for all templates, you'll have to manually replace all of occurrences on your own, whereas the "rails-way" can handle them all just with one line of modification or one command execution.
Can take advantage of template libraries.
There're lots of awesome template libraries that generate html from ruby code.
https://github.com/plataformatec/simple_form
https://github.com/justinfrench/formtastic
Gives you better abstraction
It gives you good abstraction in the way that it makes you write what you want instead of how you do. For example in my previous project, I was using bootstrap2 and decided to move to bootstrap3. If I were writing plain html, I had to see all html files, and inspect sometimes intricately structured html tags, classes, and find all bootstrap2 specific elements and change them all. But thanks to the template generation gem I was using, all I had to do was basically to upgrade the gem and add a few lines to some config files.

Want To Use Twitter Bootstrap Code and html_safe in Rails 4 Application

I have a Rails 4 application which uses a PostgreSQL 9.2.x database that stores html emails. I have a text area field that contains the html5 code for the email.
<%= #mass_email_parm["email"].html_email_text.html_safe %>
In the past I have only used straight html5 code which of course works really well. However for another application I would like to use Twitter Bootstrap code in the field to nicely format a newsletter. When I created a record with Twitter Bootstrap code everything appeared in the email but the Twitter Bootstrap formatting was ignored.
Is there a similar feature similar to html_safe or a gem available that will allow me to place Twitter Bootstrap code in a database field being used in a mailer? For now since I already have my own database I would like to avoid using another service such as MailChimp.
I have searched online but I have not found anything where html_safe is used with Twitter Bootstrap code.
I will continue searching.
It sounds like you're saying that the CSS styling from Twitter Bootstrap is being ignored. Twitter Bootstrap comes with tons of CSS. So if you produce HTML that is not also rendering along with that CSS it will not look right. So, for emails... this just isn't a good choice because you can't really include pages and pages of CSS code with each email sent. Furthermore, even if you did it wouldn't look the way it was intended to in many email clients. Pretty much no modern CSS HTML practices are a good choice for formatting emails. You've got to use simple tables for layout and mostly simple, inline styles. This is because emails are not like browsers... in fact many email clients aren't even run in a browser... some are run in the command line. So you're trying to satisfy the least common denominator when it comes to formatting HTML in emails. And that means no Twitter Bootstrap code or anything like it.

Using AngularJS in Ruby on Rails app

I have a existing project in Ruby on Rails.
What is the best way to use AngularJS in Ruby on Rails app?
I want to use AngularJs for only specified modules, not for create SPA. This is good way?
What I have seen colleagues do in order to achieve this sort of integration with an existing rails app is:
Include angular.js and relevant dependencies in the specific app pages that are to be 'angularized'
Interpolate whatever data is needed to bootstrap the angular controller into the html template which contains the angular app. This might include data about the resource being operated on. I've seen this done by rendering a RABL template inside of a haml/erb template.
Using that interpolated data, call whatever API methods you need to get additional data on the fly. This is usually just a matter of implementing json handlers for routes you've already created.
I can't say whether this is best practice, but its an easy way to get started fast.
Best of luck, angular is a very enjoyable tool to work with once you get used to it.

Backbone & Rails. Why do you set routes in backbone?

js and I want to create a rails app with backbone. The only problem is, I cant seem to figure out what goes in the backend and what goes in the frontend. The approach I am using is to use rails essentially as an API.
I am looking at various different approaches and I cant seem to quite understand why you route in backbone as well as using normal rails routing.
My theory is:
You use rails to display initial html pages, and you use backbone routing to route the javascript files to that html pages so you can perform DOM manipulation there.
Here is the part of my code where I got that idea from. (NOTE: this is all mainly taken from Ryan Bates railcast on backbone.js)
backbone router
class Poster.Routers.Posts extends Backbone.Router
routes:
'':'index'
'posts/:id': 'show'
initialize: ->
#collection = new Poster.Collections.Posts()
#collection.fetch({reset: true})
index: ->
view = new Poster.Views.PostsIndex(collection: #collection)
$('#index_container').html(view.render().el)
views/main/index.html.erb
<div id="index_container"></div>
So does this backbone routing essential do the equivalent of just loading the javascript in the index: method at the top of the views/main/index.html.erb? (i know actually copying those javascript lines into the index.html.erb file wont work, its just a conceptual question)
Backbone is designed to be used in single-page applications, therefore it has a little to do with Rails routing. All Rails has to do is land a .html page, and everything else is client's concern.
If you intend to use Rails as an API, then its routing does not matter at all. You can even keep Rails application and frontend on different servers. In this case all what Rails has to do is process requests from the client.
For example, you can build your client-side without any hard ties to a backend, they can be absolutely separated. You just make AJAX calls from a client, then server processes them and responds with JSON.
Also, Backbone does not "route the javascript files to that html pages". It just executes functions according to a hash "route: action". These are just plain JavaScript functions which already can "see" JavaScript working within the document.

trying to build simple web app with Google Maps API

I'm trying to build a simple web app using the Google Map API. I haven't decided if I want to use Rails or Django yet. I've been looking for some tutorials, but none have given me really what I'm looking for. Understand, I'm a newbie when it comes to both Rails and Django.
What I want to do is like this:
http://durasupreme.com/dealer-locator
Where you type in a zip code and it returns a map with pins for the locations on a map. I already have the database information, I'm just wondering what the best way to do this. I feel like I have the idea, I know the tools I need to use, but I don't know how to put it all together.
Any help or links to resources would be greatly appreciated.
D
Here are a few useful links if you decide to go for Rails:
Geocoder
Railscast about Geocoder
Google Maps for Rails
What you are trying to do doesn't have much to do with Django or Rails. It will be mostly javascript. Here's a simple implementation outline:
Follow the tutorials to get started on google maps api on a static local html file.
In javascript write a map_init and add_marker helper functions.
When confident, add the link, div, and script tags you wrote to your template.
Have your view/controller method get a list of objects from the db.
Pass them to the template
In the template do a for loop over the object list.
inside the loop use the appropriate obj attributes to feed the add_marker helper function.

Resources