Re: [ClojureScript] Re: Saving a file

2015-02-15 Thread Immo Heikkinen
The problem is `download` property that gets munged in advanced
compilation.

You can use `aset` to prevent it from being munged:

(aset lnk download filename)

or alternatively provide extern file to tell Closure compiler not to munge
it:

function HTMLLinkElement() {}
HTMLLinkElement.proptotype.download;




2015-02-15 3:35 GMT+02:00 Mike Thompson m.l.thompson...@gmail.com:

 On Friday, February 13, 2015 at 6:05:37 PM UTC+11, Jensontech wrote:
  I need to allow the user to save content generated by Clojurescript to
 their local drive.
 
  I do it using this code -
 
  (defn- save-file
[filename content]
(let [lnk (get-element-by-id file-export-link)
  blob (js/Blob. (js/Array. content) {:type text/plain})]
  (set! (.-href lnk) (.createObjectURL js/URL blob))
  (set! (.-download lnk) filename)
  (.click lnk)))
 
  When the function runs it does a pseudo download to the named file. This
 works with :optimizations :none.
 
  When I try the same thing with :optimizations :advanced, instead of
 doing a download and prompting to open or save a file, it moves the browser
 to a URL like: blob:null/d9bbcdab-7c87-etc
 
  I have tried Chas Emericks's url package https://github.com/cemerick/url
 to create the URL but it still doesn't work.
 
  Something is being munged by the optimization, but I am not sure what.
  Does anyone have any ideas how to go about fixing this?

 I hesitate to offer advice here, because I'm just finding my way in these
 sort of matters myself but ...

 1.  You are using HTML5 APIs:  Blob and URL.
 2.  Your code works with optimisation :none, but not :advanced
 3.  I conclude that advanced optimisation is munging the symbols.
 4.  Which means you need to include externs for this API for URL and Blob)

 This appears to be the right set of externs:
 https://code.google.com/p/closure-compiler/source/browse/externs/fileapi.js

 But at that point, I run out of knowing much. Because it is part of Google
 Closure, you'd think there was some way of pulling in that file.

 Background:
 http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html


 Alternative thought ...

 Perhaps you could the `goog` wrappers for the HTML5 API:
 http://docs.closure-library.googlecode.com/git/namespace_goog_fs.html

 (But I can't see how to get a Blob).

 (ns my.module
(:require  [goog.fs  :as fs]))

 ;; later
 (.createObjectUrl   fs  blob)

 ;; or maybe
 (fs/createObjectUrl blob)

 ;; BUT no idea how to create a Blob in the first place.

 --
 Mike



 --
 Mike



 --
 Note that posts from new members are moderated - please be patient with
 your first post.
 ---
 You received this message because you are subscribed to the Google Groups
 ClojureScript group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojurescript+unsubscr...@googlegroups.com.
 To post to this group, send email to clojurescript@googlegroups.com.
 Visit this group at http://groups.google.com/group/clojurescript.


-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
ClojureScript group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: Saving a file

2015-02-14 Thread Mike Thompson
On Friday, February 13, 2015 at 6:05:37 PM UTC+11, Jensontech wrote:
 I need to allow the user to save content generated by Clojurescript to their 
 local drive.
 
 I do it using this code -
 
 (defn- save-file
   [filename content]
   (let [lnk (get-element-by-id file-export-link)
 blob (js/Blob. (js/Array. content) {:type text/plain})]
 (set! (.-href lnk) (.createObjectURL js/URL blob))
 (set! (.-download lnk) filename)
 (.click lnk)))
 
 When the function runs it does a pseudo download to the named file. This 
 works with :optimizations :none.
 
 When I try the same thing with :optimizations :advanced, instead of doing a 
 download and prompting to open or save a file, it moves the browser to a URL 
 like: blob:null/d9bbcdab-7c87-etc
 
 I have tried Chas Emericks's url package https://github.com/cemerick/url to 
 create the URL but it still doesn't work.
 
 Something is being munged by the optimization, but I am not sure what.
 Does anyone have any ideas how to go about fixing this?

I hesitate to offer advice here, because I'm just finding my way in these sort 
of matters myself but ... 

1.  You are using HTML5 APIs:  Blob and URL.   
2.  Your code works with optimisation :none, but not :advanced
3.  I conclude that advanced optimisation is munging the symbols.
4.  Which means you need to include externs for this API for URL and Blob)

This appears to be the right set of externs:
https://code.google.com/p/closure-compiler/source/browse/externs/fileapi.js

But at that point, I run out of knowing much. Because it is part of Google 
Closure, you'd think there was some way of pulling in that file. 

Background:  
http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html


Alternative thought ... 

Perhaps you could the `goog` wrappers for the HTML5 API:
http://docs.closure-library.googlecode.com/git/namespace_goog_fs.html 

(But I can't see how to get a Blob).

(ns my.module 
   (:require  [goog.fs  :as fs]))

;; later
(.createObjectUrl   fs  blob)

;; or maybe
(fs/createObjectUrl blob)

;; BUT no idea how to create a Blob in the first place.

--
Mike



--
Mike



-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
ClojureScript group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.