amrita2 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/init.rb +1 -0
- data/lib/amrita2/rails_bridge.rb +92 -7
- data/lib/amrita2/template.rb +12 -127
- data/lib/amrita2/testsupport.rb +0 -25
- data/lib/amrita2/version.rb +1 -1
- data/sample/depot/app/controllers/admin_controller.rb +3 -1
- data/sample/depot/app/helpers/cart_helper.rb +8 -0
- data/sample/depot/app/helpers/price_helper.rb +7 -0
- data/sample/depot/config/environment.rb +0 -14
- data/sample/depot/config/environments/development.rb +2 -2
- data/sample/depot/db/schema.rb +27 -20
- data/sample/depot/test/functional/admin_controller_test.rb +63 -22
- data/sample/depot/test/functional/store_controller_test.rb +30 -18
- data/sample/depot/vendor/plugins/will_paginate/init.rb +4 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate.rb +61 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +132 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +80 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +181 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +206 -0
- data/sample/depot/vendor/plugins/will_paginate/test/array_pagination_test.rb +131 -0
- data/sample/depot/vendor/plugins/will_paginate/test/boot.rb +23 -0
- data/sample/depot/vendor/plugins/will_paginate/test/finder_test.rb +290 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/company.rb +9 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/project.rb +15 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/schema.rb +38 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/topic.rb +4 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
- data/sample/depot/vendor/plugins/will_paginate/test/helper.rb +25 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb +23 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +67 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +13 -0
- data/sample/depot/vendor/plugins/will_paginate/test/pagination_test.rb +240 -0
- data/sample/hello/test1.rb +23 -0
- data/sample/login_engine/config/environment.rb +18 -20
- data/sample/login_engine/config/environments/development.rb +2 -2
- data/sample/login_engine/db/schema.rb +24 -17
- data/sample/login_engine/lib/login_engine/authenticated_system.rb +18 -18
- data/sample/login_engine/test/functional/user_controller_test.rb +1 -0
- data/sample/ramaze/ramaise_amrita2.rb +156 -0
- data/specs/attribute.rb +11 -0
- data/specs/datatypes.rb +13 -0
- data/specs/sample.rb +1 -2
- data/specs/sanitize.rb +14 -0
- metadata +28 -7
- data/sample/depot/app/helpers/ar_form.rb +0 -169
- data/sample/depot/app/helpers/form_tag.rb +0 -24
- data/sample/depot/app/helpers/standard_form.rb +0 -73
- data/sample/depot/test/integration/dsl_user_stories_test.rb +0 -126
- data/sample/depot/test/integration/user_stories_test.rb +0 -70
@@ -0,0 +1,23 @@
|
|
1
|
+
require "amrita2/template"
|
2
|
+
include Amrita2
|
3
|
+
|
4
|
+
tmpl = Template.new <<-END
|
5
|
+
<<html<
|
6
|
+
<<body<
|
7
|
+
<<h1 :title |Attr[:title, :body]>>
|
8
|
+
<<p <
|
9
|
+
Amrita2 is a html template libraly for Ruby.
|
10
|
+
<%= x %>
|
11
|
+
END
|
12
|
+
|
13
|
+
tmpl.set_trace(STDOUT)
|
14
|
+
puts tmpl.render_with(:title=>{:title=>"hello world", :body=>"hello world" })
|
15
|
+
|
16
|
+
__END__
|
17
|
+
|
18
|
+
<html>
|
19
|
+
<body>
|
20
|
+
<h1>hello world</h1>
|
21
|
+
<p>Amrita2 is a html template libraly for Ruby</p>
|
22
|
+
</body>
|
23
|
+
</html>
|
@@ -1,9 +1,4 @@
|
|
1
1
|
|
2
|
-
$KCODE = 'u' # UTF-8�ξ�硣's' = SJIS, 'e' = EUC-JP�ʤ�
|
3
|
-
require 'jcode' # String���饹�Υ�åɤʤɤ�$KCODE�˻��ꤷ��
|
4
|
-
# ʸ�������ɤ�Ŭ�ڤ�ư���褦���֤������ޤ���
|
5
|
-
|
6
|
-
|
7
2
|
# Be sure to restart your web server when you modify this file.
|
8
3
|
|
9
4
|
# Uncomment below to force Rails into production mode when
|
@@ -48,20 +43,12 @@ Rails::Initializer.run do |config|
|
|
48
43
|
# config.active_record.default_timezone = :utc
|
49
44
|
|
50
45
|
# See Rails::Configuration for more options
|
51
|
-
end
|
52
|
-
|
53
|
-
# Add new inflection rules using the following format
|
54
|
-
# (all these examples are active by default):
|
55
|
-
# Inflector.inflections do |inflect|
|
56
|
-
# inflect.plural /^(ox)$/i, '\1en'
|
57
|
-
# inflect.singular /^(ox)en/i, '\1'
|
58
|
-
# inflect.irregular 'person', 'people'
|
59
|
-
# inflect.uncountable %w( fish sheep )
|
60
|
-
# end
|
61
46
|
|
62
|
-
|
63
|
-
|
64
|
-
|
47
|
+
config.action_controller.session = {
|
48
|
+
:session_key => '_login_engine_session',
|
49
|
+
:secret => 'a148d6564bd91d6e6c41e3bf845a816bf1776789860fe524361b23a5bbcd4846ba7f3fd2bc8534961ff9f95ac0ed0c9ef10b81c3444d15605a5c8895fa7a0437'
|
50
|
+
}
|
51
|
+
end
|
65
52
|
|
66
53
|
# Include your application configuration below
|
67
54
|
|
@@ -119,11 +106,11 @@ module LoginEngine
|
|
119
106
|
end
|
120
107
|
|
121
108
|
# controls whether or not email is used
|
122
|
-
config :use_email_notification,
|
109
|
+
config :use_email_notification, false
|
123
110
|
|
124
111
|
# Controls whether accounts must be confirmed after signing up
|
125
112
|
# ONLY if this and use_email_notification are both true
|
126
|
-
config :confirm_account,
|
113
|
+
config :confirm_account, false
|
127
114
|
|
128
115
|
|
129
116
|
config :salt, "your-salt-here"
|
@@ -138,3 +125,14 @@ require 'amrita2/macro'
|
|
138
125
|
# set text domain for get_text
|
139
126
|
Amrita2View::Base.text_domain = "login_engine"
|
140
127
|
|
128
|
+
# fix trouble with gettext and rails2.0
|
129
|
+
# http://zargony.com/2007/07/29/using-ruby-gettext-with-edge-rails/
|
130
|
+
class CGI
|
131
|
+
module QueryExtension
|
132
|
+
alias index_without_fix :[]
|
133
|
+
def [] (key)
|
134
|
+
return nil unless @params[key]
|
135
|
+
index_without_fix(key)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -9,7 +9,7 @@ config.cache_classes = false
|
|
9
9
|
config.whiny_nils = true
|
10
10
|
|
11
11
|
# Enable the breakpoint server that script/breakpointer connects to
|
12
|
-
config.breakpoint_server = true
|
12
|
+
#config.breakpoint_server = true
|
13
13
|
|
14
14
|
# Show full error reports and disable caching
|
15
15
|
config.action_controller.consider_all_requests_local = true
|
@@ -18,4 +18,4 @@ config.action_view.cache_template_extensions = false
|
|
18
18
|
config.action_view.debug_rjs = true
|
19
19
|
|
20
20
|
# Don't care if the mailer can't send
|
21
|
-
config.action_mailer.raise_delivery_errors = false
|
21
|
+
#config.action_mailer.raise_delivery_errors = false
|
@@ -1,25 +1,32 @@
|
|
1
|
-
# This file is
|
2
|
-
# migrations feature of ActiveRecord to incrementally modify your database, and
|
1
|
+
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
+
# please use the migrations feature of ActiveRecord to incrementally modify your database, and
|
3
3
|
# then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
6
|
+
# to create the application database on another system, you should be using db:schema:load, not running
|
7
|
+
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
8
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
9
|
+
#
|
10
|
+
# It's strongly recommended to check this file into your version control system.
|
4
11
|
|
5
12
|
ActiveRecord::Schema.define(:version => 1) do
|
6
13
|
|
7
14
|
create_table "users", :force => true do |t|
|
8
|
-
t.
|
9
|
-
t.
|
10
|
-
t.
|
11
|
-
t.
|
12
|
-
t.
|
13
|
-
t.
|
14
|
-
t.
|
15
|
-
t.
|
16
|
-
t.
|
17
|
-
t.
|
18
|
-
t.
|
19
|
-
t.
|
20
|
-
t.
|
21
|
-
t.
|
22
|
-
t.
|
15
|
+
t.string "login", :limit => 80, :default => "", :null => false
|
16
|
+
t.string "salted_password", :limit => 40, :default => "", :null => false
|
17
|
+
t.string "email", :limit => 60, :default => "", :null => false
|
18
|
+
t.string "firstname", :limit => 40
|
19
|
+
t.string "lastname", :limit => 40
|
20
|
+
t.string "salt", :limit => 40, :default => "", :null => false
|
21
|
+
t.integer "verified", :default => 0
|
22
|
+
t.string "role", :limit => 40
|
23
|
+
t.string "security_token", :limit => 40
|
24
|
+
t.datetime "token_expiry"
|
25
|
+
t.datetime "created_at"
|
26
|
+
t.datetime "updated_at"
|
27
|
+
t.datetime "logged_in_at"
|
28
|
+
t.integer "deleted", :default => 0
|
29
|
+
t.datetime "delete_after"
|
23
30
|
end
|
24
31
|
|
25
32
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module LoginEngine
|
2
2
|
module AuthenticatedSystem
|
3
|
-
|
3
|
+
|
4
4
|
protected
|
5
5
|
|
6
6
|
# overwrite this if you want to restrict access to only a few actions
|
7
|
-
# or if you want to check if the user has the correct rights
|
7
|
+
# or if you want to check if the user has the correct rights
|
8
8
|
# example:
|
9
9
|
#
|
10
10
|
# # only allow nonbobs
|
@@ -14,10 +14,10 @@ module LoginEngine
|
|
14
14
|
def authorize?(user)
|
15
15
|
true
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# overwrite this method if you only want to protect certain actions of the controller
|
19
19
|
# example:
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# # don't protect the login and the about method
|
22
22
|
# def protect?(action)
|
23
23
|
# if ['action', 'about'].include?(action)
|
@@ -29,42 +29,42 @@ module LoginEngine
|
|
29
29
|
def protect?(action)
|
30
30
|
true
|
31
31
|
end
|
32
|
-
|
33
|
-
# login_required filter. add
|
32
|
+
|
33
|
+
# login_required filter. add
|
34
34
|
#
|
35
35
|
# before_filter :login_required
|
36
36
|
#
|
37
|
-
# if the controller should be under any rights management.
|
37
|
+
# if the controller should be under any rights management.
|
38
38
|
# for finer access control you can overwrite
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# def authorize?(user)
|
41
|
-
#
|
41
|
+
#
|
42
42
|
def login_required
|
43
43
|
if not protect?(action_name)
|
44
|
-
return true
|
44
|
+
return true
|
45
45
|
end
|
46
46
|
|
47
47
|
if user? and authorize?(session[:user])
|
48
48
|
return true
|
49
49
|
end
|
50
50
|
|
51
|
-
# store current location so that we can
|
51
|
+
# store current location so that we can
|
52
52
|
# come back after the user logged in
|
53
53
|
store_location
|
54
|
-
|
54
|
+
|
55
55
|
# call overwriteable reaction to unauthorized access
|
56
56
|
access_denied
|
57
57
|
end
|
58
58
|
|
59
59
|
# overwrite if you want to have special behavior in case the user is not authorized
|
60
|
-
# to access the current operation.
|
60
|
+
# to access the current operation.
|
61
61
|
# the default action is to redirect to the login screen
|
62
62
|
# example use :
|
63
63
|
# a popup window might just close itself for instance
|
64
64
|
def access_denied
|
65
65
|
redirect_to :controller => "/user", :action => "login"
|
66
|
-
end
|
67
|
-
|
66
|
+
end
|
67
|
+
|
68
68
|
# store current uri in the session.
|
69
69
|
# we can return to this location by calling return_location
|
70
70
|
def store_location
|
@@ -76,7 +76,7 @@ module LoginEngine
|
|
76
76
|
if session['return-to'].nil?
|
77
77
|
redirect_to default
|
78
78
|
else
|
79
|
-
|
79
|
+
redirect_to session['return-to']
|
80
80
|
session['return-to'] = nil
|
81
81
|
end
|
82
82
|
end
|
@@ -104,10 +104,10 @@ module LoginEngine
|
|
104
104
|
# Everything failed
|
105
105
|
return false
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# Returns the current user from the session, if any exists
|
109
109
|
def current_user
|
110
110
|
session[:user]
|
111
111
|
end
|
112
112
|
end
|
113
|
-
end
|
113
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# Ramaise Amrita, the Ramaze version of Reprise, a minimal hAtom blog
|
2
|
+
# with Amrita2
|
3
|
+
#
|
4
|
+
# http://redflavor.com/reprise.rb
|
5
|
+
# http://www.rubyinside.com/reprise-a-ruby-powered-blogging-app-in-
|
6
|
+
# 100-lines-including-templates-646.html
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
#
|
10
|
+
# 1. gem install ramaze bluecloth rubypants amrita2 -y
|
11
|
+
# 2. mkdir entries
|
12
|
+
# 3. vi entries/YYYY.MM.DD.Title.Goes.Here
|
13
|
+
# 4. ruby ramaise_amrita2.rb
|
14
|
+
|
15
|
+
%w(rubygems ramaze bluecloth rubypants amrita2).each{|lib| require lib }
|
16
|
+
|
17
|
+
class BlogPost
|
18
|
+
include Amrita2::DictionaryData
|
19
|
+
DIR = __DIR__/:entries
|
20
|
+
|
21
|
+
def initialize filename
|
22
|
+
raise 'Invalid BlogPost filename' unless File.exists?(filename)
|
23
|
+
@filename, filename = filename, File.basename(filename)
|
24
|
+
@date = Date.strptime(filename, '%Y.%m.%d').to_s
|
25
|
+
@title = filename[11..-1].tr('.', ' ')
|
26
|
+
end
|
27
|
+
|
28
|
+
def body
|
29
|
+
RubyPants.new(BlueCloth.new(File.read(@filename)).to_html).to_html
|
30
|
+
end
|
31
|
+
|
32
|
+
def slug
|
33
|
+
@slug ||= title.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :date, :title
|
37
|
+
|
38
|
+
class << self
|
39
|
+
include Enumerable
|
40
|
+
|
41
|
+
def each
|
42
|
+
Dir[DIR/'*'].sort.reverse.each do |file| yield BlogPost.new(file) end
|
43
|
+
end
|
44
|
+
|
45
|
+
def [] key
|
46
|
+
BlogPost.find{|post| post.slug == key }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class MainController < Ramaze::Controller
|
52
|
+
include Amrita2
|
53
|
+
|
54
|
+
TITLE = 'Ramaise with Amrita2 BLOG'
|
55
|
+
AUTHOR = { :name => 'Taku Nakajima', :url => 'http://retro.brain-tokyo.net' }
|
56
|
+
|
57
|
+
engine :Amrita2
|
58
|
+
|
59
|
+
def index slug = nil
|
60
|
+
title = nil
|
61
|
+
if slug.nil?
|
62
|
+
@posts = BlogPost.collect
|
63
|
+
raise Ramaze::Error::NoAction,
|
64
|
+
'No blog posts found, create
|
65
|
+
entries/YYYY.MM.DD.My.First.Blog.Post' unless @posts.any?
|
66
|
+
else
|
67
|
+
raise Ramaze::Error::NoAction,
|
68
|
+
'Invalid blog post' unless post = BlogPost[slug]
|
69
|
+
post = BlogPost[slug]
|
70
|
+
title = post.title
|
71
|
+
@posts = [ post ]
|
72
|
+
end
|
73
|
+
|
74
|
+
title_hook = Amrita2::Core::Hook.new do
|
75
|
+
if title
|
76
|
+
render_child(:post_title, :href=>'/', :text=>title)
|
77
|
+
else
|
78
|
+
render_child(:index_title, :text=>TITLE)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
@data = binding
|
83
|
+
|
84
|
+
%(
|
85
|
+
<<h1 :title_hook | AcceptData[:hook] <
|
86
|
+
<<a :post_title | Attr[:href] <
|
87
|
+
<<:text>>
|
88
|
+
<<span :index_title <
|
89
|
+
<<:text>>
|
90
|
+
|
91
|
+
<<div.hentry :posts <
|
92
|
+
<<h2 { :url=> '/' + $_.slug } <
|
93
|
+
<<abbr.updated title="$1" :| Eval["Time.parse($_.date).iso8601", :date] <
|
94
|
+
$2
|
95
|
+
<<a.entry-title href="$1" rel="bookmark" :| NVar[:url, :title] <
|
96
|
+
$2
|
97
|
+
|
98
|
+
<<div.entry-content :body | NoSanitize >>
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def error
|
103
|
+
title = "#{TITLE}: Resource not found"
|
104
|
+
message = Ramaze::Dispatcher::Error.current.message + '.'
|
105
|
+
go_back = {
|
106
|
+
:href => '/',
|
107
|
+
:body => 'the front page.'
|
108
|
+
}
|
109
|
+
@data = binding
|
110
|
+
%(
|
111
|
+
<<h1 :title>>
|
112
|
+
<<h2 :message>>
|
113
|
+
|
114
|
+
Go back to the
|
115
|
+
<<a :go_back | Attr[:href, :body] >>
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
def layout
|
120
|
+
@data = binding
|
121
|
+
%(
|
122
|
+
<<html<
|
123
|
+
<<head<
|
124
|
+
<<title<
|
125
|
+
%= TITLE
|
126
|
+
%= ': ' + @title if @title
|
127
|
+
<<style type='text/css'<
|
128
|
+
body {
|
129
|
+
font-size: 90%;
|
130
|
+
line-height: 1.4;
|
131
|
+
width: 94%;
|
132
|
+
margin: auto;
|
133
|
+
}
|
134
|
+
|
135
|
+
abbr { border: 0; }
|
136
|
+
|
137
|
+
.entry-content {
|
138
|
+
-moz-column-width: 30em;
|
139
|
+
-moz-column-gap: 1.5em;
|
140
|
+
-webkit-column-width: 30em;
|
141
|
+
-webkit-column-gap: 1.5em;
|
142
|
+
}
|
143
|
+
|
144
|
+
h2 { border-bottom: 0.05em solid #999; }
|
145
|
+
|
146
|
+
<<body<
|
147
|
+
<<:content | NoSanitize >>
|
148
|
+
<<address.author.vcard <
|
149
|
+
<<a.url.fn :AUTHOR | Attr[:href=>:url, :body=>:name]>>
|
150
|
+
)
|
151
|
+
end
|
152
|
+
layout :layout
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
Ramaze.start :sessions => false #, :adapter => :mongrel, :port => 3000
|
data/specs/attribute.rb
CHANGED
@@ -83,6 +83,17 @@ context "Attribute" do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
specify "key with space" do
|
87
|
+
t = Amrita2::Template.new(%[<div><a am:src="aaa" am:filter="Attr[:body=>true, :href=>:'my url']">aaa</a></div>])
|
88
|
+
t.test_with(:aaa => {
|
89
|
+
:"my url"=>"http://amrita2.rubyforge.org/",
|
90
|
+
:body=>"Amrita"
|
91
|
+
}
|
92
|
+
) do |r|
|
93
|
+
r.should_be_samexml_as '<div><a href="http://amrita2.rubyforge.org/">Amrita</a></div>'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
86
97
|
specify "change body key" do
|
87
98
|
t = Amrita2::Template.new('<div><a am:src="aaa|Attr[:href=>:url, :body=>:text]">aaa</a></div>')
|
88
99
|
t.test_with(:aaa => {
|
data/specs/datatypes.rb
CHANGED
@@ -40,6 +40,19 @@ context "DictionaryData" do
|
|
40
40
|
def self.aaa; 'Amrita2';end;
|
41
41
|
@t.render_with(binding).should_be_samexml_as('Amrita2')
|
42
42
|
end
|
43
|
+
|
44
|
+
specify "Accepts key contains spaces" do
|
45
|
+
t = Amrita2::Template.new('<span am:src="key with space" />')
|
46
|
+
result = "Amrita2"
|
47
|
+
t.render_with(:"key with space"=>'Amrita2').should_be_samexml_as("Amrita2")
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "Accepts key contains not-word-character" do
|
51
|
+
t = Amrita2::Template.new('<span am:src="Time.local(2008,1,23,9,23,12)" />')
|
52
|
+
t.render_with(binding).should_be_samexml_as("Wed Jan 23 09:23:12 +0900 2008")
|
53
|
+
t = Amrita2::Template.new('<span am:src="Amrita2::Version::STRING" />')
|
54
|
+
t.render_with(binding).should_be_samexml_as(Amrita2::Version::STRING)
|
55
|
+
end
|
43
56
|
end
|
44
57
|
|
45
58
|
context "NullObject" do
|