sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

    Scheduled Pinned Locked Moved Plugins
    37 Posts 5 Posters 30.7k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      @alexschreyer said:

      1. ... So the undo option is meant for undoing the SU action. ...
        OK just so you know, and hopefully the users will also.

      I thought of a scenario: What if a user wishes to actually experient themselves with the undo API feature, writing the .start_operation, .commit_operation calls into the snippet editor? What would happen in ruby with double nested operations? Perhaps a checkbox next to the UNDO button to turn on|off the editor's Undo calls, ie(as_rubyeditor.rb):
      line 74: Sketchup.active_model.start_operation "RubyEditor" **if @undo_is_on**
      line 82: Sketchup.active_model.abort_operation **if @undo_is_on**
      line 84: Sketchup.active_model.commit_operation **if @undo_is_on**

      @alexschreyer said:

      1. Until there is a multi-file version of the editor, the multi-instance option is actually useful. Question: On close, can I destroy an instance like "UI::WebDialog = nil".
        Agreed, and actually even with a multi-file version (if you don't have a split screen feature,) then allowing two instances can satisfy those who'd want a split screen feature, (ie: 'cut & pasting' between two windows.) But we need to control instancing, and limit it (with a default limit, which might be overridden by the user.) I'm using a class variable: @@max_num
        Garbage Collection. You would not set the class to nil. You are suppossed to be able to set the instance to nil and then call GC.start, but I've never witnessed GC disposing of the instance variable. It just sits around with a nil value (at least it's not taking up much space.) So ..
        dlg=Namespace::RubyEditor.new( *arglist* ) #.. set it up.. show it .. use it .. close it dlg=nil GC.start
        Anyway... in this case: we first must use a symbol to hold a reference to each instance. In editor code (line 205) in the add menu item command block you have (as Jim did,): "RubyEditor.new" which is not storing a reference to the instance, even though the object.new method always returns a reference to the newly created instance of the object class (which is the third main task of the new method in ruby.)
        I'm using an Array class variable: @@instances=[]
        and when I construct the instance, I push it's reference into the array:
        if @@instances.size < @@max_num %(#F0F0F0)[__]num = @@instances.size+1 %(#F0F0F0)[__]if dlgi = WebConsole.new(num) # non-nil if success %(#F0F0F0)[____]@@instances.push( dlgi ) %(#F0F0F0)[____]# add menu link for instance %(#F0F0F0)[__]end end
        The num var is used both to insert into instance menu text (similar to an editor's untitled(1), untitled(2) captions,) and is passed to new, so the instance itself can know which one it is (it's position in the class array var @@instances,) and to append as text onto the instance's Preferences Key suffix.
        All that if block, above is wrapped within a UI::Commandclass instance @@cmd
        __

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        BY the way... you announced a ver 1.1.1, but...

        The Revision block at the top of as_rubyeditor.rb says version: 1.2
        (The extension registration/loader script says version: 1.1.1)

        The thread topic (title of the first post,) still says version 1.1

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • alexschreyerA Offline
          alexschreyer Extension Creator
          last edited by

          @dan rathbun said:

          The Revision block at the top of as_rubyeditor.rb says version: 1.2

          I keep missing those little details... Thanks!

          @dan rathbun said:

          Perhaps a checkbox next to the UNDO button

          Great idea. I'll put this into the preferences section, though.

          @dan rathbun said:

          Garbage Collection

          Thanks for the detailed explanation. I'll look at it.

          But zooming out a little: It seems to me that we could maybe work more effectively on this if it were a collaborative project. I haven't worked with Github or similar systems before, but from what I understand it is made for stuff like this. Would you (and anyone else interested, of course) want to move this to a collaborative project?

          Cheers,
          Alex

          Author of "Architectural Design with SketchUp":
          http://sketchupfordesign.com/

          1 Reply Last reply Reply Quote 0
          • A Offline
            alz
            last edited by

            Wow -- very nice and helpful plugin! I almost wish I could run it outside of SketchUp 😛

            Have you thought about adding syntax highlighting? Something to pop out basic Ruby keywords and SketchUp-specific keywords?

            1 Reply Last reply Reply Quote 0
            • alexschreyerA Offline
              alexschreyer Extension Creator
              last edited by

              @alz said:

              Have you thought about adding syntax highlighting?

              I actually had it in there at the beginning. Unfortunately (since it uses Javascript), I found that it would get very slow with moderately sized files. But I agree it would be nice.

              Cheers,
              Alex

              Author of "Architectural Design with SketchUp":
              http://sketchupfordesign.com/

              1 Reply Last reply Reply Quote 0
              • C Offline
                chrisjk
                last edited by

                @alexschreyer said:

                @alz said:

                Have you thought about adding syntax highlighting?

                I actually had it in there at the beginning. Unfortunately (since it uses Javascript), I found that it would get very slow with moderately sized files. But I agree it would be nice.

                Cheers,
                Alex

                I am way out of my depth here not knowing any ruby or javascript but could you not use the same functionality provided by the browser that is used to highlight words in say a google search?

                Chris

                1 Reply Last reply Reply Quote 0
                • alexschreyerA Offline
                  alexschreyer Extension Creator
                  last edited by

                  @chrisjk said:

                  could you not use the same functionality provided by the browser that is used to highlight words in say a google search?

                  Although I can find words easily in a textarea (the editor field), I can't highlight it unless I use a custom html-formatted component. In any case, there needs to be some code that runs on every keypress that scans the entire document and formats words. For longer documents that becomes quite slow.

                  I looked at this editor:
                  http://ajaxian.com/archives/editarea-rich-sourcecode-editor

                  It is pretty neat but I figured, considering the performance issues, that once someone wants highlighting, they'll switch to Notepad++ or other external editors anyways.

                  Cheers,
                  Alex

                  Author of "Architectural Design with SketchUp":
                  http://sketchupfordesign.com/

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    driven
                    last edited by

                    Hi Alex,

                    you are more than likely aware of dCode, it does seem to be abandoned, I have posed questions about it before without response, but it does seem to have some useful features the are already tuned to SU. http://www.errorinitus.de./sketchup/dcode/help/1.0_RC1/index_en.html

                    I was looking at doing something with it myself but it's all way out of my league... and maybe it's crap...

                    happy to test and comment though

                    the latest RCE is working quite nicely on both my Mac's, thank you

                    john

                    learn from the mistakes of others, you may not live long enough to make them all yourself...

                    1 Reply Last reply Reply Quote 0
                    • alexschreyerA Offline
                      alexschreyer Extension Creator
                      last edited by

                      Just updated to version 2.0. Download in the same location as before.

                      Cheers,
                      Alex

                      Author of "Architectural Design with SketchUp":
                      http://sketchupfordesign.com/

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        driven
                        last edited by

                        hi Alex,

                        looking good, but there's a parsing issue with complex saved files.

                        this may just be a mac thing, but, I could always do it with previous versions.

                        if you edit as_rubyeditor.rb in 'itself' and then 'save' on SU restart it fails to load 'it' due to this happening.

                        Encode backward slashes and single quotes in Ruby

                        234          text.gsub!('\\', "<84JSed>")
                        235          text.gsub!('\'', "<25SKxw>")   
                        

                        becomes

                        234         text.gsub!('\\', "\")
                        235         text.gsub!('\'', "'")
                        

                        and also

                        245          dlg.execute_script("tmp = tmp.replace(/<84JSed>/g,'\\\\')")
                        246          dlg.execute_script("tmp = tmp.replace(/<25SKxw>/g,'\\'')")
                        

                        becomes

                        245         dlg.execute_script("tmp = tmp.replace(/\/g,'\\\\')")
                        246         dlg.execute_script("tmp = tmp.replace(/'/g,'\\'')")
                        

                        The 'new' file then fails on restart with SU error messages

                        it also adds a return after 'end' at 403, but I don't think that will cause problems.

                        All I was doing, was changing to show_modal, which works fine when done in external editor.

                        362         show_modal do
                        

                        I'll see if there are any other Mac issues (or solutions) over the next few days and let you know.

                        john

                        learn from the mistakes of others, you may not live long enough to make them all yourself...

                        1 Reply Last reply Reply Quote 0
                        • alexschreyerA Offline
                          alexschreyer Extension Creator
                          last edited by

                          @driven said:

                          there's a parsing issue with complex saved files.

                          Hi John,

                          It should just be the plugin file. I needed to put the "encoding dance" in there so that those symbols load correctly. That's why I chose something like "<84JSed>" - the chance that another file uses these letters is pretty slim (except for the plugin file, of course).

                          Edit the plugin file itself in another editor and it should work fine. Use my editor for any other files.

                          Cheers,
                          Alex

                          Author of "Architectural Design with SketchUp":
                          http://sketchupfordesign.com/

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            driven
                            last edited by

                            hi Alex,

                            I had sorted out the editor, edit, and later realised the parsing only effected 'itself'.

                            I've been digging out all my Mac code editor 'theme' tweeks and some may interest you, I think there's an IE9 versions of these for example

                            .CodeMirror{   background;transparent; color;inherit; border;none; cursor;text;}
                            .CodeMirror-gutter{ background-color;transparent; opacity;.5;}
                            .CodeMirror-cursor{z-index;10;  position;absolute;  visibility;hidden;  border-left;2px solid #lime !important;  color;transparent;  background-color;transparent;}
                            .CodeMirror-lines pre;nth-child(odd){background; rgba(255,255,255,0.1); }
                            .CodeMirror-lines pre;nth-child(N);hover{background; rgba(255,0,0,0.2); }
                            
                            

                            these are in addition or overwrite what you've already got.
                            I'm also porting a version of my ace theme 'blendin' but I'll need to enable a few more codeMirror functions as I go...

                            couple of jquery-ui things don't work and it through me trying to get the line scrolling to work because you use pt instead of px for fonts [px=pt/.75] and it frond upon a bit to use for screen media... The scrolling line were working with pt, but I've swopped pt's to px's or em's for personal convenience.
                            the hover and scroller highlight didn't show up in the grab...

                            oh, the line only appear if there's code.
                            john

                            learn from the mistakes of others, you may not live long enough to make them all yourself...

                            1 Reply Last reply Reply Quote 0
                            • alexschreyerA Offline
                              alexschreyer Extension Creator
                              last edited by

                              John, thanks for looking at this so closely. I wanted to put line highlighting in there but didn't get to finishing it. I'll check it out later. Thanks for the CSS suggestions.

                              In the past I found that text could be defined in pt as long as line-height is defined in px (to make line coloring work). I might switch to px at some point - I usually like that better for my web pages.

                              I was thinking about putting the code on Github - I am very happy if others can help out here (or create their own fork). Should I pursue this? I actually haven't used GIT before.

                              Cheers,
                              Alex

                              Author of "Architectural Design with SketchUp":
                              http://sketchupfordesign.com/

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                driven
                                last edited by

                                Yes, git seems relatively straight forward, although I've only started using it recently for ace and cloud9 cloning.

                                For a slow start you then get a free cloud9 account, upload a trunk from git, and maybe we could do some interactive editing?

                                I really liked codeMirror, but couldn't sort out the ruby bits for SU and was thinking of asking for your help with either it or ace, when you anounced this.

                                I'll happily jump back to CM as it's so much simpler (after cloud and ace) although I've been running those off my localhost, rather than from inside 'plugin folder' and there's lots of plusses in that.

                                I'm really a Mac man, and most my tweaking is html5 and css3 and a little js, so IE input would be limited.

                                john

                                learn from the mistakes of others, you may not live long enough to make them all yourself...

                                1 Reply Last reply Reply Quote 0
                                • alexschreyerA Offline
                                  alexschreyer Extension Creator
                                  last edited by

                                  Great! Would be perfect to have you help work on this because I am mainly developing in Windows and the Mac side is the last thing I look at.

                                  I am away at a conference for a week but we can get this started after Easter.

                                  Cheers,
                                  Alex

                                  Author of "Architectural Design with SketchUp":
                                  http://sketchupfordesign.com/

                                  1 Reply Last reply Reply Quote 0
                                  • D Offline
                                    driven
                                    last edited by

                                    Hi Alex,

                                    are you back from your conference?

                                    I did a bit of re-jigging of the file folders so that you can have the standard css (CM lang) with the light themes and yours with the dark.

                                    I've been trying to add long comments, but my js is even worse than my ruby...
                                    shoot me a line when your around and I'll send the files that I tweaked.

                                    john
                                    I've got all the themes back...

                                    I just noticed the moved the theme switcher, but that's just for faster testing....

                                    learn from the mistakes of others, you may not live long enough to make them all yourself...

                                    1 Reply Last reply Reply Quote 0
                                    • alexschreyerA Offline
                                      alexschreyer Extension Creator
                                      last edited by

                                      John, those changes look great! And yes, I am back now...

                                      I am trying to wrap my head around GIT and it's wrapping very slowly. If I did everything right, then there should be a repository on GITHUB now at the following address that has all of the files in the correct locations. Can someone who knows more about this than I do test this out?

                                      Link Preview Image
                                      GitHub - alexschreyer/Ruby-Code-Editor-for-SketchUp: A nice-looking code editor for SketchUp. Supports Ruby and various other languages.

                                      A nice-looking code editor for SketchUp. Supports Ruby and various other languages. - alexschreyer/Ruby-Code-Editor-for-SketchUp

                                      favicon

                                      GitHub (github.com)

                                      Feel free to use the repository for collaborating on this project once we establish that the files are actually correctly up there.

                                      Cheers,
                                      Alex

                                      Author of "Architectural Design with SketchUp":
                                      http://sketchupfordesign.com/

                                      1 Reply Last reply Reply Quote 0
                                      • D Offline
                                        driven
                                        last edited by

                                        hi Alex,

                                        yes it's there, almost...

                                        you can't actually test or modify without the ui.html and it's support files.

                                        do you want to put those in as well, so it's the full monty.

                                        when you do I'll see if I can update (what I just downloaded) directly from terminal.

                                        adding and 'experiments' folder uploading to would be good as well.

                                        john

                                        learn from the mistakes of others, you may not live long enough to make them all yourself...

                                        1 Reply Last reply Reply Quote 0
                                        • alexschreyerA Offline
                                          alexschreyer Extension Creator
                                          last edited by

                                          @driven said:

                                          ...without the ui.html and it's support files...

                                          It should all be there.. ui.html is in there. As far as I understand GIT, you just create a "fork" and start modifying.

                                          I just added a v.2.0 tag so that the uploaded snapshot is the same as the last download from my site.

                                          Cheers,
                                          Alex

                                          Author of "Architectural Design with SketchUp":
                                          http://sketchupfordesign.com/

                                          1 Reply Last reply Reply Quote 0
                                          • D Offline
                                            driven
                                            last edited by

                                            the tarball doesn't have all the files, I'll have another look

                                            john

                                            EDIT... but the zip file does, my experience is that the tar should have everything as well...

                                            learn from the mistakes of others, you may not live long enough to make them all yourself...

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement