Handling a file upload within the padrino framework - ruby

I am building a small file upload service using the Sinatra framework with Padrino. I am pretty new to the whole world of html, php, rails style development, all of it. When using just a file_field_tag, I can generate a generic html file field tag, but as my bible w3school says, the tag merely generates a link to the file, and I need to make a ASP, PHP file to handle the actual upload of the file.
So what's going on here? Do I need to create my own php action command that lives outside of my framework? That seems like the wrong solution. I would rather have padrino handle the actual upload of files. When I did bite the bullet, I wrote a tiny php script, but my padrino form filler treats "myaction.php" as a post page, when I just wanna run my php script.

Related

Getting html content api with laravel

I need to develop an application get html content from certain urls and shows them in my own web app.
UI web application will be laravel 5.3 its ok. But the thing is key pointhere that retrieves data from urls(read and parse html content of via url)
and writes it to postgresql db migth be developed within laravel also ?
Before I decide to create this post I feel had to make an web service in python and read url and writes to db and read them within laravel web application. Which one is better or more efficient?
Besides them I also wonder that is possible develop such a web service in laravel
You can use ixudra/curl package. It's powerful, easy to use and you will be free to do anything you want. You can also save results into database. Make sure php-curl module installed on your php before you use this package. there is a pacakge named Guzzle and you can use that package but it's a little bit complicated than ixudra.
when you get html content from requested urls. You can parse the content with yangqi/htmldom package.

Load JS widget in Angular View

I have a widget that I want to plug into my angular view. I'm not sure I'm explaining it right but the code I get from the site that makes/hosts the widget is below:
<script src="http://www.somesite.com/widgetfile.js"></script>
This works perfectly fine on a standard html site (just a simple html file loaded locally in my browser). It loads the external JS file and does a document.write onto my DOM as far as I can tell.
The problem I'm having is putting this on a view in an Angular app I've built. I thought it would be the same thing as just copy/pasting the single line of script that the site gave me, but it doesn't work... error i get is below (Chrome).
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
I can't use something other than document.write because I don't have access to the file itself, the site that generates the widget does that for me. I've tried doing $http get request in my controller than putting that to a scope variable to be put on the DOM, but I get an error about cross domain security.
Any thoughts? This seems super basic to me since there are thousands of sites that offer "One line of code to embed a widget"... and it works in basic HTML pages. Am I missing something stupid (keep in mind that yes, I did copy and paste the widget script directly from the site that hosts it).
Thanks for the help. I'm pretty new with coding and newer at angular, but this seems like something that should be borderline plug-n-play and not need some complex cross domain workaround.
Try these with these two links.
http://ngmodules.org/modules/angular-widget
https://github.com/cztomsik/ng-widgets

Convert emails to HTML or PDF programmatically

I'm trying to convert emails from my mailbox, into either HTML or PDF programatically.
My main motivation is to able to create summary of emails on a web page, and able to expand a particular email and view the entire content of the email.
I figured PDF might be an option since I do not have to worry about linking the contents in the email (eg. image) to the storage location of the image.
I'm starting with the ruby Mail gem and I also came across mhonarc. I'm not sure if mhonarc is a too much for what I'm trying to do, so I decided to ask here to see if there alternatives out there.
Gem pdfkit is used for generating PDFs. Please read readme, gem requires wkhtmltopdf library in your system.
I would approach email conversion via the IMAP library (there might be newer ones out by now) and then serve everything from a simple Sinatra app in the browser. You can use a template language to generate simple html output and logic. Of course you can also use prawn for pdf generation. Many different ways to get there... Not sure why you don't just load emails and show partial content. Life can be so simple.

CodeIgniter input class outside codeigniter

I'm moving an app from flat file php to codeigniter and I'd like to integrate the two as much as possible before moving over completely. I'm looking to specifically use the input class outside of codeigniter but it looks like I'd also need to use the controller logic (to get access to input segments). Can anyone walk me through using the input library in a flat file php?
I think you're creating too much work and potential problems by trying to do this. You'll be better off if you go directly to CI. Move any standalone functions in your standard PHP files into Helper functions.
If you really want to do this, you could use CI and create controllers/functions for all your files, then in the controller functions, just include() your PHP file and ignore the models and view for now. That way you'll have access to all the CI variables, including the $this->input data.

