|
Revision 235, 0.7 kB
(checked in by zimbatm, 14 months ago)
|
|
Removed Markaby as a direct dependency. As AR, it is loaded on demand.
|
| Line | |
|---|
| 1 | class MissingLibrary < Exception #:nodoc: all |
|---|
| 2 | end |
|---|
| 3 | begin |
|---|
| 4 | require 'markaby' |
|---|
| 5 | rescue LoadError => e |
|---|
| 6 | raise MissingLibrary, "Markaby could not be loaded (is it installed?): #{e.message}" |
|---|
| 7 | end |
|---|
| 8 | |
|---|
| 9 | $MAB_CODE = %{ |
|---|
| 10 | # The Mab class wraps Markaby, allowing it to run methods from Camping::Views |
|---|
| 11 | # and also to replace :href, :action and :src attributes in tags by prefixing the root |
|---|
| 12 | # path. |
|---|
| 13 | class Mab < Markaby::Builder |
|---|
| 14 | include Views |
|---|
| 15 | def tag!(*g,&b) |
|---|
| 16 | h=g[-1] |
|---|
| 17 | [:href,:action,:src].map{|a|(h[a]=self/h[a])rescue 0} |
|---|
| 18 | super |
|---|
| 19 | end |
|---|
| 20 | end |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | Camping::S.sub! /autoload\s*:Mab\s*,\s*['"]camping\/mab['"]/, $MAB_CODE |
|---|
| 24 | Object.constants.map{|c|Object.const_get(c)}.each do |c| |
|---|
| 25 | c.module_eval $MAB_CODE if c.respond_to?(:goes) |
|---|
| 26 | end |
|---|