Html multiline, js to SketchUp
-
@chris fullmer said:
I'm thinking maybe I could delete line breaks and replace them with a special character combo ...
@unknownuser said:
escape
Returns the hexadecimal encoding of an argument in the ISO-Latin-1 character set.
Core function
Implemented in
- JavaScript 1.0, NES 2.0
- ECMA version ECMA-262 compatible, except for Unicode characters.
see: escape()
-
@chris fullmer said:
Any thoughts how to pass this more cleanly into SketchUp? I'm thinking maybe I could delete line breaks and replace them with a special character combo like "^
^" and then rebuild the lines in SketchUp - all_lines = query.split("^
^") or something.On the Js side you would use replace
see: http://docs.oracle.com/cd/E19957-01/816-6408-10/string.htm#1194258
I think Jim had an example in his old WebConsole where he changed special characters " to "
see:[url=http://msdn.microsoft.com/en-us/library/aa752007(v=vs.85).aspx:firgcgl8]ISO Latin-1 Character Set[/url:firgcgl8]
for example, a single quote (apostrophe) is '
also:- [url=http://msdn.microsoft.com/en-us/library/aa752009(v=vs.85).aspx:firgcgl8]Character Entities for Special Symbols[/url:firgcgl8]
[url=http://msdn.microsoft.com/en-us/library/aa752008(v=vs.85).aspx:firgcgl8]Additional Named Entities for HTML[/url:firgcgl8]
On the Ruby-side you would use a inverse of the regular expression, but with the
gsub!()
method, ortr!()
etc. There are quite a few Ruby methods you can use. - [url=http://msdn.microsoft.com/en-us/library/aa752009(v=vs.85).aspx:firgcgl8]Character Entities for Special Symbols[/url:firgcgl8]
-
Awesome, thanks for the tips Dan. I like the look of the escape() method in js. I'll probably post back eventually once I get around to trying to unescape it in ruby.
Thanks!
-
Great, thanks again! I got your PM. I do have ruby 1.8.6-p287 installed. but that sure made it easy. Thanks Dan,
Chris
-
@aerilius said:
If the text can contain any user input, you need to ... escape and urlencode the text.
Here's another idea if you'll be using %hex uri-encoded strings:
On the Ruby-side:
- cut and paste the "Ruby186/lib/ruby/1.8/uri/common.rb" INSIDE your plugin sub-module
- delete the alias method for the
Kernel
module (at the bottom of the file.) - cut it down by removing any unwanted comments, or methods that you do not need for your plugin.
-
If you do not have Ruby v1.8.6-p287 installed, I can PM you the "uri/common.rb" file.
-
EDIT: Went ahead and PM'd ya' the file.
ADD: The online doc for URI::Escape
On the Javascript-side you might be able to get away with using the built-in
%(#8000BF)[escape()]
and%(#8000BF)[unescape()]
functions. -
Your welcome ...
ADD: The online doc for URI::Escape
-
@dan rathbun said:
[*]cut and paste the "Ruby186/lib/ruby/1.8/uri/common.rb" INSIDE your plugin sub-module
Thanks Dan, this works well. I know another basic question, but is it possible to have the "require" statement in my plugin specify a relative path to common.rb i.e. I currently have to use
require 'MyPlugin/common.rb'
from the MyPlugin.rb file, even though they are both in the same folder, i.e. the plugins/MyPlugin folder.@dan rathbun said:
On the Javascript-side you might be able to get away with using the built-in
%(#8000BF)[escape()]
and%(#8000BF)[unescape()]
functions.Do you know if it is possible to port the 1.9.2 version of the common.rb library to work in Sketchup. This would allow you to use the new
encode_www_form
andencode_www_form_component
methods which also have corresponding methods in JS. -
(1) I said inside your module (not your directory!) Messing with require would not be good idea. But you can do whatever inside your own module. Override the method your module inherited. You can always call
Kernel.require()
to use the original, but this all sounds silly.There is a code example here I wrote that shows using the
SketchupExtension
class, and dealing with paths. (Check the Code Snippets index.)(2) Likely NOT. Ruby 1.9.2 has totally overhauled encoding. It's the reason SketchUp will not load it (I have tried.)
-
@dan rathbun said:
(1) I said inside your module (not your directory!) Messing with require would not be good idea. But you can do whatever inside your own module. Override the method your module inherited. You can always call
Kernel.require()
to use the original, but this all sounds silly.Sorry Dan, I am being really thick here . Are you saying I should cut and paste the code in common.rb into MyPlugin.rb file...?
btw it appears that I can use the URI.escape() method without doing a require or even having the common.rb file in my plugin directory. Does Sketchup not maybe support it now out of the box?
@dan rathbun said:
There is a code example here I wrote that shows using the
SketchupExtension
class, and dealing with paths. (Check the Code Snippets index.)Again being a bit slow... but where is the code example you refer to?
Thanks for the help.
-
@myhand said:
Again being a bit slow...
If you weren't, ... then I wouldn't feel so smart!
@myhand said:
... but where is the code example you refer to?
See all the topics at the top of the topic list that are shaded ? They have a special icon, because they are called "sticky topics". They always appear at the top of the list on page 1 (in any forum, but vary from forum to forum.)
For instance in the Plugins Forum, you will discover that Jim Foltz maintains a [ Plugins Index ] sticky topic.
In THIS forum, he has a [ Code Snippets ] index, to which I have added a manual categorical index.
Anyway... you can look under my name in the Author index.
.. and you'll find: "[Code] SketchupExtension and rbs rubies" -
@myhand said:
btw it appears that I can use the
URI.escape()
method without doing arequire
or even having the "common.rb" file in my plugin directory.Does Sketchup not maybe support it now out of the box?
No way. Either the Development Tools loaded it ... or you pushed the absolute path to your plugin sub-dir into the
$LOAD_PATH
array.... or you used the SketchUp API's
require_all()
global method (defined in "Tools/sketchup.rb",) which will push the argument path into$LOAD_PATH
. (But does not remove it afterward... which may not be the best implementation.)On the subject of autoloading files, and controlling them ... I have a example called !autoload.rb, see the snippets index, to find it.
-
@myhand said:
@dan rathbun said:
(1) I said inside your module (not your directory!) ...
Sorry Dan, I am being really thick here . Are you saying I should cut and paste the code in common.rb into MyPlugin.rb file...?
It is what I told Chris to do (in case he didn't wish to have users of his code do a full Ruby install.)
%(#8000FF)[An aside rant to any reader who won't read a book, and learn the basics,
before diving in and attempting to write complex projects:]If you don't know what I meant by "inside your module" you likely did not follow the advice in my Newbie Guide, and have skipped over learning the nitty-gritty basics of Ruby. Yes it can be boring, but your just running into frustrations because you don't know the simple things.
Really .. print out a chapter a day from the ol' "Pick-Axe" book, and put it next to toilet. Don't waste the time when your sitting on the pot.
In a nutshell... you need to be writing all your code within YOUR unique top-level namespace (which is a
module
in Ruby.)Unwrapped code runs within the
TOPLEVEL_BINDING
, which is the global instance ofObject
... and everything is a descendant ofObject
, so everything inherits whatever is defined inObject
.Other authors do not want your objects, variables etc, propagating into their plugins.
OK ... back on subject, ... "uri/common.rb" ... for now just leave it in the Ruby lib directory, where it belongs, and use a script similar to the one posted to push paths for a full Ruby install.
See: Ruby LOAD PATHs script (Win32)
Advertisement