Static web site generation

I need an easy way to generate static web pages so that I can serve them up with Apache or Nginx. Currently I am using SproutCore's build tool (Abbot) to generate static pages but that is a little bit cumbersome as it is designed for building SproutCore apps, not non-SproutCore HTML pages.
Here are my requirements:
Javascript must be combined and minified
CSS files must be combined
Each image / CSS / Javascript asset must have unique URL for better caching (query string isn't enough)
Asset URL should be different only when it really changes
Localization support thorough HTML, CSS, Javascript and image files
Nice template engine with layouts, partials etc.
Here are possible solutions I have found:
Create the site using Ruby on Rails, then get all resources using wget like http://usefulfor.com/ruby/2009/03/23/use-rails-to-create-a-static-site-rake-and-subversion/
Use Middleman: http://middlemanapp.com
Any thoughts on this?
After a longish evaluation process I have decided to use Middleman. It does the trick and I love its simplicity and the fact that I can use existing Rack components with it.
Best Regards,
Pekka Mattila
I'm the creator of Middleman and would be eager to help you get comfortable using Middleman. My main goal is to give users the power of Rails, but focused on static development. Some of the actual code of Middleman is simplified versions of Ab
Here's what I do:
Ruby on Rails 3 with the High Voltage Gem, which makes it easy
to serve a static page body using the common templates. It requires a
simple entry in the routes (and you can use namespaces to create a
hierarchy).
Apache reverse proxy to stand-alone Passenger (which uses nginx I
believe) to run the Rails app. This article describes how to
configure it.
Stand-alone passenger will read the URL, see if there is a corresponding file in /public with the .html on it, and serve that. If not found, it will invoke Rails and generate the page. In essence, page caching, with the option of publishing your URLs with or without the .html. There is a section in the Passenger docs about page caching specifically.
As far as combining and minifying js and css, here's a good stackoverflow thread.
Rails has excellent i18n/l10n support.
Rails template engine is very nice to work with. And you can use HAML if you prefer.
For your 3rd and 4th points, I'm a little confused. You want css and js combined, but then you want each to have it's own URL. In Rails, the "cache => true" directive on asset tags takes care of adding a query string parameter that changes when the content does, which is a fairly traditional scheme. I'm not sure what context you are working in where that would not work. Any CDN I've ever used works fine with that, as does an web server implementing the HTTP spec correctly. Anyway, changing the actual path or file in the URL would require changing all references to it. Maybe I'm misunderstanding?
Monkeyman has the template engine you need, I think. Think of it as Middleman's little Scala brother. Nowhere as mature or feature rich yet, but we'll get there eventually. The current incarnation supports HAML, Jade, SSP for layouts, Markdown for content and a couple of other things.
Without any special order
jekyll - quite simple
middleman - a lot of funcionalities
nanoc - a lot of funcionalities
stasis - use controllers
staticmatic
frank
gumdrop
ruby on rails + wget
ruby on rails + high voltage + apache reverse proxy
You should probably also checkout mod_pagespeed. It will at least give you this:
Javascript must be combined and minified
CSS files must be combined
Each image / CSS / Javascript asset must have unique URL for better caching (query string isn't enough)
Asset URL should be different only when it really changes
It won't give you this:
Localization support thorough HTML, CSS, Javascript and image files
Nice template engine with layouts, partials etc.
You can have a look at docpad. It's written in coffeescript and runs on Nodejs. It is document based, where you write some documents and layouts, it will compile them and write them in the out directory. You can write documents in a lot of languages via plugins
It also supports multiple level of file compilation. For example from eco to markdown to html.
Another great feature of it is that you can query on other documents being generated in a document. For example in the first page, you have something like this to get all blog posts:
database.findAll({url : /posts/})
Which will return all documents having posts in their url.

Resources