webmcp

changeset 4:5e32ef998acf v1.0.4

Version 1.0.4

ui.link{...} with POST target can now be parameterized with BOTH content and text to allow HTML content for JavaScript browsers and a text-only version for accessiblity

Changes related to database selectors:
- Support for row-based locking
- New method :count(), caching and returning the number of rows, which WOULD have been returned by :exec()
- Bugfix: WHERE and HAVING expressions are now enclosed in parenthesis to avoid problems with operator precedence

ui.script{...} now supports external .js files

Changes in langtool.lua to cope with escaped new-line chars (\n)
author jbe/bsw
date Fri Dec 25 12:00:00 2009 +0100 (2009-12-25)
parents 795b764629ca
children 4fb227630097
files doc/autodoc-header.htmlpart framework/bin/langtool.lua framework/cgi-bin/webmcp.lua framework/env/ui/link.lua framework/env/ui/script.lua libraries/mondelefant/mondelefant.lua
line diff
     1.1 --- a/doc/autodoc-header.htmlpart	Thu Dec 10 12:00:00 2009 +0100
     1.2 +++ b/doc/autodoc-header.htmlpart	Fri Dec 25 12:00:00 2009 +0100
     1.3 @@ -55,10 +55,10 @@
     1.4          color: #505050;
     1.5        }
     1.6      </style>
     1.7 -    <title>WebMCP 1.0.3 Documentation</title>
     1.8 +    <title>WebMCP 1.0.4 Documentation</title>
     1.9    </head>
    1.10    <body>
    1.11 -    <h1>WebMCP 1.0.3 Documentation</h1>
    1.12 +    <h1>WebMCP 1.0.4 Documentation</h1>
    1.13      <p>
    1.14        WebMCP is a completely new web development framework, and has not been extensively tested yet. The API might change at any time, but in future releases there will be a list of all changes, which break downward compatibility.
    1.15      </p>
     2.1 --- a/framework/bin/langtool.lua	Thu Dec 10 12:00:00 2009 +0100
     2.2 +++ b/framework/bin/langtool.lua	Fri Dec 25 12:00:00 2009 +0100
     2.3 @@ -94,6 +94,7 @@
     2.4                (not string.find(key, "^%s*%.%.[^%.]")) and
     2.5                (not string.find(key, "^%s*,[^,]"))
     2.6              then
     2.7 +              local key = key:gsub("\\n", "\n")
     2.8                translations[key] = false
     2.9              end
    2.10            end
    2.11 @@ -103,6 +104,7 @@
    2.12                (not string.find(key, "^%s*%.%.[^%.]")) and
    2.13                (not string.find(key, "^%s*,[^,]"))
    2.14              then
    2.15 +              local key = key:gsub("\\n", "\n")
    2.16                translations[key] = false
    2.17              end
    2.18            end
    2.19 @@ -178,9 +180,9 @@
    2.20    for num, key in ipairs(translation_keys) do
    2.21      local value = translations[key]
    2.22      if value then
    2.23 -      file:write(string.format("[%q] = %q;\n", key, value))
    2.24 +      file:write((string.format("[%q] = %q;\n", key, value):gsub("\\\n", "\\n"))) -- double () important to hide second result of gsub
    2.25      else
    2.26 -      file:write(string.format("[%q] = false;\n", key))
    2.27 +      file:write((string.format("[%q] = false;\n", key):gsub("\\\n", "\\n"))) -- double () important to hide second result of gsub
    2.28      end
    2.29    end
    2.30    file:write("}\n")
     3.1 --- a/framework/cgi-bin/webmcp.lua	Thu Dec 10 12:00:00 2009 +0100
     3.2 +++ b/framework/cgi-bin/webmcp.lua	Fri Dec 25 12:00:00 2009 +0100
     3.3 @@ -1,6 +1,6 @@
     3.4  #!/usr/bin/env lua
     3.5  
     3.6 -_WEBMCP_VERSION = "1.0.3"
     3.7 +_WEBMCP_VERSION = "1.0.4"
     3.8  
     3.9  -- include "../lib/" in search path for libraries
    3.10  do
     4.1 --- a/framework/env/ui/link.lua	Thu Dec 10 12:00:00 2009 +0100
     4.2 +++ b/framework/env/ui/link.lua	Fri Dec 25 12:00:00 2009 +0100
     4.3 @@ -9,7 +9,7 @@
     4.4    params    = params,     -- optional parameters to be passed to the view or action
     4.5    routing   = routing,    -- optional routing information for action links, as described for ui.form{...}
     4.6    text      = text,       -- link text
     4.7 -  content   = content     -- alternative name for 'text' option, preferred for functions
     4.8 +  content   = content     -- link content (overrides link text, except for submit buttons for action calls without JavaScript)
     4.9  }
    4.10  
    4.11  This function inserts a link into the active slot. It may be either an internal application link ('module' given and 'view' or 'action' given), or a link to an external web page ('external' given), or a link to a file in the static file directory of the application ('static' given).
    4.12 @@ -18,7 +18,7 @@
    4.13  
    4.14  function ui.link(args)
    4.15    local args = args or {}
    4.16 -  local content = args.text or args.content  -- TODO: decide which argument name to use
    4.17 +  local content = args.content or args.text
    4.18    assert(content, "ui.link{...} needs a text.")
    4.19    local function wrapped_content()
    4.20      -- TODO: icon/image
     5.1 --- a/framework/env/ui/script.lua	Thu Dec 10 12:00:00 2009 +0100
     5.2 +++ b/framework/env/ui/script.lua	Fri Dec 25 12:00:00 2009 +0100
     5.3 @@ -26,10 +26,17 @@
     5.4        slot.put(args.script)
     5.5      end
     5.6    end
     5.7 +  if args.external then
     5.8 +    attr.src = encode.url{ external = args.external }
     5.9 +  elseif args.static then
    5.10 +    attr.src = encode.url{ static = args.static }
    5.11 +  end
    5.12    if noscript then
    5.13      ui.tag{ tag = "noscript", attr = attr, content = noscript }
    5.14    end
    5.15 -  if script then
    5.16 +  if attr.src then
    5.17 +    ui.tag{ tag = "script", attr = attr, content = "" }
    5.18 +  elseif script then
    5.19      ui.tag{ tag = "script", attr = attr, content = script }
    5.20    end
    5.21  end
     6.1 --- a/libraries/mondelefant/mondelefant.lua	Thu Dec 10 12:00:00 2009 +0100
     6.2 +++ b/libraries/mondelefant/mondelefant.lua	Fri Dec 25 12:00:00 2009 +0100
     6.3 @@ -62,17 +62,15 @@
     6.4    self._distinct = false
     6.5    self._distinct_on = {sep = ", ", expression}
     6.6    self._from = { sep = " " }
     6.7 -  self._where = { sep = " AND " }
     6.8 +  self._where = { sep = ") AND (" }
     6.9    self._group_by = { sep = ", " }
    6.10 -  self._having = { sep = " AND " }
    6.11 +  self._having = { sep = ") AND (" }
    6.12    self._combine = { sep = " " }
    6.13    self._order_by = { sep = ", " }
    6.14    self._limit = nil
    6.15    self._offset = nil
    6.16 -  --[[
    6.17 -  self._lock = nil
    6.18 -  self._lock_tables = { sep = ", " }
    6.19 -  --]]
    6.20 +  self._read_lock = { sep = ", " }
    6.21 +  self._write_lock = { sep = ", " }
    6.22    self._class = nil
    6.23    self._attach = nil
    6.24    return self
    6.25 @@ -193,6 +191,26 @@
    6.26    return self
    6.27  end
    6.28  
    6.29 +function selector_prototype:for_share()
    6.30 +  self._read_lock.all = true
    6.31 +  return self
    6.32 +end
    6.33 +
    6.34 +function selector_prototype:for_share_of(expression)
    6.35 +  add(self._read_lock, expression)
    6.36 +  return self
    6.37 +end
    6.38 +
    6.39 +function selector_prototype:for_update()
    6.40 +  self._write_lock.all = true
    6.41 +  return self
    6.42 +end
    6.43 +
    6.44 +function selector_prototype:for_update_of(expression)
    6.45 +  add(self._write_lock, expression)
    6.46 +  return self
    6.47 +end
    6.48 +
    6.49  function selector_prototype:reset_fields()
    6.50    for idx in ipairs(self._fields) do
    6.51      self._fields[idx] = nil
    6.52 @@ -324,13 +342,13 @@
    6.53    if #self._mode == "empty_list" then
    6.54      add(parts, "WHERE FALSE")
    6.55    elseif #self._where > 0 then
    6.56 -    add(parts, {"WHERE $", self._where})
    6.57 +    add(parts, {"WHERE ($)", self._where})
    6.58    end
    6.59    if #self._group_by > 0 then
    6.60      add(parts, {"GROUP BY $", self._group_by})
    6.61    end
    6.62    if #self._having > 0 then
    6.63 -    add(parts, {"HAVING $", self._having})
    6.64 +    add(parts, {"HAVING ($)", self._having})
    6.65    end
    6.66    for i, v in ipairs(self._combine) do
    6.67      add(parts, v)
    6.68 @@ -348,6 +366,18 @@
    6.69    if self._offset then
    6.70      add(parts, "OFFSET " .. self._offset)
    6.71    end
    6.72 +  if self._write_lock.all then
    6.73 +    add(parts, "FOR UPDATE")
    6.74 +  else
    6.75 +    if self._read_lock.all then
    6.76 +      add(parts, "FOR SHARE")
    6.77 +    elseif #self._read_lock > 0 then
    6.78 +      add(parts, {"FOR SHARE OF $", self._read_lock})
    6.79 +    end
    6.80 +    if #self._write_lock > 0 then
    6.81 +      add(parts, {"FOR UPDATE OF $", self._write_lock})
    6.82 +    end
    6.83 +  end
    6.84    return self._db_conn:assemble_command{"$", parts}
    6.85  end
    6.86  
    6.87 @@ -390,6 +420,18 @@
    6.88    end
    6.89  end
    6.90  
    6.91 +-- NOTE: This function caches the result!
    6.92 +function selector_prototype:count()
    6.93 +  if not self._count then
    6.94 +    local count_selector = self:get_db_conn():new_selector()
    6.95 +    count_selector:add_field('count(1)')
    6.96 +    count_selector:add_from(self)
    6.97 +    count_selector:single_object_mode()
    6.98 +    self._count = count_selector:exec().count
    6.99 +  end
   6.100 +  return self._count
   6.101 +end
   6.102 +
   6.103  
   6.104  
   6.105  -----------------

Impressum / About Us