Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dryml/lib/dryml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# gem dependencies
require 'hobosupport'
require 'action_pack'
require 'action_view'
require 'action_controller'
require 'active_record' if ActionPack::VERSION::MAJOR==2 && ActionPack::VERSION::MINOR==2

ActiveSupport::Dependencies.load_paths |= [ File.dirname(__FILE__)] if ActiveSupport.const_defined? :Dependencies
Expand Down Expand Up @@ -284,8 +286,8 @@ def render(template_src, locals={}, template_path=nil, included_taglibs=[], view
this = locals.delete(:this) || nil

renderer_class = Dryml::Template.build_cache[template_path]._?.environment ||
Dryml.make_renderer_class(template_src, template_path, locals.keys)
renderer_class.new(template_path, view).render_page(this, locals)
Dryml.make_renderer_class(template_src, template_path, locals.keys, [], included_taglibs)
renderer_class.new(template_path, view).render_page(this, locals)
end

end
2 changes: 2 additions & 0 deletions dryml/lib/dryml/taglib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def taglib_filename(options)
"#{rails_root}/app/views"
elsif options[:template_dir] =~ /^#{HOBO_ROOT}/
options[:template_dir]
elsif options[:absolute_template_path]
options[:absolute_template_path]
else
"#{rails_root}/#{options[:template_dir].gsub(/^\//, '')}" # remove leading / if there is one
end
Expand Down
65 changes: 65 additions & 0 deletions hobo/doctest/rapid.rdoctest
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
doctest_require: 'rubygems'
>> require 'active_record'
>> require 'active_support'

https://rails.lighthouseapp.com/projects/8994/tickets/2577-when-using-activerecordassociations-outside-of-rails-a-nameerror-is-thrown

>> ActiveRecord::ActiveRecordError
>> require 'rexml/document'
>> require 'rexml/xpath'
>> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../dryml/lib')
>> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../hobo/lib')
>> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../hobofields/lib')
>> require 'dryml'
>> require 'hobo'
>> require 'hobo/model'
>> require 'hobofields'
>> HoboFields.enable
>> ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
>> ddl = 'CREATE TABLE "models" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" text)'
>> ActiveRecord::Base.connection.execute(ddl)
>>
class Guest
end

class Model < ActiveRecord::Base
hobo_model
fields do
name :string
end

mattr_accessor :editable
self.editable = true

def edit_permitted?(attr=nil)
Model.editable
end
end

def render(src)
# core depends on support but interdependencies are not declared
# so just load everything
libs = [{ :src => 'rapid', :plugin => 'hobo'},]
REXML::Document.new Dryml.render(src,{:this => Model.new},nil,libs)
end

def first_label(src)
html = render("#{src}")
[REXML::XPath.first(html,'//label/@for'), REXML::XPath.first(html,'//label/text()')]
end

>> first_label('<field-list fields="name"/>')
=> [nil, nil]

Get is needed to not trigger protect_against_forgery?

>> first_label('<form action="/" method="get"><field-list fields="name"><label:>CustomLabel</label:></field-list></form>')
=> [for='model_name', "CustomLabel"]

>> first_label('<form action="/" method="get"><field-list fields="name"/></form>')
=> [for='model_name', "Name"]

>> Model.editable = false
>> first_label('<field-list fields="name" tag="input" no-edit="view"/>')
=> [nil, nil]

1 change: 1 addition & 0 deletions hobo/lib/hobo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'hobofields'
begin
require 'will_paginate'
require 'will_paginate/finder'
rescue MissingSourceFile
# OK, Hobo won't do pagination then
end
Expand Down
4 changes: 2 additions & 2 deletions hobo/lib/hobo/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def request_no_cache?
end

def not_found(error)
if self.class.superclass.method_defined?("not_found_response")
super
if self.class.superclass.method_defined?(:not_found)
self.class.superclass.instance_method(:not_found).bind(self).call(error)
elsif render_tag("not-found-page", {}, :status => 404)
# cool
else
Expand Down
8 changes: 5 additions & 3 deletions hobo/lib/hobo/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def self.included(base)

register_model(base)

patch_will_paginate

base.class_eval do
inheriting_cattr_reader :default_order
alias_method_chain :attributes=, :hobo_type_conversion
Expand All @@ -42,7 +40,9 @@ def inherited(klass)
end
end
end


# https://hobo.lighthouseapp.com/projects/8324/tickets/762-hobo_model-outside-a-full-rails-env-can-lead-to-stack-level-too-deep
raise HoboError, "HoboFields.enable has not been called" unless base.respond_to?(:fields)
base.fields(false) # force hobofields to load

included_in_class_callbacks(base)
Expand Down Expand Up @@ -132,6 +132,8 @@ def self.hobo_user_model

Hobo::Permissions.enable
end

patch_will_paginate
end


Expand Down
2 changes: 1 addition & 1 deletion hobo/lib/hobo/model_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def permission_denied(error)
logger.info "Hobo: Permission Denied!"
@permission_error = error
if self.class.superclass.method_defined?("permission_denied")
super
self.class.superclass.instance_method(:permission_denied).bind(self).call(error)
else
respond_to do |wants|
wants.html do
Expand Down
4 changes: 2 additions & 2 deletions hobo/lib/hobo/scopes/automatic_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def create_scope
type = klass.attr_type(field)
if type.nil? #a virtual attribute from an SQL alias, e.g., 'total' from 'COUNT(*) AS total'
colspec = "#{field}" # don't prepend the table name
elsif type.respond_to?(:table_name) && (name = type.name_attribute)
elsif type.respond_to?(:name_attribute) && (name = type.name_attribute)
include = field
colspec = "#{type.table_name}.#{name}"
else
Expand All @@ -290,7 +290,7 @@ def create_scope
words = query.split
args = []
word_queries = words.map do |word|
field_query = '(' + fields.map { |field| "(#{@klass.table_name}.#{field} #{match_keyword} ?)" }.join(" OR ") + ')'
field_query = '(' + fields.map { |field| "(#{@klass.table_name+'.' unless field.to_s.index('.')}#{field} #{match_keyword} ?)" }.join(" OR ") + ')'
args += ["%#{word}%"] * fields.length
field_query
end
Expand Down
8 changes: 7 additions & 1 deletion hobo/taglibs/rapid_core.dryml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
-%>
<labelled-item unless="&tag == 'input' && no_edit == 'skip' && !can_edit?">
<item-label param="#{scope.field_name.to_s.sub('?', '').gsub('.', '-')}-label" unless="&field_name.blank?">
<do param="label"><%= field_name %></do>
<if test="&tag == 'input' && can_edit?">
<%# Need to inline render in order to pass to label_tag %>
<%= label_tag(param_name_for_this, call_tag_parameter(:do_,{}, {:default => Proc.new { field_name }}, all_parameters, :label)) %>
</if>
<else>
<do param="label"><%= field_name %></do>
</else>
</item-label>
<item-value param="#{scope.field_name.to_s.sub('?', '').gsub('.', '-')}-view" colspan="&2 if field_name.blank?">
<do param="view"><call-tag tag="&tag" param="#{scope.field_name.to_s.sub('?', '').gsub('.', '-')}-tag" merge-attrs="&input_attrs"/></do>
Expand Down
15 changes: 13 additions & 2 deletions hobo/taglibs/rapid_forms.dryml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ AJAX based submission can be enabled by simply adding an `update` attribute. e.g
<div part="comments"><collection:comments/></div>
<form with="&Comment.new" update="comments"/>

`<form>` support all of the standard ajax attributes.

### Additional Notes

- Hobo automatically inserts an `auth_token` hidden field if forgery protection is enabled
Expand All @@ -112,6 +110,19 @@ AJAX based submission can be enabled by simply adding an `update` attribute. e.g
validation error occurs.

- `<form>` supports all of the standrd ajax attributes - (see the main taglib docs for Rapid Forms)

- `<form>` resets `last_if` if it does not have permission to display the form. The `<else>` clause may be used to display alternate content. For example:

<form>...</form>
<else>You do not have permission to edit this form</else>

or on a standard generated page using a default form:

<some-page>
<after-form:>
<else>You do not have permission to edit this form</else>
</after-form:>
</some-page>

### Attributes

Expand Down
2 changes: 1 addition & 1 deletion hobo/taglibs/rapid_user_pages.dryml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</def>


<!-- The page that initiates the forgotten password process. Contians a single text-input where the user can provide
<!-- The page that initiates the forgotten password process. Contains a single text-input where the user can provide
their email address -->
<def tag="forgot-password-page">
<simple-page title="#{ht 'hobo.forgot_password.title', :default=>['Forgotten Password'] }" merge>
Expand Down
2 changes: 1 addition & 1 deletion hobosupport/lib/hobo_support/blankslate.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Define BlankSlate in case ActiveSupport aint present
unless defined? BlankSlate
class BlankSlate
instance_methods.reject { |m| m =~ /^__/ || m.to_s == 'object_id' }.each { |m| undef_method m }
(instance_methods+protected_instance_methods+private_instance_methods).reject { |m| m =~ /^__/ || m.to_s == 'object_id' }.each { |m| undef_method m }
def initialize(me)
@me = me
end
Expand Down