splendeo_translator 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,95 @@
1
+ # Stub a Blog Posts controller
2
+ class BlogPostsController < ActionController::Base
3
+
4
+ # Sets up view paths so tests will work
5
+ before_filter :fix_view_paths
6
+
7
+ # Simulate auth filter
8
+ before_filter :authorize, :only => [:admin]
9
+
10
+ layout "blog_layout", :only => :show_with_layout
11
+
12
+ def index
13
+ # Pull out sample strings for index to the fake blog
14
+ @page_title = t('title')
15
+ @intro = translate(:intro, :owner => "Ricky Rails")
16
+ render :nothing => true, :layout => false
17
+ end
18
+
19
+ def show
20
+ # Sample blog post
21
+ render :template => "blog_posts/show"
22
+ end
23
+
24
+ def about
25
+ # About page
26
+ render :template => "blog_posts/about"
27
+ end
28
+
29
+ # Render the show action with a layout
30
+ def show_with_layout
31
+ render :template => "blog_posts/show"
32
+ end
33
+
34
+ # The archives action references a view helper
35
+ def archives
36
+ render :template => "blog_posts/archives"
37
+ end
38
+
39
+ # View that has a key that doesn't reference a valid string
40
+ def missing_translation
41
+ render :template => "blog_posts/missing_translation"
42
+ end
43
+
44
+ def ajax_message
45
+ render :update do |page|
46
+ page << t('no_template.ajax_message')
47
+ end
48
+ end
49
+
50
+ def different_formats
51
+ # Get the same tagline using the different formats
52
+ @taglines = []
53
+ @taglines << t('global.sub.key') # dot-sep keys
54
+ @taglines << t('sub.key', :scope => :global) # dot-sep keys with scope
55
+ @taglines << t('key', :scope => 'global.sub') # string key with dot-sep scope
56
+ @taglines << t(:key, :scope => 'global.sub') # symbol key with dot-sep score
57
+ @taglines << t(:key, :scope => %w(global sub))
58
+ render :nothing => true
59
+ end
60
+
61
+ # Partial template, but stored within this controller
62
+ def footer_partial
63
+ render :partial => "footer"
64
+ end
65
+
66
+ # Partial that is shared across controllers
67
+ def header_partial
68
+ render :partial => "shared/header"
69
+ end
70
+
71
+ def admin
72
+ # Simulate an admin page that has a protection scheme
73
+ end
74
+
75
+ def default_value
76
+ # Get a default value if the string isn't there
77
+ @title = t('not_there', :default => 'the default')
78
+ render :nothing => true
79
+ end
80
+
81
+ protected
82
+
83
+ # Simulate an auth system that prevents login
84
+ def authorize
85
+ # set a flash with a common message
86
+ flash[:error] = t('flash.invalid_login')
87
+ redirect_to :action => :index
88
+ end
89
+
90
+ def fix_view_paths
91
+ # Append the view path to get the correct views/partials
92
+ self.append_view_path("#{File.dirname(__FILE__)}/../views")
93
+ end
94
+
95
+ end
@@ -0,0 +1,10 @@
1
+ # Helper
2
+ module BlogPostsHelper
3
+
4
+ # Get the list of archives
5
+ def get_archives
6
+ # Will be scoped to controller.action ("blog_posts.archives")
7
+ t('title')
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ # A mailer for new comments on the fake blog
2
+ class BlogCommentMailer < ActionMailer::Base
3
+ # Send email about new comments
4
+ def comment_notification
5
+ @subject = t('subject')
6
+ end
7
+ end
8
+
9
+ # Set the path to where the mail template will be found
10
+ BlogCommentMailer.template_root = "#{File.dirname(__FILE__)}/../views"
@@ -0,0 +1,14 @@
1
+ # Model of a blog post, defined in schema.rb
2
+ class BlogPost < ActiveRecord::Base
3
+
4
+ # text for a permalink
5
+ def self.permalink(url)
6
+ t('permalink', :url => url)
7
+ end
8
+
9
+ # Has a title, author and body
10
+ def written_by
11
+ # Get sting like "Written by Ricky"
12
+ t('byline', :author => self.author)
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ Subject: <%= @subject %>
2
+
3
+ From,
4
+
5
+ <%= t('signoff' )%>
@@ -0,0 +1,3 @@
1
+ <hr />
2
+
3
+ <p><%= t('copyright') %></p>
@@ -0,0 +1,6 @@
1
+ <!-- Fake About page -->
2
+ <%# Bio exists in English & Spanish %>
3
+ <%= t('bio') %>
4
+
5
+ <%# Subscribe only exists in English %>
6
+ <%= t('subscribe_feed') %>
@@ -0,0 +1,2 @@
1
+ <%# Call to BlogPostsHelper %>
2
+ <%= get_archives() %>
@@ -0,0 +1,2 @@
1
+ <!-- Key should not be found -->
2
+ <p><%= t('missing_string') %></p>
@@ -0,0 +1,4 @@
1
+ <!-- Simulate blog posting page -->
2
+ <h1><%= t('title') %></h1>
3
+
4
+ <p><%= t('body', :name => 'hobbes') %></h1>
@@ -0,0 +1,9 @@
1
+ <html>
2
+
3
+ <body>
4
+ <h1><%= t('blog_title') %></h1>
5
+
6
+ <%= yield %>
7
+
8
+ </body>
9
+ </html>
@@ -0,0 +1,2 @@
1
+ <!-- The header for my awesome blog -->
2
+ <h1><%= translate('blog_name') %></h1>
@@ -0,0 +1,11 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table "blog_posts", :force => true do |t|
4
+ t.column "title",:string
5
+ t.column "body", :text
6
+ t.column "author", :string
7
+ t.column "created_at", :datetime
8
+ t.column "updated_at", :datetime
9
+
10
+ end
11
+ end
@@ -0,0 +1,60 @@
1
+ en:
2
+ # Global strings
3
+ global:
4
+ sub:
5
+ key: "Hello i18n World"
6
+
7
+ # Controller
8
+ blog_posts:
9
+ # shared strings
10
+ bio: "Hello!"
11
+ subscribe_feed: "Subscribe to my feed!"
12
+
13
+ # typical actions
14
+ index:
15
+ title: "My Blog Posts"
16
+ intro: "Welcome to the blog of {{owner}}"
17
+ # specific post
18
+ show:
19
+ title: "Catz Are Cute"
20
+ body: "My cat {{name}} is the most awesome"
21
+ category: "catz, lolz"
22
+ # archives action - key used from a view helper
23
+ archives:
24
+ title: "My Blog Archives"
25
+ # footer partial (non-shared)
26
+ footer:
27
+ copyright: "Copyright 2009"
28
+
29
+ # Flash messages not specific to one action, but within a single controller
30
+ flash:
31
+ invalid_login: "Invalid login"
32
+
33
+ # shared partials in the "shared" dir
34
+ shared:
35
+ header:
36
+ blog_name: "Ricky Rocks Rails"
37
+
38
+ # Layouts
39
+ layouts:
40
+ blog_layout:
41
+ blog_title: "The Blog of Ricky"
42
+
43
+ # no view template is used
44
+ no_template:
45
+ ajax_message: "Ajax message that doesn't use a template"
46
+
47
+ #
48
+ # ActiveRecord models (note singular)
49
+ #
50
+ blog_post:
51
+ byline: "Written by {{author}}"
52
+ permalink: "Permalink to {{url}}"
53
+
54
+ #
55
+ # ActionMailers
56
+ #
57
+ blog_comment_mailer:
58
+ comment_notification:
59
+ subject: "New Comment Notification"
60
+ signoff: "Your Faithful Emailing Bot"
@@ -0,0 +1,16 @@
1
+ # Spanish version (pardon the bad translations)
2
+ es:
3
+ # Global strings
4
+ global:
5
+ sub:
6
+ key: "Hola i18n Mundo"
7
+
8
+ # Controller
9
+ blog_posts:
10
+ # shared strings
11
+ bio: "Hola!"
12
+
13
+ # typical actions
14
+ index:
15
+ # Purposely has the intro but *not* "title" key
16
+ intro: "Bienvenidos a el blog de {{owner}}"
@@ -0,0 +1,90 @@
1
+ # Load Rails from the app, which allows picking up a frozen rails install
2
+ # instead of from the gems
3
+ #
4
+ # Borrowed from setup in classic_pagination plugin
5
+ plugin_root = File.join(File.dirname(__FILE__), '..')
6
+ # is the plugin installed in an application?
7
+ app_root = plugin_root + '/../../..'
8
+
9
+ if File.directory? app_root + '/config'
10
+ Object.const_set(:RAILS_ENV, ENV["RAILS_ENV"] ||= "test") unless defined?(RAILS_ENV)
11
+ Object.const_set(:RAILS_ROOT, app_root) unless defined?(RAILS_ROOT)
12
+ require "#{RAILS_ROOT}/config/environment"
13
+ end
14
+
15
+ require 'pp'
16
+ require 'test/unit'
17
+ require 'rubygems'
18
+ require 'active_support'
19
+ require 'active_support/test_case'
20
+
21
+ require 'action_controller'
22
+ require 'action_controller/test_process'
23
+ require 'action_mailer'
24
+ require 'active_record'
25
+ require 'active_record/fixtures'
26
+
27
+ require 'action_pack'
28
+ require 'action_view'
29
+ require 'action_view/helpers'
30
+
31
+ # Load the Translator init after loading Rails
32
+ require File.dirname(__FILE__) + '/../init'
33
+
34
+ # Set up an ActiveRecord connection to sqlite db for testing
35
+ # Define the connector
36
+ class ActiveRecordTestConnector
37
+ cattr_accessor :able_to_connect
38
+ cattr_accessor :connected
39
+
40
+ # Set our defaults
41
+ self.connected = false
42
+ self.able_to_connect = true
43
+
44
+ class << self
45
+ def setup
46
+ unless self.connected || !self.able_to_connect
47
+ setup_connection
48
+ load_schema
49
+ self.connected = true
50
+ end
51
+ rescue Exception => e # errors from ActiveRecord setup
52
+ $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
53
+ self.able_to_connect = false
54
+ end
55
+
56
+ private
57
+
58
+ def setup_connection
59
+ if Object.const_defined?(:ActiveRecord)
60
+ defaults = { :database => ':memory:' }
61
+ begin
62
+ options = defaults.merge :adapter => 'sqlite3', :timeout => 500
63
+ ActiveRecord::Base.establish_connection(options)
64
+ ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
65
+ ActiveRecord::Base.connection
66
+ rescue Exception # errors from establishing a connection
67
+ $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.'
68
+ options = defaults.merge :adapter => 'sqlite'
69
+ ActiveRecord::Base.establish_connection(options)
70
+ ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options }
71
+ ActiveRecord::Base.connection
72
+ end
73
+
74
+ Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE)
75
+ else
76
+ raise "Can't setup connection since ActiveRecord isn't loaded."
77
+ end
78
+ end
79
+
80
+ # Loads the schema.rb
81
+ def load_schema
82
+ # Silence the output of creating the db
83
+ silence_stream(STDOUT) do
84
+ Dir.glob(File.dirname(__FILE__) + "/fixtures/schema.rb").each {|f| require f}
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ ActiveRecordTestConnector.setup