View · Index

Weblog Page

Filtered by category Tutorials for Programmers, 1 - 10 of 12 Postings (all, summary)

Add extra headers

Created by Rocael Hernández Rizzardini, last modified by Benjamin Brink 30 Jun 2017, at 06:53 AM

Usually you can do it with templates:
<property name="header_stuff">
....
  </property>

But sometimes you want to add it not in just one page, so you usually go to www/site-master.adp, but that is not really good to maintain modularity, so instead, now you can define within your package a tcl callback like this:

ad_proc -public -callback subsite::get_extra_headers -impl my_implementation {} {
    return the stuff that should go into the html headers
} {

    set scripts "...."
    set tags "...."

    set text_to_return $scripts
    append text_to_return $tags

    return $text_to_return

}
 

Emacs as an OpenACS IDE

Created by OpenACS community, last modified by Gustaf Neumann 13 Jun 2017, at 10:30 AM

emacs integrated development environment for OpenACS

emacs documentation: http://www.gnu.org/software/emacs/manual/html_node/

Emacs uses major and minor modes that provide a UI context for editing various file types. Here are some useful ones for working with OpenACS:

CVS Mode Emacs with OpenACS

I use M-x cvs-examine to update and check in code when I am working with OpenACS. One thing that is a pain with CVS is that cvs diff does not tell you what you are going to get if you update, it only tells you what is changed in your local copy.

You can use M-x cvs-examine and then type "d e" next to any of the files in your checkout in the *cvs* buffer to open ediff mode and then interactively merge what's in CVS with your local changes. In ediff mode you use n/p to got to the next/previous difference. You can copy changes from the CVS buffer to your local copy using a/b to copy the the buffer marked A to B or B to A. Type ? on the ediff window to get a list of other commands.

OpenACS Mode for Emacs

See historical page describing oacs.el http://web.archive.org/web/20040621200046/www.thecodemill.biz/services/oacs/

 

Download: oacs.el.tar updated 2006-08-15 . The lastest version includes nXML mode support in addition to PSGML support. There are good installation instructions in the INSTALL.txt file. A quick install guide for Debian


 


sudo su -
cd /usr/share/emacs/site-lisp
wget http://www.emacswiki.org/elisp/color-occur.el
wget https://openacs.org/storage/view/xowiki-resources%5C/oacs.el.tar
tar xf oacs.el.tar
apt-get install psgml mmm-mode

# Alternatively compile manually
wget http://www.lysator.liu.se/~lenst/about_psgml/psgml-1.2.5.tar.gz
tar xfz psgml-1.2.5.tar.gz
cd psgml-1.2.5
./configure
make install
cd ..
wget http://switch.dl.sourceforge.net/sourceforge/mmm-mode/mmm-mode-0.4.8.tar.gz
tar xfz mmm-mode-0.4.8.tar.gz
cd mmm-mode-0.4.8
./configure
make install

