forked from spohlenz/tinymce-rails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
120 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ gem 'json', :platforms => [:ruby_18] | |
|
||
group :test do | ||
gem "rspec-rails" | ||
gem "guard-rspec" | ||
end | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
guard 'rspec', :version => 2 do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/tinymce/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module TinyMCE::Rails | ||
class Configuration | ||
def self.defaults | ||
{ | ||
"mode" => "textareas", | ||
"theme" => "advanced", | ||
"language" => default_language, | ||
"editor_selector" => "tinymce" | ||
} | ||
end | ||
|
||
attr_reader :options | ||
|
||
def initialize | ||
@options = self.class.defaults | ||
end | ||
|
||
# Default language falls back to English if current locale is not available. | ||
def self.default_language | ||
available_languages.include?(I18n.locale.to_s) ? I18n.locale.to_s : "en" | ||
end | ||
|
||
# Searches asset paths for TinyMCE language files. | ||
def self.available_languages | ||
assets.paths.map { |path| | ||
files = assets.entries(File.join(path, "tinymce/langs")) | ||
files.map { |file| | ||
asset = assets.attributes_for(File.join(path, file)) | ||
asset.logical_path.sub(/\.js$/, "") | ||
} | ||
}.flatten.uniq | ||
end | ||
|
||
def self.assets | ||
Rails.application.assets | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
module TinyMCE | ||
module Rails | ||
class Engine < ::Rails::Engine | ||
config.tinymce = ActiveSupport::OrderedOptions.new | ||
end | ||
module TinyMCE::Rails | ||
class Engine < ::Rails::Engine | ||
config.tinymce = ActiveSupport::OrderedOptions.new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tinyMCE.addI18n({ | ||
erb: <%= {}.to_json %> | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tinyMCE.addI18n({ | ||
pirate: {} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
module TinyMCE::Rails | ||
describe Configuration do | ||
it "has default options" do | ||
Configuration.defaults.should eq( | ||
"mode" => "textareas", | ||
"theme" => "advanced", | ||
"language" => "en", | ||
"editor_selector" => "tinymce" | ||
) | ||
end | ||
|
||
it "uses the current locale if available" do | ||
I18n.locale = "pirate" | ||
Configuration.defaults["language"].should eq("pirate") | ||
end | ||
|
||
it "falls back to English if the current locale is not available" do | ||
I18n.locale = "missing" | ||
Configuration.defaults["language"].should eq("en") | ||
end | ||
|
||
it "uses default options when instantiated without a filename" do | ||
config = Configuration.new | ||
config.options.should eq(Configuration.defaults) | ||
end | ||
|
||
it "loads configuration from YAML file when instantiated with a filename" | ||
|
||
it "detects available languages" do | ||
langs = Configuration.available_languages | ||
|
||
langs.should include("en") | ||
langs.should include("pirate") | ||
langs.should include("erb") | ||
|
||
langs.should_not include("missing") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
describe TinyMCE::Rails do | ||
before(:each) do | ||
::Rails.application.config.action_controller.asset_host = nil | ||
ActionController::Base.config.relative_url_root = nil | ||
end | ||
|
||
it "has a base path" do | ||
TinyMCE::Rails.base.should eq("/assets/tinymce") | ||
end | ||
|
||
it "uses the asset host in the base path when set" do | ||
::Rails.application.config.action_controller.asset_host = "http://assets.example.com" | ||
TinyMCE::Rails.base.should eq("http://assets.example.com/assets/tinymce") | ||
end | ||
|
||
it "uses the relative url root in the base path when set" do | ||
ActionController::Base.config.relative_url_root = "/subfolder" | ||
TinyMCE::Rails.base.should eq("/subfolder/assets/tinymce") | ||
module TinyMCE | ||
describe Rails do | ||
describe ".base" do | ||
before(:each) do | ||
::Rails.application.config.action_controller.asset_host = nil | ||
ActionController::Base.config.relative_url_root = nil | ||
end | ||
|
||
it "has a base path" do | ||
TinyMCE::Rails.base.should eq("/assets/tinymce") | ||
end | ||
|
||
it "uses the asset host in the base path when set" do | ||
::Rails.application.config.action_controller.asset_host = "http://assets.example.com" | ||
TinyMCE::Rails.base.should eq("http://assets.example.com/assets/tinymce") | ||
end | ||
|
||
it "uses the relative url root in the base path when set" do | ||
ActionController::Base.config.relative_url_root = "/subfolder" | ||
TinyMCE::Rails.base.should eq("/subfolder/assets/tinymce") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters