Hello fellow coders & codetts
I was wondering, if I needed to create a rich text formatted document using html and css, which will be used inside a UIWebView, could I then insert cocoa calls inside HTML tags? I do this in ruby, and many other langs do this as well, but I do not know if possible on the iphone.
My main goal is to display a report that will pull data from coreData entities, format it to look pretty, and then create a PDF for the user to email or print.
The only reason I am using HTML is that is what someone here # StackOverflow mentioned that was the best practice for the iphone. But I would really like to be able to just create a PDF without the HTML and UIWebVIew, so If you know how this can be done, by all means do tell, the world wants to know.
thank u for your precious time
No, you can't (easily) access your Cocoa objects and classes from HTML/JavaScript. You can, however use Cocoa to call JavaScript methods on the loaded webpage. You can use these JavaScript methods to pass data from Cocoa to the web page, and in those JavaScript methods, you can then change the content of the webpage. That would look something like this:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"doSomethingWithString('%#');", stringToPass]];
And on the JavaScript side:
function doSomethingWithString(passedString) {
// show stuff in webpage
}
Related
I have created HTML code that creates a layout for information that my iPhone app gathers from the user. I would like to be able to take the html string and place the right values in the right location, but cannot think of a good way to accomplish this.
Example.
<html>
<body>Name:</body>
</html>
And I am wanting to put "Eric" after "Name:".
Because my html file is much larger than this I am just trying to think of the most efficient way to basically add NSStrings into my long html NSString...
Thanks,
Eric
You can do: NSString *html = [NSString stringWithFormat:#"<html><body>Name: %#</body></html>", #"Eric"];
While unknown about it's efficiency, you can use UIWebview's stringByEvaluatingJavaScriptFromString to execute javascript to replace values inside your HTML page using javascript.
There are two ways to do this:
Dynamically create the javascript method, then invoke it
Invoke a statically created javascript method that is already part of your html file.
You should be able to invoke jQuery, in which case it would be painfully easy to modify the dom.
Check out this link for an example of js injection.
http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview
What I am trying to do is to load a webpage into in a UIWebView. The problem is that I need to do some preprocessing on the html before displaying it in the web view.
The UIWebview loadHTMLString is quiet slow when the html is big. I don't need to display the full page therefore i am trying to remove some html nodes before displaying it in the web view to speed up the loading time.
I don't think using regex for that is a wise idea. I checked out NSXMLParser and TFHPPLE but I couldn't find any way to remove nodes from the html tree using an XPath or something.
I know I could do that using Javascript but that won't solve my problem. I also don't have no control on the website so I can't edit in the webpage itself.
Is there something as easy as deleteNodeUsingXPath or something :)
Cheers and thanks a lot for your help in advance.
One possibility solution: do a proxy website which strips out unwanted stuff. The iphone accesses the proxy website URL. The proxy website loads from the original website, strips out unwanted stuff, and replies with the remaining stuff.
There is a tool called Objective-C-HTML-Parser that will do what you are looking for. The documentation is thorough, and the implementation is pretty straight-forward.
Basically, you take your HTML string and make an HTMLParser object that you can then manipulate however you want. It is a very powerful library that basically lets you do whatever you want with HTML with easy-to-use Objective-C APIs.
Good luck!
I have made a simple blog using Node/Express/Mongo/Jade (and/or HAML.js). I used (and slightly updated) the blog app from this tutorial, which itself an update of one from howtonode.org
I can render attributes such as links, etc., with the template engine just fine, but when I pass data from the db, none of the html renders. I get plain text print-outs of the HTML. I figure I need some other node packages/modules to render the 'dynamic' content, but I don't know where to start.
In jade, when you're passing content you DON'T want to be escaped, be sure you pass it along as != instead of =
BE EXTREMELY CAREFUL THOUGH! If you don't manually parse out the bad stuff, you could make your website extremely vulnerable.
You can read some more jade documentation here
Are there any good thing, best practice or profit we have after using the HTML helper in an ASP.NET MVC project?
When I am trying to use them I found that I lose the speed I have with HTML and many difficulties I have whenever I use an HTML helper.
Other [non-techie] persons can't understand what I write using Helper if I want to show them or they want to do something they need to spent more time on, even if they have working knowledge of HTML.
If I use an HTML helper I lose the speed. When I use HTML I just type and of course I am not aware of it. But using helper, it is hard to understand.
What thing do we get when I use HTML helper? I think it is nothing I get because I lose the speeed. Others can't understand what I do using helper and can't customize the code if they want.
Why do we use HTML helpers?
You use HTML helpers to encapsulate some small HTML fragments which are repeated all over your pages. And to avoid writing those HTML snippets all over again you use helpers.
They are very useful, especially when dealing with things like URLs because instead of hardcoding your links helpers take advantage of routing the definition on your server and by simply changing those routes the whole site URLs' change without ever touching any single HTML page.
Another scenario where HTML helpers are useful is for generating form input fields. In this case they automatically could handle values when posting back and show associated validation messages. Can you imagine the spaghetti code you would have to write in your views if there weren't HTML helpers?
The biggest advantage I find is with the editor and display templates.
If your editor for a field is more than just a simple input box, you can put that into a template and replace the several tags with a call to
<%:Html.EditorFor(m=>m.Property)%>
This means that your page is a lot easier to edit as you aren't wading through a lot of fluff HTML to find what you want.
I have an iPhone application which needs to generate a local HTML file from a template and then render the HTML in a UIWebView. It basically needs simple Django-like template features, just to replace template tags with values and simple enumeration over collections (for instance to generate rows of a table). Is there some existing simple template framework available for iPhone apps (implemented in C or in Objective-C of course)? I looked at Dashcode but that does not fit my needs I dont think. I have an HTML file I just want to replace values in it and enumerate/loop over collections to do it. I cant use Javascript for this actually because HTML needs to be email-able.
Thanks.
Take a look at MGTemplateEngine
https://github.com/groue/GRMustache may help you.
I've written a simple tempalte class once. It had <%= foobar %> style tags in it. I would call [myTemplate setValue:#"I like SO" forVar:#"foobar"] which would find the tag and replace it.
Looping and enumeration might be much harder. Maybe there is a ObjC templating library out there that I don't know of.