editor to scripted files

MiServer is Dyalog's APL-based web development framework

editor to scripted files

Postby Gantois on Tue Jun 10, 2014 6:24 pm

Hello! Good Afternoon!

I am reading MiServer User Guide to learn how to create APL web pages and I have some questions. Could you help me?

I have already used with success APL editor to make some classes, inside a WS. (classes to access my Component Files)
It has an example on user guide page 19( ]SAVE helloworld C:\MyMisite/ ) saving a scripted file (.dyalog), but I could not edit it to change.
I also read that any of these scripted files can be edit both from inside an APL session and from a text editor. From a text editor (notepad++) I have no problem but it has no APL characters . Using )edit oNameofClass I could not do.

What editor do you recommend me to APL sites development?

Thanks,
Att, Marco Gantois
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: editor to scripted files

Postby Brian|Dyalog on Wed Jun 11, 2014 4:46 pm

Hi Marco!

You raise several good questions in your post; I'll try to address them here.

Using ]SAVE and ]LOAD...
]SAVE and ]LOAD are user commands that implement interfaces to the SAVE and LOAD functions in SALT (the Simple APL Library Toolkit). You can find more information about user commands and SALT at http://docs.dyalog.com. Normally, you'll use ]SAVE once to write your code to a .dyalog script file. After that, whenever you edit your code using )ed SALT will prompt you to update the script file when you save your changes. If you need to bring your code into the workspace, for instance, when you start a new APL session, you use the ]LOAD command.

Editing MiServer MiPages from within APL...
All of your pages should be in script files. MiServer knows to load the page when it receives a request. Because your pages need to be derived from the MiPage class, the MiPage class needs to be present when you want to edit your pages. The easiest way is to load the MiServer development environment by using the Load function in the mserver workspace. In your example you have your MiSite in c:\MyMisite\, so, after you )LOAD the mserver workspace you would do the following to edit your helloworld page.
      )load {your path to the mserver workspace}
{your path}\mserver saved ...
Load 'c:\MyMisite\'
Development environment loaded
]load c:\MyMisite\helloworld
#.helloworld
)ed helloworld


Using a Text Editor like Notepad.exe to Edit APL Script Files...
There are three things to consider when editing APL script files with a text editor.
  • The file needs to be UTF-8 encoded (SALT's SAVE function will do this for you)
  • You need the APL character set. To do this, select the APL385 Unicode font in your editor.
  • You need to be able to type APL characters. To do this under Windows, you can use the Dyalog APL IME
You can find the font and IME (and other APL resources) at http://www.dyalog.com/apl-font-keyboard.htm

Which Editor to Use?
Questions like this can spark great debate. It's largely a matter of personal choice and using the editor you can be most productive with. I've been an APL developer for a long time, and as such, I tend to prefer the editor built into Dyalog APL - it has syntax coloring, auto completion, outlining, and a number of keyboard shortcuts that make it the most productive environment for me. I will use Notepad or vim on occasion when I'm making small changes. People have written add-ons for Notepad++ and vim to provide some additional functionality for APL code, but I can't comment on them as I don't use them. If you plan on doing any significant amount of APL development, it's probably worth the effort to learn the Dyalog Interactive Development Environment (IDE).

I hope this helps!
/Brian
User avatar
Brian|Dyalog
 
Posts: 116
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: editor to scripted files

Postby Gantois on Thu Jun 12, 2014 12:30 am

Brian,
Thanks very much for these informations and for your prompt reply. You really helped me.

Att
Marco Gantois
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: editor to scripted files

Postby Gantois on Tue Jun 24, 2014 2:38 pm

Hello Brian, Good Morning!

I'm learning MiServer (User Guide) and APL/OOP (Language Help) so I have some conceptual questions. Some of them you have already helped me, but I have other questions:

1) MiPage Templates (MiServer page 5): “… you can have any numbers of these templates in your site and can switch between
them by changing the template from which a MiPage is derived.”

As an exercise I replaced C:\MyMisite\Code\Templates\MiPage.dyalog as C:\MyMisite\Code\Templates\ABC.dyalog an after
I changed the header of helloworld.dyalog (:Class helloworld : ABC).
The dyalog APL/64 - status was: line(0,21) : error AC0527: invalid base class or interface declaration ":Class helloworld: ABC" and line(0,22) : error AC0528: only interfaces can be declared after the base class ":Class helloworld : ABC"

- Should I keep the same name (MiPage.dyalog / :Class MiPage: MildPage ) and change the content? If so, how can I have any numbers of these templates to my site?

2) A sample MiSite - Directory or File Scripts\ (page 12): Where should I place the APL scripted files of my site?
In this directory or in “MyMisite” root directory ?

3) Ideas for using style sheets in MiPages (page 32): “… Pass the file path of a new style sheet to the Style method of the request object (req.Style). This appends the link for a new style sheet with that path after style.css link.” Where could I see an example? What should I do when I need more than one external CSS file to my page?

4) About APL/OOP (Language Help) and MiServer:
I have developed some classes to access my component files (each class refers to one file having specific access methods – open/close/read/replace/list etc.). I have used []new to create an instance. The methods were tested with success and these classes were saved in a WS.

Now I need use them in my pages. I understand that, at first, I have to save each class as an APL scripted file in MyMisite calling these methods from inside my page code, isn’t it? If so, how can I to do this if my page needs to be derived from MiPage template to apply that template to my code? What is the right way? What about the []new ?

Summarizing I will create one mypage, this page will access a component file method (I already have this class with its methods created inside a WS), this method will return a vector (for example) and this vector will be used in my page.

ps: you had already given me an example when I asked you about (PHP/APL), but after this I decided to use MiServer instead
of PHP/APL component files. Is this the same case?

As you see I am very confused. Could you help me if possible giving me an example?

Thanks,
Att
Marco Gantois
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: editor to scripted files

Postby Brian|Dyalog on Fri Jun 27, 2014 11:26 pm

Hi Marco!

I apologize for not having replied sooner; I've been on vacation this week with very limited internet access.

I'm assuming you're using MiServer 2.1. MiServer 3.0 will be available later this year, and makes some minor naming changes.

Templates -
Every page has to eventually derive from the MildPage class (in MiServer 3.0 it will be the MiPage class).
So, your class hierarchy should be like: helloworld >> ABC >> MildPage
Here's a very simple example. The only thing the ABC template does is set the title for the page.
But you can see where helloworld derives from ABC which derives from MildPage
Code: Select all
:Class helloworld : ABC
    ∇ html←Render req
      :Access Public
      html←'h2' #.HTMLInput.Enclose'Welcome to MiServer!'
    ∇
:EndClass

:Class ABC : MildPage
    :Include #.HTMLInput
    ∇ Wrap req;head
      :Access Public
      head←'head' Enclose req.Response.HTMLHead,'title' Enclose 'Testing'
      req.Response.HTML←'html' Enclose head,'body' Enclose req.Response.HTML     
    ∇
:EndClass


Where to put the APL script files that make up your MiSite...
In the sample MiSites, we've used a convention of having a \Scripts folder which is intended for JavaScript files, not APL script files. However, there's no requirement for you to use that convention; you can organize your MiSite however works best for you.
Historically, we've located MiSites under the MiServer folder - the sample MiSite "Intro" is located in the \Intro folder under the MiServer root folder. However, it's probably best to locate your MiSite(s) in a separate folder not under the MiServer root. This will make it easier to update MiServer in the future, and separates your code from the code that Dyalog supplies. So, you could potentially have something like:
    C:\MiSites\MiSite1
    C:\MiSites\MiSite2
    C:\MiSites\YetAnotherMiSite

Then, when you start your MiSite1, you'd use
      Start 'C:\MiSites\MiSite1'


Style Sheets
Similar to \Scripts, we've used a convention in the sample MiSites to locate style elements (CSS file, images, etc) in the \Styles folder. Again, you can organize your MiSite however works best for you.
To use the request object's Style method, you'd do something like this:
Code: Select all
:Class helloworld : ABC
    ∇ html←Render req
      :Access Public
      req.Style '\Styles\yellow.css'
      html←'h2' #.HTMLInput.Enclose'Welcome to MiServer!'
    ∇
:EndClass


APL/OOP and MiServer
I'm not sure I have enough information on the structure and use of your application to give you a definitive answer on this.
For example, is there a separate instance of your file class per file, per user, or something else?
I'll try to lay out some options here that might give you an idea of how to proceed.
If we need to dig deeper in the specifics of your application, we may want to move that discussion to email rather than in the forums.
  • Your classes need not be saved as APL script files (though there are a lot of good reasons to do so). You could save the workspace with your classes, copy the contents of the mserver workspace, and set up a ⎕LX to perform whatever initialization needed to be done and then start your site.
  • If you do save your classes in APL script files, you can have the code called by ⎕LX do a ⎕SE.SALT.Load to bring in each class.
  • If your need an instance of your class for each user, MiServer creates a session for each user which will persist until the session times out or the server is shut down. For something like this, you could test to see if the class has been initialized and take some appropriate action.
    Here's some mocked up code that does that sort of thing.
    Code: Select all
    :Class mypage : ABC
        :Field initialized←0   ⍝ start out as not initialized

        ∇ html←Render req
          :Access Public
          :If ~initialized
              myinstance←⎕NEW #.myclass  ⍝ create the instance   
              initialized←1 ⍝ and indicate that we've initialized
          :EndIf
          req.Style '\Styles\yellow.css'
          html←'h2' #.HTMLInput.Enclose'Welcome to MiServer!'
          html,←'div' #.HTMLInput.Enclose myinstance.readdata  ⍝ use the instance
        ∇
    :EndClass
I hope this helps. These are all good questions - keep them coming!

/Brian
User avatar
Brian|Dyalog
 
Posts: 116
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: editor to scripted files

Postby Gantois on Tue Jul 01, 2014 10:50 am

Hi Brian!

I think I can go ahead some steps with your informations.

Thanks very much,
Marco
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: editor to scripted files

Postby Gantois on Tue Jul 01, 2014 1:00 pm

Hy Brian,

About Template case on your example, Where am I making a mistake? I received the same error again:

line(0,15) : error AC0527: invalid base class or interface declaration ":Class hello : ABC"
^
line(0,16) : error AC0528: only interfaces can be declared after the base class ":Class hello : ABC"
^
Complete: 2 errors.

A) following step by step what I did:

)load mserver
C:\MiServer\mserver saved Thu Apr 18 00:42:52 2013
Start 'Intro' ⍝ Run the demo server
Start 'c:\MyMisite\' ⍝ Run the demo server
0
MiServer started on port: 8088
Load 'c:\MyMisite\'
Development environment loaded
)ed ○ABC
:Class ABC : MildPage
:Include #.HTMLInput
∇ Wrap req;head
:Access Public
head←'head' Enclose req.Response.HTMLHead,'title' Enclose 'Testing'
req.Response.HTML←'html' Enclose head,'body' Enclose req.Response.HTML

:EndClass

)ed ○hello

:Class hello : ABC
∇ html←Render req
:Access Public
html←'h2' #.HTMLInput.Enclose'Welcome to MiServer!'

:EndClass


]Save ABC c:\MyMisite/
c:\MyMisite\ABC.dyalog
]Save hello c:\MyMisite/
c:\MyMisite\hello.dyalog


B) Another question: Where should I save ABC ? In that directory (c:\MyMisite/) or in C:\MyMisite\Code\Templates?


Thanks again,

Marco
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: editor to scripted files

Postby Brian|Dyalog on Thu Jul 03, 2014 9:32 pm

Hi Marco!

MiPage templates (like your ABC) should be in the MiSite/Code/Templates folder. I think once you move it there, your example should work.

/Brian
User avatar
Brian|Dyalog
 
Posts: 116
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: editor to scripted files

Postby Gantois on Fri Jul 04, 2014 6:38 am

Hi Brian,

Everything worked now.

As I had already tried in that directory first, I downloaded mserver ws before repeat the instructions. Certainly I've made another mistake.

Thanks
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am


Return to MiServer

Who is online

Users browsing this forum: No registered users and 1 guest