diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..428eeb0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+\#*
+*~
+.#*
+.DS_Store
+.idea
+.project
+tmp
+nbproject
+*.swp
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..5800638
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the Rails Dog LLC nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..47bf1e7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+SpreeEditor
+===========
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2010 [name of extension creator], released under the New BSD License
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..6772bed
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,31 @@
+require File.expand_path('../../config/application', __FILE__)
+
+require 'rubygems'
+require 'rake'
+require 'rake/testtask'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
+
+spec = eval(File.read('spree_editor.gemspec'))
+
+Rake::GemPackageTask.new(spec) do |p|
+ p.gem_spec = spec
+end
+
+desc "Release to gemcutter"
+task :release => :package do
+ require 'rake/gemcutter'
+ Rake::Gemcutter::Tasks.new(spec).define
+ Rake::Task['gem:push'].invoke
+end
+
+desc "Default Task"
+task :default => [ :spec ]
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new
+
+# require 'cucumber/rake/task'
+# Cucumber::Rake::Task.new do |t|
+# t.cucumber_opts = %w{--format pretty}
+# end
\ No newline at end of file
diff --git a/app/controllers/content_files_controller.rb b/app/controllers/content_files_controller.rb
new file mode 100644
index 0000000..7fc1436
--- /dev/null
+++ b/app/controllers/content_files_controller.rb
@@ -0,0 +1,10 @@
+class ContentFilesController < Spree::BaseController
+
+ def create
+ @content_file = ContentFile.new(params[:content_file])
+ @content_file.save!
+
+ render :text => "#{@content_file.attachment.url},#{@content_file.attachment_file_name}"
+ end
+
+end
diff --git a/app/controllers/content_images_controller.rb b/app/controllers/content_images_controller.rb
new file mode 100644
index 0000000..bff7699
--- /dev/null
+++ b/app/controllers/content_images_controller.rb
@@ -0,0 +1,10 @@
+class ContentImagesController < Spree::BaseController
+
+ def create
+ @content_image = ContentImage.new(params[:content_image])
+ @content_image.save!
+
+ render :text => @content_image.attachment.url
+ end
+
+end
diff --git a/app/models/content_file.rb b/app/models/content_file.rb
new file mode 100644
index 0000000..5b3bc42
--- /dev/null
+++ b/app/models/content_file.rb
@@ -0,0 +1,5 @@
+class ContentFile < Asset
+ has_attached_file :attachment,
+ :url => "/assets/content_files/:id/:basename.:extension",
+ :path => ":rails_root/public/assets/content_files/:id/:basename.:extension"
+end
diff --git a/app/models/content_image.rb b/app/models/content_image.rb
new file mode 100644
index 0000000..f87efdb
--- /dev/null
+++ b/app/models/content_image.rb
@@ -0,0 +1,7 @@
+class ContentImage < Image
+ has_attached_file :attachment,
+ :styles => {:mini => '48x48#', :large => '600x600>'},
+ :default_style => :large,
+ :url => "/assets/content_images/:id/:style/:basename.:extension",
+ :path => ":rails_root/public/assets/content_images/:id/:style/:basename.:extension"
+end
diff --git a/app/views/shared/_editor.html.erb b/app/views/shared/_editor.html.erb
new file mode 100644
index 0000000..57fb7e9
--- /dev/null
+++ b/app/views/shared/_editor.html.erb
@@ -0,0 +1,207 @@
+<% content_for :head do %>
+ <%= stylesheet_link_tag 'editor' %>
+<% end %>
+
+
+ <%= t("editor.loading") %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/config/locale/en.yml b/config/locale/en.yml
new file mode 100644
index 0000000..4175b9c
--- /dev/null
+++ b/config/locale/en.yml
@@ -0,0 +1,25 @@
+---
+en:
+ editor:
+ loading: Loading
+ font_name_and_size: Font Name and Size
+ font_style: Font Style
+ alignment: Alignment
+ paragraph_style: Paragraph Style
+ indenting_and_lists: "Indenting/Lists"
+ insert_item: Insert Item
+ insert_image: Insert Image
+ upload_image: Upload Image
+ upload_image: Upload File
+ show_more_fields: Show more fields
+ hide_more_fields: Hide more fields
+ switch_simple: Switch to Simple Editor
+ switch_rich: Switch to Rich Editor
+ no_link: "No link Add Slug Or Foreign Link"
+ in_menu: Menu
+ sidebar: Sidebar
+ header: Header
+ footer: Footer
+ parent: Parent page
+ main_page: Main
+ enter_file_name: Enter file name
diff --git a/config/locale/ru.yml b/config/locale/ru.yml
new file mode 100644
index 0000000..b8bf57c
--- /dev/null
+++ b/config/locale/ru.yml
@@ -0,0 +1,24 @@
+ru:
+ editor:
+ loading: Загружается
+ font_name_and_size: Шрифт и размер
+ font_style: Стиль
+ alignment: Выравнивание
+ paragraph_style: Стиль
+ indenting_and_lists: "Отступы/списки"
+ insert_item: Вставка
+ insert_image: Вставить картинки по адресу
+ upload_image: Загрузить картинку
+ upload_image: Загрузить файл
+ show_more_fields: Показать дополнительные поля
+ hide_more_fields: Скрыть дополнительные поля
+ switch_simple: Переключиться на простой редактор
+ switch_rich: Переключиться на расширенный
+ no_link: "Нет ссылки Добавьте Адрес или Внешнюю ссылку"
+ in_menu: Меню
+ sidebar: Боковое меню
+ header: Верхнее меню
+ footer: Нижнее меню
+ parent: Находится на странице
+ main_page: Главная
+ enter_file_name: Введите имя файла
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000..9ac6e7c
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,6 @@
+Rails.application.routes.draw do
+
+ resources :content_images, :only => [:create]
+ resources :content_files, :only => [:create]
+
+end
diff --git a/lib/helpers/editor_helper.rb b/lib/helpers/editor_helper.rb
new file mode 100644
index 0000000..5a99f30
--- /dev/null
+++ b/lib/helpers/editor_helper.rb
@@ -0,0 +1,10 @@
+module EditorHelper
+
+ def rich_editor(options)
+ options[:editor_id] = options[:id]
+ options.delete(:id)
+
+ render :partial => "shared/editor", :locals => options
+ end
+
+end
diff --git a/lib/spree_editor.rb b/lib/spree_editor.rb
new file mode 100644
index 0000000..c3b7a5c
--- /dev/null
+++ b/lib/spree_editor.rb
@@ -0,0 +1,22 @@
+require 'spree_core'
+require 'spree_editor_hooks'
+require 'helpers/editor_helper'
+
+module SpreeEditor
+ class Engine < Rails::Engine
+
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+ end
+
+ config.to_prepare &method(:activate).to_proc
+ end
+end
+
+ActionView::Base.class_eval do
+ include EditorHelper
+end
diff --git a/lib/spree_editor_hooks.rb b/lib/spree_editor_hooks.rb
new file mode 100644
index 0000000..1823a04
--- /dev/null
+++ b/lib/spree_editor_hooks.rb
@@ -0,0 +1,3 @@
+class SpreeEditorHooks < Spree::ThemeSupport::HookListener
+ # custom hooks go here
+end
\ No newline at end of file
diff --git a/lib/tasks/install.rake b/lib/tasks/install.rake
new file mode 100644
index 0000000..8f0ae21
--- /dev/null
+++ b/lib/tasks/install.rake
@@ -0,0 +1,25 @@
+namespace :spree_editor do
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
+ task :install do
+ Rake::Task['spree_editor:install:migrations'].invoke
+ Rake::Task['spree_editor:install:assets'].invoke
+ end
+
+ namespace :install do
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
+ task :migrations do
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
+ destination = File.join(Rails.root, 'db')
+ Spree::FileUtilz.mirror_files(source, destination)
+ end
+
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
+ task :assets do
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
+ destination = File.join(Rails.root, 'public')
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
+ Spree::FileUtilz.mirror_files(source, destination)
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/lib/tasks/spree_editor.rake b/lib/tasks/spree_editor.rake
new file mode 100644
index 0000000..2c5c4e2
--- /dev/null
+++ b/lib/tasks/spree_editor.rake
@@ -0,0 +1 @@
+# add custom rake tasks here
\ No newline at end of file
diff --git a/public/stylesheets/editor.css b/public/stylesheets/editor.css
new file mode 100644
index 0000000..41431aa
--- /dev/null
+++ b/public/stylesheets/editor.css
@@ -0,0 +1,37 @@
+.yui-editor-container A {color: black !important;}
+.editor-mask-container.active .editor-mask {
+ background-color: black;
+ filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30); /* IE 5.5+*/
+ -moz-opacity: 0.3; /* Mozilla 1.6 */
+ -webkit-opacity: 0.3; /* Mozilla 1.6 */
+ -khtml-opacity: 0.3; /* Konqueror 3.1, Safari 1.1 */
+ opacity: 0.3;
+ width: 100%;
+ height: 100%;
+ width: 100%;
+ z-index: 100;
+ position: fixed;
+ top: 0;
+ left: 0;
+}
+.editor-mask-container .editor-mask-label {display: none;}
+.editor-mask-container.active .editor-mask-label {
+ background-color: black;
+ color: white;
+ font-weight: bold;
+ height: 25px;
+ left: 50%;
+ margin-left: -130px;
+ padding: 30px 50px;
+ position: fixed;
+ top: 250px;
+ width: 200px;
+ z-index: 101;
+ display: block !important;
+}
+.yui-toolbar-imageUpload {
+ background: url("/images/upload_image.png") no-repeat scroll 50% 50% transparent !important;
+}
+.yui-toolbar-fileUpload {
+ background: url("/images/upload_file.png") no-repeat scroll 50% 50% transparent !important;
+}
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..87449fe
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,30 @@
+# This file is copied to ~/spec when you run 'ruby script/generate rspec'
+# from the project root directory.
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../../config/environment", __FILE__)
+require 'rspec/rails'
+
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ #config.include Devise::TestHelpers, :type => :controller
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, comment the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+end
+
+@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
diff --git a/spree_editor.gemspec b/spree_editor.gemspec
new file mode 100644
index 0000000..3786683
--- /dev/null
+++ b/spree_editor.gemspec
@@ -0,0 +1,21 @@
+Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.name = 'spree_editor'
+ s.version = '1.0.0'
+ s.summary = 'Add gem summary here'
+ #s.description = 'Add (optional) gem description here'
+ s.required_ruby_version = '>= 1.8.7'
+
+ # s.author = 'David Heinemeier Hansson'
+ # s.email = 'david@loudthinking.com'
+ # s.homepage = 'http://www.rubyonrails.org'
+ # s.rubyforge_project = 'actionmailer'
+
+ s.files = Dir['CHANGELOG', 'README.md', 'LICENSE', 'lib/**/*', 'app/**/*']
+ s.require_path = 'lib'
+ s.requirements << 'none'
+
+ s.has_rdoc = true
+
+ s.add_dependency('spree_core', '>= 0.40.99')
+end
\ No newline at end of file