After this login as the user who is doing the development and edit you .emacs file.

 (add-to-list 'load-path "/usr/share/emacs/site-lisp/oacs")
 (require 'oacs)
 (setq user-full-name "<yourname>")
 (setq user-mail-address "<your email>")
 (add-to-list 'auto-mode-alist '("\\.vuh" . tcl-mode))
 (add-to-list 'auto-mode-alist '("\\.adp" . html-mode))

For recent Emacs versions (> 2008), modify oacs-nxml.el in the downloaded tarball:

 line 30: (load "nxml-mode.el")  instead of (load "rng-auto.el")

See http://lists.gnu.org/archive/html/emacs-devel/2008-01/msg00947.html

Also, you may need to modify adp.rnc to the correct path to the xhtml.rnc schema on your installation. On OS X, for example, line 5 should read:

include "/Applications/Emacs.app/Contents/Resources/etc/schema/xhtml.rnc" 

 

The following was written by Bart the author of oacs.el

OpenACS lacked a good Integrated Development Environment and as I use Emacs for almost everything it was only natural to fill the void. The Emacs OACS module is an extension to GNU Emacs, the extensible, customizable, self-documenting real-time display editor.

Development status

Emacs OACS's development is driven by the needs I encounter in my OpenACS projects. Development takes place in my spare time. At this stage the code is the documentation. I lack the time to write a proper article. However, as Emacs OACS addresses the issues described in articles XQL Document Type Definition and Replacing SQL bind vars in Emacs some background information can be found in those articles.

Forum thread: Beta Emacs OACS module available

Useful commands

Formating TCL

  • M-o ft to re-format Tcl code. See code for details.
  • M-o fh to reformat Html or Adp code.
  • M-o fs to reformat Sql code.
  • M-x oacs-format-separate-tags to separate adjacent tags. E.g. <tr><td>
  • M-x oacs-format-includes to place all include attribubtes on a separate line.
    
     

Code navigation

  • M-o oo to search for any custom regular expression.
  • M-o on to search the log for Notice oacs-dbg messages. That is a Notice level message created with the macro 'oddbg'.
  • M-o od to search the log for Debug oacs-dbg messages.
  • M-o oe to search the log for Error oacs-dbg messages. Etc for all other ns_log levels.
  • M-o op to browse Tcl libraries for procedure definitions. This is by far my favorite way of navigating a library!
  • M-o fp (find-file-at-point) to NSD error log mode.
  • M-o rl to revert the logfile
  • M-o ml to to open an error log file and monitor the changes to the log. 

 

Editing docbook xml

 

editing via Muse mode

editing via nXML mode

See https://openacs.org/doc/nxml-mode.html

psgml mode

See:

Developing with emacs

To make emacs display .vuh files similar to .tcl files, add to .emacs file:

 (add-to-list 'auto-mode-alist '("\\.vuh" . tcl-mode))

 

To make emacs display .adp files similar to .html files, add to .emacs file:

 (add-to-list 'auto-mode-alist '("\\.adp" . html-mode))

 

Common command shortcuts

Minor Modes

 M-x global-font-lock-mode highlights syntax using colors
 M-x transient-mark-mode   shows a highlighted text region
 M-x show-paren-mode       shows matching parentheses (and when the do not)

Move, Search and Replace

 M-x goto-line             go to a specific line in a file
 M-x goto-char             go to a specific character number in a file
 M-C-f                     search forward for matching brace
 M-C-b                     search backward for matching brace
 M-x replace-regexp        search/replace using regular expressions
 M-x query-replace-regexp  query/search/replace using regular expressions
   note \\( and \\) for start and end subgroups
 M-x grep                  grep creates new buffer with results
                           for fast loading/editing search hits

Useful "sleepers" (not found in many shortcut sheets)

 fg<cr>                    restart a suspended emacs session from commandline
 C-q <key press>           add a key without emacs interpreting the key binding

You can configure emacs to create 4 spaces when you press the tab key--important for meeting coding standards. Add this to your .emacs file:

(setq-default tab-width 4 indent-tabs-mode nil)

other useful quicksheets

Webinar - Part 1 - Basics

Created by Marcin Kuczkowski, last modified by Gustaf Neumann 20 Apr 2017, at 06:05 PM

OpenACS Basics - Part 1

On 2006-10-15 Tracy Adams gave a webinar for developers on OpenACS basics. Here are notes, that might be of use for people who are starting to learn the toolkit. For example for easy copy-n-paste during learning sessions.

We assume the reader has a working instance of OpenACS at hand. If not, there are other sections of xowiki, that cover the installation and configuration of OACS.

Configuration for the turorial 

The default config puts the files of the toolkit to:

/var/lib/aolserver/service0

In this case, the dir of our interest for now, will be:

/var/lib/aolserver/service0/www

 We will edit all our tutorial files in that directory.

Hello, world! 

 OACS uses combination of Tcl and ADP pages for clear separation of logic and presentation. Tcl pages are just a Tcl scripts and ADP are HTML pages with some extra tags. However the early versions of the toolkit rendered pages within Tcl. We will use some of the earlier features of the toolkit.

Open a file "helo-1.tcl" in the path:

/var/lib/aolserver/service0/www

and put there:


 

# helo-1.tcl # return standard HTTP headers ReturnHeaders ns_write "hello, world!"

 now, open Your Firefox and go to:

http://yourhost/helo-1

or maybe with the port number: 

http://yourhost:8000/helo-1

instead of "yourhost" put the name or IP of the host of the edited instance of OACS. It also refers to all examples which follow.

Note the lack of .tcl extension at url. OACS has a Request Processor, that figures out the right extension and fetches the file.

ReturnHeaders - returns HTTP headers to the browser ns_write - just writes string to the browser

The docs for the entire system can be found at:

http://yourhost/doc

Note also very useful API browser and search boxes at:

http://yourhost/api-doc 

( maybe the URL will need also the port number, depending on Your config, for example:

http://yourhost:8000/api-doc 

)

Set a value

 To use a variable just put a value in it:

# helo-2.tcl
ReturnHeaders
# first, set the value for a
set a 10

# then use it
ns_write "value of a is $a"

The value of the var can also be a string:

# helo-3.tcl
ReturnHeaders
# first, set the value for a
set name "John"

# then use it
ns_write "My name is $name"

To get the value of the var:


 

# helo-4.tcl ReturnHeaders set a 10 # let's use the value of a for new var: set b $a ns_write "<br/> value of b is $b" # we can also do this like that: set c [set b] ns_write "<br/> value of c is $c"

The form [set varname] form of getting the value of the var seems at first a bit too long, but it comes in handy when doing some metadata manipulations.

Call a func

To evaluate the function ( or call a procedure ) use [ ] as follows:


 

# helo-4b.tcl ReturnHeaders set a 10 # let's use the value of a for new var: # expr is a func that returns the result of the math expression given # as the argument. using square braces we call this func set b [ expr $a + 5 ] ns_write "<br/> value of b is $b"

 Lists are simple

To create a list:

# helo-5.tcl
ReturnHeaders
set mylist [ list "red" "green" "blue" ] 
ns_write "<p> mylist is: $mylist"

( TODO: more on the lists - creation, adding, deleting, finding, etc...)

More complex structures: ns_set  

See the docs on ns_set: http://panoptic.com/wiki/aolserver/Ns_set.

 


 

 

# helo-6.tcl ReturnHeaders

# create a new set with a name "the_name_of_the_set": set vars_by_names [ ns_set create the_name_of_the_set ] # the name of the set is different that the name of the # variable, that contains that set # put some variables into the set: ns_set put $vars_by_names red   $red ns_set put $vars_by_names green $green ns_set put $vars_by_names blue  $blue # how many things do we have in the bag? set size [ ns_set size $vars_by_names ] ns_write "size of the set:  $size " # let's show them: ns_write "<br>red:   [ ns_set get $vars_by_names red   ]" ns_write "<br>green: [ ns_set get $vars_by_names green ]" ns_write "<br>blue:  [ ns_set get $vars_by_names blue  ]" # the same, but better: ns_write "<hr/>" set size [ ns_set size $vars_by_names ]

#     counter     condition      change the counter for { set i 0 } { $i < $size } { incr i } {     set key   [ns_set key   $vars_by_names $i]     set value [ns_set value $vars_by_names $i]     ns_write "<br/> $key: $value " }

Parameters for the page

It is very simple to control the way the parameters from query string go to our page:

#helo-7.tcl
ad_page_contract {
    demonstrates using of ad_page_contract
} {
    id:integer
}

ReturnHeaders
ns_write "id is: $id"

1. try to reach the page http://yourhost/helo-7 without the query string     the page should display the message about input problems

2. try the same with the url: http://yourhost/helo-7?id=123    the page should write the message: "id is 123"

3. try the same with the url: http://yourhost/helo-7?id=asdf    the page should display the message about id not being the integer

The parameter can be optional:


 

#helo-8.tcl ad_page_contract {     demonstrates using of ad_page_contract } {     id:integer,optional }

set id "<b>not necessary but optional</b>" ReturnHeaders ns_write "id is: $id"

Access control 

Using ad_conn, we can discover many useful info: 


 

# helo-9.tcl

# check if the user is logged in, redirect if not ad_maybe_redirect_for_registration ReturnHeaders # id of the user set user_id [ad_conn user_id] ns_write "user_id: $user_id" # peer's IP set user_ip [ad_conn peeraddr] ns_write "<p> user's IP: $user_ip"

Logic and Presentation

Now let's get to Tcl + ADP stuff which allows to separate the work of the designer from the work of the developer.

Most of the pages in OACS consist of at least Tcl and ADP components. Here is how:

In most cases Tcl and ADP pages are named the same, except for the extension. It is possible to explicitly call the presentation page from the script. See the docs for ad_return_template.

In the following example we will use helo-10.tcl and helo-10.adp.

in Tcl we do some data manipulation


 

# helo-10.tcl ad_page_contract {     demonstrates TCL and ADP combination     and multirow } {     id:integer,optional } -properties {     a:onevalue     alist:multirow }

set a 10 # create the multirow multirow create alist no name      color # add rows multirow append alist 1  Adam      red multirow append alist 2  Ben       blue multirow append alist 3  Catherine green multirow append alist 4  Danae     black

then we present it in ADP. Put the script below into helo-10.adp: ( note: remove the space between @ and the name of the variable below; I do not know how to escape the @ )


 

<master> <p>     the value of a is @ a@ </p> <blockquote>     <multiple name="alist">         <li> @ alist.no@ - @ alist.name@ ( color: @ alist.color@ )

</li>     </multiple> </blockquote>

 now open the page in browser:

http://yourhost:8000/helo-10

That's all.

The webinar took place on Sunday 2006-10-15 at 2:30 P.M. Eastern time.

Many thanks to Tracy Adams, who was presenting the material.  

( corrections welcome, especially of my english )

Body Onload javascript event

Created by Rocael Hernández Rizzardini, last modified by Gustaf Neumann 22 Oct 2016, at 09:10 AM

API calls for adding javascript

 

template::add_event_listener

add event listener for a single ID or for a CSS class. When using this call, the provided JavaScript snipped will be added suitable for content security policies (by adding nonces).

Example:

    template::add_event_listener \
        -id edit-tags-control \
        -script [subst {document.getElementById("edit_tags").style.display="block";}]

template::add_body_handler

Adds javascript code to an event handler in the body tag. Several javascript code blocks may be assigned to each handler by subsequent calls to template::add_body_handler.

template::add_event_listener

Add a script to the start of the body section of the document to be returned to the users client.

 

DEPRECATED:

There was no easy way to add onload event to openacs, unless you edit www/site-master.tcl, but now you can define within you own package what functions you want to be for onload javascript event. This tcl callback definition will work for any page.

   ad_proc -public -callback subsite::header_onload -impl my_onload {} {
      return the function to load when the page is served
   } {
      return {my_javascript_function();}
   }

Or in case you want it for a single page, or for you custom template, use the template property to send it:

   <property name="body(onload)">
      my_javascript_function();
   </property>

Alternatively, as the on_load property tag has been deprecated, you could in your .tcl file set a variable

   set my_function_name "my_javascript_function();"

then in the .adp

   <property name="body(onload)">
     @my_function_name;noquote@
   </property>

Vi as an OpenACS IDE

Created by OpenACS community, last modified by Monika Andergassen 05 Oct 2015, at 12:45 PM

In vim add the following in your .vimrc will help convert tabs to 4 spaces to meet part of the OpenACS coding standard.

set tabstop=4
set expandtab
set list
set listchars=tab:>.

It's also nice to have syntax highlighting by adding the following line

syntax on 

Also useful to use tagging features. In brief - run ctags -R in the root of the install or source tree.

At that point you can edit using vim -t procname or ::package::procname and go to the corresponding place in the code. From within the code, you can lookup functions by having the term highlighted and hit CTL-] - use CTL-T to go back.

Only works if you edit from the top directory, all tags are relative to there.



Automated Installs - Using install.xml

Created by Ryan Gallimore, last modified by Ryan Gallimore 10 Apr 2010, at 07:29 PM

To automatically install packages with specific parameters and mount points, create an install.xml file in your /path/to/service/ directory, according to:

 Automated Install Thread

Webinar - Part 3 - Packages and ad_form

Created by Marcin Kuczkowski, last modified by Manish Hasija 06 Jun 2007, at 06:32 AM

Packages and ad_form 

The session covered packages creation and developing them using some of the OACS features. The second part of the session was about using ad_form to easily create and manage web forms.


Webinar - Part 4 - Survey

Created by Marcin Kuczkowski, last modified by Marcin Kuczkowski 28 Oct 2006, at 12:02 PM

Survey module

 The session covered the user point of view of the survey module. It also has got some explanation of its data model and inner TCL mechanisms.

TODO: link the recorded webinar here


 

Webinar - Part 2 - Site Map Administration

Created by Marcin Kuczkowski, last modified by Marcin Kuczkowski 21 Oct 2006, at 01:36 AM

Site Map Administration

 ( notes from part 2 of webinar series by Tracy Adams )

 

  1. Packages - Applications vs Services
  2. Package .info Files - xml about the package
  3. Package Manager - parameters, xml file creation, package installation and upgrade
  4. Site Map - subsites, permissions, groups, users, registration
  5. Request Processor - package_id, permissions for an instance
  6. Site Map API - mount, instantiate_and_mount

 

Packages - Applications vs Services

Most of the OpenACS code is divided into packages. There are application packages and service packages. Applications are packages like "Room Reservation" or "Photo Album" - something that people, who come to the site can see and use. Services are the parts of the OACS that are not used by users directly, but rather provide functions or data for applications to use.

There is a package repository OpenACS community site divided into channels for each major version of OpenACS.

To use a package on the site, first - install it, then mount it into the Site Map. Consider the example of forums. Assume we have 3 groups of users that will post on different topics. We install forums package, then we mount fhe package in following urls:

/group-1/forum 
/group-2/forum
/group-3/forum

Every forum will have its own "package_id", its own users and its own set of permissions. There will be separate data for each forum but the same TCL and ADP files.

Administration pages are at the url:  http://yourserver/acs-admin/. Links presented there let admin perform miscellaneous tasks.

To install packages from local filesystem or from OpenACS repository follow "Install software" link.

To mount packages follow the link "Site Map".






OpenACS mode for Emacs

Created by Rob, last modified by Carl Robert Blesius 21 Sep 2006, at 05:19 AM

moved: ide-emacs

Next Page
previous November 2024
Sun Mon Tue Wed Thu Fri Sat
27 28 29 30 31 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Popular tags

17 , 5.10 , 5.10.0 , 5.10.1 , 5.9.0 , 5.9.1 , ad_form , ADP , ajax , aolserver , asynchronous , bgdelivery , bootstrap , bugtracker , CentOS , COMET , compatibility , CSP , CSRF , cvs , debian , docker , docker-compose , emacs , engineering-standards , exec , fedora , FreeBSD , guidelines , host-node-map
No registered users in community xowiki
in last 30 minutes
Contributors

OpenACS.org