rmce_uploadr 0.0.2 → 0.0.3

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.
@@ -19,17 +19,21 @@ For this gem to work you *have* to put your TinyMCE javascripts in public/javasc
19
19
  === 2. Set RMceUploadr::App as a middleware
20
20
 
21
21
  * for a rails app add the following inside <tt>Rails::Initializer.run</tt> block:
22
- config.middleware.use "RMceUploadr::App" do |conf|
22
+ config.middleware.use "RMceUploadr::App" do |app|
23
23
  # configuration according to ActiveRecord::Base.establish_connection
24
- conf.dbconf = {:adapter => 'sqlite3',
25
- :database => File.join(File.dirname(__FILE__), '..', '..', 'shared', 'db.sqlite3')}
24
+ app.dbconf = {:adapter => 'sqlite3',
25
+ :database => File.join(File.dirname(__FILE__), '..', '..', 'shared', 'db.sqlite3')}
26
+ app.settings.set :cdn_host, "http://localhost:3000"
26
27
  end
27
28
  * almost the same if you're a rack/sinatra app:
28
- use ::RMceUploadr::App do |conf|
29
+ use ::RMceUploadr::App do |app|
29
30
  # configuration according to ActiveRecord::Base.establish_connection
30
- conf.dbconf = {:adapter => 'sqlite3',
31
- :database => root_path('..', 'shared', 'db.sqlite3')}
31
+ app.dbconf = {:adapter => 'sqlite3',
32
+ :database => root_path('..', 'shared', 'db.sqlite3')}
32
33
  end
34
+ <tt>cdn_host</tt> is an optional parameter. Useful when you host your images through another domain.
35
+ Having this set will result in images src attribute be an absolute URL, otherwise image URLs will
36
+ be something like "/public/uploads/g/images/..."
33
37
 
34
38
  === 3. Add plugin loading to TinyMCE init function, e.g.
35
39
 
data/Rakefile CHANGED
@@ -17,7 +17,9 @@ begin
17
17
  gem.add_dependency "activerecord", ">= 2.3.4"
18
18
  gem.add_dependency "paperclip", ">= 2.3.1.1"
19
19
  gem.add_development_dependency "rspec", ">= 1.2.9"
20
+ gem.add_development_dependency "rack-test", ">= 0.5.3"
20
21
  gem.files.include('lib/**/*.rb', 'lib/rmce_uploadr/public/**/*', 'lib/**/*.erb')
22
+ gem.test_files.include('spec/test.sqlite3')
21
23
  end
22
24
  Jeweler::GemcutterTasks.new
23
25
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,243 +1,15 @@
1
- == Welcome to Rails
1
+ = How to run
2
2
 
3
- Rails is a web-application framework that includes everything needed to create
4
- database-backed web applications according to the Model-View-Control pattern.
3
+ First, create the database
5
4
 
6
- This pattern splits the view (also called the presentation) into "dumb" templates
7
- that are primarily responsible for inserting pre-built data in between HTML tags.
8
- The model contains the "smart" domain objects (such as Account, Product, Person,
9
- Post) that holds all the business logic and knows how to persist themselves to
10
- a database. The controller handles the incoming requests (such as Save New Account,
11
- Update Product, Show Post) by manipulating the model and directing data to the view.
5
+ rake db:create
6
+
7
+ Run the migrations
12
8
 
13
- In Rails, the model is handled by what's called an object-relational mapping
14
- layer entitled Active Record. This layer allows you to present the data from
15
- database rows as objects and embellish these data objects with business logic
16
- methods. You can read more about Active Record in
17
- link:files/vendor/rails/activerecord/README.html.
9
+ rake db:migrate
10
+
11
+ And lastly,
18
12
 
19
- The controller and view are handled by the Action Pack, which handles both
20
- layers by its two parts: Action View and Action Controller. These two layers
21
- are bundled in a single package due to their heavy interdependence. This is
22
- unlike the relationship between the Active Record and Action Pack that is much
23
- more separate. Each of these packages can be used independently outside of
24
- Rails. You can read more about Action Pack in
25
- link:files/vendor/rails/actionpack/README.html.
26
-
27
-
28
- == Getting Started
29
-
30
- 1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
- and your application name. Ex: rails myapp
32
- 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
33
- 3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
- 4. Follow the guidelines to start developing your application
35
-
36
-
37
- == Web Servers
38
-
39
- By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
- with a variety of other web servers.
41
-
42
- Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
43
- suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
44
- getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
45
- More info at: http://mongrel.rubyforge.org
46
-
47
- Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
48
- Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
49
- FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
50
-
51
- == Apache .htaccess example for FCGI/CGI
52
-
53
- # General Apache options
54
- AddHandler fastcgi-script .fcgi
55
- AddHandler cgi-script .cgi
56
- Options +FollowSymLinks +ExecCGI
57
-
58
- # If you don't want Rails to look in certain directories,
59
- # use the following rewrite rules so that Apache won't rewrite certain requests
60
- #
61
- # Example:
62
- # RewriteCond %{REQUEST_URI} ^/notrails.*
63
- # RewriteRule .* - [L]
64
-
65
- # Redirect all requests not available on the filesystem to Rails
66
- # By default the cgi dispatcher is used which is very slow
67
- #
68
- # For better performance replace the dispatcher with the fastcgi one
69
- #
70
- # Example:
71
- # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
72
- RewriteEngine On
73
-
74
- # If your Rails application is accessed via an Alias directive,
75
- # then you MUST also set the RewriteBase in this htaccess file.
76
- #
77
- # Example:
78
- # Alias /myrailsapp /path/to/myrailsapp/public
79
- # RewriteBase /myrailsapp
80
-
81
- RewriteRule ^$ index.html [QSA]
82
- RewriteRule ^([^.]+)$ $1.html [QSA]
83
- RewriteCond %{REQUEST_FILENAME} !-f
84
- RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
85
-
86
- # In case Rails experiences terminal errors
87
- # Instead of displaying this message you can supply a file here which will be rendered instead
88
- #
89
- # Example:
90
- # ErrorDocument 500 /500.html
91
-
92
- ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
93
-
94
-
95
- == Debugging Rails
96
-
97
- Sometimes your application goes wrong. Fortunately there are a lot of tools that
98
- will help you debug it and get it back on the rails.
99
-
100
- First area to check is the application log files. Have "tail -f" commands running
101
- on the server.log and development.log. Rails will automatically display debugging
102
- and runtime information to these files. Debugging info will also be shown in the
103
- browser on requests from 127.0.0.1.
104
-
105
- You can also log your own messages directly into the log file from your code using
106
- the Ruby logger class from inside your controllers. Example:
107
-
108
- class WeblogController < ActionController::Base
109
- def destroy
110
- @weblog = Weblog.find(params[:id])
111
- @weblog.destroy
112
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
113
- end
114
- end
115
-
116
- The result will be a message in your log file along the lines of:
117
-
118
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
119
-
120
- More information on how to use the logger is at http://www.ruby-doc.org/core/
121
-
122
- Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
123
-
124
- * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
125
- * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
126
-
127
- These two online (and free) books will bring you up to speed on the Ruby language
128
- and also on programming in general.
129
-
130
-
131
- == Debugger
132
-
133
- Debugger support is available through the debugger command when you start your Mongrel or
134
- Webrick server with --debugger. This means that you can break out of execution at any point
135
- in the code, investigate and change the model, AND then resume execution!
136
- You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
137
- Example:
138
-
139
- class WeblogController < ActionController::Base
140
- def index
141
- @posts = Post.find(:all)
142
- debugger
143
- end
144
- end
145
-
146
- So the controller will accept the action, run the first line, then present you
147
- with a IRB prompt in the server window. Here you can do things like:
148
-
149
- >> @posts.inspect
150
- => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
151
- #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
152
- >> @posts.first.title = "hello from a debugger"
153
- => "hello from a debugger"
154
-
155
- ...and even better is that you can examine how your runtime objects actually work:
156
-
157
- >> f = @posts.first
158
- => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
159
- >> f.
160
- Display all 152 possibilities? (y or n)
161
-
162
- Finally, when you're ready to resume execution, you enter "cont"
163
-
164
-
165
- == Console
166
-
167
- You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
- Here you'll have all parts of the application configured, just like it is when the
169
- application is running. You can inspect domain models, change values, and save to the
170
- database. Starting the script without arguments will launch it in the development environment.
171
- Passing an argument will specify a different environment, like <tt>script/console production</tt>.
172
-
173
- To reload your controllers and models after launching the console run <tt>reload!</tt>
174
-
175
- == dbconsole
176
-
177
- You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
- You would be connected to the database with the credentials defined in database.yml.
179
- Starting the script without arguments will connect you to the development database. Passing an
180
- argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
181
- Currently works for mysql, postgresql and sqlite.
182
-
183
- == Description of Contents
184
-
185
- app
186
- Holds all the code that's specific to this particular application.
187
-
188
- app/controllers
189
- Holds controllers that should be named like weblogs_controller.rb for
190
- automated URL mapping. All controllers should descend from ApplicationController
191
- which itself descends from ActionController::Base.
192
-
193
- app/models
194
- Holds models that should be named like post.rb.
195
- Most models will descend from ActiveRecord::Base.
196
-
197
- app/views
198
- Holds the template files for the view that should be named like
199
- weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
200
- syntax.
201
-
202
- app/views/layouts
203
- Holds the template files for layouts to be used with views. This models the common
204
- header/footer method of wrapping views. In your views, define a layout using the
205
- <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
206
- call <% yield %> to render the view using this layout.
207
-
208
- app/helpers
209
- Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
- for you automatically when using script/generate for controllers. Helpers can be used to
211
- wrap functionality for your views into methods.
212
-
213
- config
214
- Configuration files for the Rails environment, the routing map, the database, and other dependencies.
215
-
216
- db
217
- Contains the database schema in schema.rb. db/migrate contains all
218
- the sequence of Migrations for your schema.
219
-
220
- doc
221
- This directory is where your application documentation will be stored when generated
222
- using <tt>rake doc:app</tt>
223
-
224
- lib
225
- Application specific libraries. Basically, any kind of custom code that doesn't
226
- belong under controllers, models, or helpers. This directory is in the load path.
227
-
228
- public
229
- The directory available for the web server. Contains subdirectories for images, stylesheets,
230
- and javascripts. Also contains the dispatchers and the default HTML files. This should be
231
- set as the DOCUMENT_ROOT of your web server.
232
-
233
- script
234
- Helper scripts for automation and generation.
235
-
236
- test
237
- Unit and functional tests along with fixtures. When using the script/generate scripts, template
238
- test files will be generated for you and placed in this directory.
239
-
240
- vendor
241
- External libraries that the application depends on. Also includes the plugins subdirectory.
242
- If the app has frozen rails, those gems also go here, under vendor/rails/.
243
- This directory is in the load path.
13
+ script/server
14
+
15
+ Point your browser to http://localhost:3000
@@ -12,6 +12,8 @@
12
12
  tinyMCE.init({
13
13
  plugins: "rmce_uploadr,inlinepopups",
14
14
  mode : "textareas",
15
+ convert_urls : false,
16
+ relative_urls : false,
15
17
  theme : "advanced",
16
18
  dialog_type: 'modal',
17
19
  theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink,image",
@@ -40,8 +40,9 @@ Rails::Initializer.run do |config|
40
40
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
41
41
  # config.i18n.default_locale = :de
42
42
 
43
- config.middleware.use "RMceUploadr::App" do |conf|
44
- conf.dbconf = {:adapter => 'sqlite3',
43
+ config.middleware.use "RMceUploadr::App" do |app|
44
+ app.dbconf = {:adapter => 'sqlite3',
45
45
  :database => File.join(File.dirname(__FILE__), '..', '..', 'shared', 'db.sqlite3')}
46
+ app.settings.set :cdn_host, "http://localhost:3000"
46
47
  end
47
48
  end
@@ -33,7 +33,7 @@ ActionController::Routing::Routes.draw do |map|
33
33
  # end
34
34
 
35
35
  # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
36
- # map.root :controller => "welcome"
36
+ map.root :controller => "posts"
37
37
 
38
38
  # See how all your routes lay out with "rake routes"
39
39
 
Binary file
@@ -6,4 +6,4 @@ gem "rack-flash", ">= 0.1.1"
6
6
  gem "sinatra", ">= 1.0"
7
7
  gem "activerecord", ">= 2.3.2"
8
8
  gem "sqlite3-ruby", :require => "sqlite3"
9
- gem "rmce_uploadr", "= 0.0.1"
9
+ gem "rmce_uploadr", "= 0.0.3"
@@ -0,0 +1,13 @@
1
+ = How to run
2
+
3
+ It is pretty much setup already. <tt>db/development.sqlite3</tt> contains valid <tt>images</tt> (empty) table so all you need to do is run
4
+
5
+ bundle install
6
+
7
+ (you'll need bundler gem for that) and
8
+
9
+ scripts/server
10
+
11
+ (you'll need shotgun gem)
12
+
13
+ Point your browser to http://localhost:3000
@@ -18,6 +18,11 @@ module RMceUploadr
18
18
  set :public, rmce_uploadr_root_path('rmce_uploadr', 'public')
19
19
  set :views, rmce_uploadr_root_path('rmce_uploadr', 'views')
20
20
 
21
+ # a host that distributes static content
22
+ # can be set in use RMceUPloadr::App do |conf| block like
23
+ # conf.settings.set :cdn_host, "http://cdn.host.com/"
24
+ set :cdn_host, nil
25
+
21
26
  def dbconf=(opts)
22
27
  RMceUploadr.dbconf = opts
23
28
  end
@@ -1,7 +1,53 @@
1
+ # This class expects the following table attributes to be found:
2
+ # - +data_file_name+ (string)
3
+ # - +data_content_type+ (string)
4
+ # - +data_file_size+ (integer)
5
+ # - +data_updated_at+ (datetime)
6
+ # - +width+ (integer)
7
+ # - +height+ (integer)
1
8
  class RMceUploadr::Image < ActiveRecord::Base
2
9
  has_attached_file :data, :styles => { :medium => "300x300>", :thumb => "100x100#" },
3
10
  :url => "/uploads/g/images/:id_partition/:style_:filename",
4
11
  :default_url => "/images/rmce_uploadr_default/:style.png",
5
12
  :storage => :filesystem,
6
13
  :path => "public/uploads/g/images/:id_partition/:style_:filename"
14
+ # set in images_controller
15
+ # needed to calcuate original file geometry in :update_image_geometry
16
+ attr_accessor :tempfile
17
+
18
+ before_save :update_image_geometry
19
+
20
+ # Returns a string with width and height
21
+ # e.g. "100x50"
22
+ def geometry
23
+ return "" if width.nil? || height.nil?
24
+ "#{width}x#{height}"
25
+ end
26
+
27
+ # Convers image size in B, Kb, Mb or Gb
28
+ # and returns something like "10Kb"
29
+ def size_in_bytes
30
+ case data_file_size
31
+ when 0..1023
32
+ "#{data_file_size}B"
33
+ when 1024..1048575
34
+ "#{(data_file_size / 1024.0).round}Kb"
35
+ when 1048576..1073741823
36
+ "#{(data_file_size / 1048576.0).round}Mb"
37
+ else
38
+ "#{(data_file_size / 1073741823.0).round}Gb"
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def update_image_geometry
45
+ unless tempfile.nil?
46
+ begin
47
+ geometry = Paperclip::Geometry.from_file(tempfile)
48
+ self.width = geometry.width.to_i
49
+ self.height = geometry.height.to_i
50
+ rescue NotIdentifiedByImageMagickError => e; end
51
+ end
52
+ end
7
53
  end
@@ -22,8 +22,7 @@ module Sinatra
22
22
  # actual image upload
23
23
  app.post '/rmce_uploadr/images' do
24
24
  data = Fash.new(params[:image][:data])
25
- puts data.inspect
26
- @image = ::RMceUploadr::Image.new(:data => data)
25
+ @image = ::RMceUploadr::Image.new(:data => data, :tempfile => data.to_tempfile)
27
26
  @image.save
28
27
  redirect '/rmce_uploadr/images'
29
28
  end
@@ -1 +1,39 @@
1
- // rmce_uploadr app javascript
1
+ /*
2
+ * rmce_uploadr app main javascript
3
+ *
4
+ * should be loaded after tiny_mce.js and jquery.js
5
+ */
6
+
7
+ // when DOM is loaded
8
+ $(function(){
9
+ // we're looking mainly for images that have data-src-original attribute set
10
+ $("[data-src-original]").click(function(){
11
+ var editor = tinyMCEPopup.editor;
12
+
13
+ // Fixes crash in Safari
14
+ if (tinymce.isWebKit) { editor.getWin().focus(); }
15
+
16
+ // TODO: add widht, height and other stuff
17
+ var imgParams = {
18
+ src: uploadrCdnHost + $(this).attr('data-src-original')
19
+ };
20
+
21
+ // get original selection, an image already inserted in the editor's main area
22
+ var original = editor.selection.getNode();
23
+
24
+ // check if that's really an image and replace it with the new one
25
+ if (original && original.nodeName == 'IMG') {
26
+ editor.dom.setAttribs(original, imgParams);
27
+
28
+ // otherwise just insert a new image
29
+ } else {
30
+ editor.execCommand('mceInsertContent', false, '<img id="__mce_tmp" />', {skip_undo : 1});
31
+ editor.dom.setAttribs('__mce_tmp', imgParams);
32
+ editor.dom.setAttrib('__mce_tmp', 'id', '');
33
+ editor.undoManager.add();
34
+ }
35
+
36
+ // close ourselves, i.e. the popup
37
+ tinyMCEPopup.close();
38
+ });
39
+ });
@@ -1,11 +1,12 @@
1
- <p>
2
- images index files (GET /rmce_uploadr/images)
3
- </p>
1
+ <% @images.each do |image| %>
2
+ <div class="image">
3
+ <img src="<%= image.data.url(:thumb) %>" width="100" height="100" class="srcimage"
4
+ data-src-original="<%= image.data.url(:original) %>" />
5
+ <br/>
6
+ <span class="small"><%= image.size_in_bytes %>, <%= image.geometry %></span>
7
+ </div>
8
+ <% end %>
4
9
 
5
- <ul>
6
- <% @images.each do |image| %>
7
- <li><img src="<%= image.data.url(:thumb) %>"
8
- data-src-original="<%= image.data.url(:original) %>"
9
- width="100" height="100" class="srcimage"/></li>
10
- <% end %>
11
- </ul>
10
+ <% if @images.empty? %>
11
+ <em class="quiet">No images found, yet.</em>
12
+ <% end %>
@@ -3,42 +3,53 @@
3
3
  <html>
4
4
  <head>
5
5
  <title>RMce Uploadr</title>
6
- <script type="text/javascript" charset="utf-8" src="/javascripts/tiny_mce/tiny_mce_popup.js"></script>
7
- <script type="text/javascript" charset="utf-8" src="/javascripts/rmce_uploadr/jquery-1.4.2.min.js"></script>
8
- <script type="text/javascript" charset="utf-8" src="/javascripts/rmce_uploadr.js"></script>
6
+ <style type="text/css" media="screen">
7
+ #upload_form, #main_area {
8
+ margin-bottom: 1em;
9
+ }
10
+ .image {
11
+ float: left;
12
+ background-color: white;
13
+ border: 1px solid #ccc;
14
+ padding: 5px;
15
+ margin: 10px;
16
+ cursor: pointer;
17
+ }
18
+ .image:hover, .image:focus {
19
+ background-color: #eee;
20
+ }
21
+ img.srcimage {
22
+ padding: 0;
23
+ margin: 0 0 .2 0;
24
+ border: 1px solid #aaa;
25
+ }
26
+ .quiet { color: #ccc; }
27
+ .small { font-size: 11px; }
28
+ .clearfix {
29
+ clear: both;
30
+ overflow: hidden;
31
+ height: 0;
32
+ }
33
+ </style>
9
34
  </head>
10
- <div id="upload_form">
11
- <form action="/rmce_uploadr/images" method="post" enctype="multipart/form-data">
12
- <input type="file" name="image[data]"/>
13
- <input type="submit" value="Upload"/>
14
- </form>
15
- </div>
16
- <%= yield %>
35
+ <body>
36
+ <div id="upload_form">
37
+ <form action="/rmce_uploadr/images" method="post" enctype="multipart/form-data">
38
+ <input type="file" name="image[data]"/>
39
+ <input type="submit" value="Upload"/>
40
+ </form>
41
+ </div>
17
42
 
18
- <script type="text/javascript" charset="utf-8">
19
- $(function(){
20
- $("[data-src-original]").click(function(){
21
- var editor = tinyMCEPopup.editor;
43
+ <div id="main_area">
44
+ <%= yield %>
45
+ </div>
22
46
 
23
- // Fixes crash in Safari
24
- if (tinymce.isWebKit) { editor.getWin().focus(); }
25
-
26
- var imgParams = {
27
- src: $(this).attr('data-src-original')
28
- };
29
-
30
- var original = editor.selection.getNode();
31
- if (original && original.nodeName == 'IMG') {
32
- editor.dom.setAttribs(original, imgParams);
33
- } else {
34
- editor.execCommand('mceInsertContent', false, '<img id="__mce_tmp" />', {skip_undo : 1});
35
- editor.dom.setAttribs('__mce_tmp', imgParams);
36
- editor.dom.setAttrib('__mce_tmp', 'id', '');
37
- editor.undoManager.add();
38
- }
39
-
40
- tinyMCEPopup.close();
41
- });
42
- });
43
- </script>
47
+ <script type="text/javascript" charset="utf-8">
48
+ var uploadrCdnHost = "<%= settings.cdn_host %>";
49
+ </script>
50
+
51
+ <script type="text/javascript" src="/javascripts/tiny_mce/tiny_mce_popup.js"></script>
52
+ <script type="text/javascript" src="/javascripts/rmce_uploadr/jquery-1.4.2.min.js"></script>
53
+ <script type="text/javascript" src="/javascripts/rmce_uploadr.js"></script>
54
+ </body>
44
55
  </html>
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rmce_uploadr}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Vagin"]
@@ -52,7 +52,6 @@ Gem::Specification.new do |s|
52
52
  "examples/rails/db/migrate/20100417132216_create_posts.rb",
53
53
  "examples/rails/db/schema.rb",
54
54
  "examples/rails/db/seeds.rb",
55
- "examples/rails/doc/README_FOR_APP",
56
55
  "examples/rails/public/404.html",
57
56
  "examples/rails/public/422.html",
58
57
  "examples/rails/public/500.html",
@@ -327,6 +326,7 @@ Gem::Specification.new do |s|
327
326
  "examples/shared/uploads/.gitignore",
328
327
  "examples/sinatra/.bundle/config",
329
328
  "examples/sinatra/Gemfile",
329
+ "examples/sinatra/README",
330
330
  "examples/sinatra/app/post.rb",
331
331
  "examples/sinatra/app/posts_controller.rb",
332
332
  "examples/sinatra/boot.rb",
@@ -603,9 +603,11 @@ Gem::Specification.new do |s|
603
603
  "spec/core_ext_spec.rb",
604
604
  "spec/image_spec.rb",
605
605
  "spec/images_controller_spec.rb",
606
+ "spec/layout_spec.rb",
606
607
  "spec/rcov.opts",
607
608
  "spec/spec.opts",
608
- "spec/spec_helper.rb"
609
+ "spec/spec_helper.rb",
610
+ "spec/test.sqlite3"
609
611
  ]
610
612
  s.homepage = %q{http://github.com/crhym3/rmce_uploadr}
611
613
  s.rdoc_options = ["--charset=UTF-8"]
@@ -617,6 +619,7 @@ Gem::Specification.new do |s|
617
619
  "spec/core_ext_spec.rb",
618
620
  "spec/image_spec.rb",
619
621
  "spec/images_controller_spec.rb",
622
+ "spec/layout_spec.rb",
620
623
  "spec/spec_helper.rb",
621
624
  "examples/rails/app/controllers/application_controller.rb",
622
625
  "examples/rails/app/controllers/posts_controller.rb",
@@ -644,7 +647,8 @@ Gem::Specification.new do |s|
644
647
  "examples/sinatra/app/post.rb",
645
648
  "examples/sinatra/app/posts_controller.rb",
646
649
  "examples/sinatra/boot.rb",
647
- "examples/sinatra/scripts/console.rb"
650
+ "examples/sinatra/scripts/console.rb",
651
+ "spec/test.sqlite3"
648
652
  ]
649
653
 
650
654
  if s.respond_to? :specification_version then
@@ -656,17 +660,20 @@ Gem::Specification.new do |s|
656
660
  s.add_runtime_dependency(%q<activerecord>, [">= 2.3.4"])
657
661
  s.add_runtime_dependency(%q<paperclip>, [">= 2.3.1.1"])
658
662
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
663
+ s.add_development_dependency(%q<rack-test>, [">= 0.5.3"])
659
664
  else
660
665
  s.add_dependency(%q<sinatra>, [">= 1.0"])
661
666
  s.add_dependency(%q<activerecord>, [">= 2.3.4"])
662
667
  s.add_dependency(%q<paperclip>, [">= 2.3.1.1"])
663
668
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
669
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
664
670
  end
665
671
  else
666
672
  s.add_dependency(%q<sinatra>, [">= 1.0"])
667
673
  s.add_dependency(%q<activerecord>, [">= 2.3.4"])
668
674
  s.add_dependency(%q<paperclip>, [">= 2.3.1.1"])
669
675
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
676
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
670
677
  end
671
678
  end
672
679
 
@@ -1,5 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RMceUploadr::App do
4
- it "should work"
4
+ before(:each) do
5
+ RMceUploadr.stub!(:dbconf=).and_return(true)
6
+ end
7
+
8
+ describe "settings" do
9
+ it "should set cdn_host" do
10
+ RMceUploadr::App.should_receive(:set).with(:cdn_host, "http://cdn.host.com/")
11
+ RMceUploadr::App.new do |conf|
12
+ conf.settings.set :cdn_host, "http://cdn.host.com/"
13
+ end
14
+ end
15
+
16
+ it "should have static option enabled" do
17
+ RMceUploadr::App.static.should be_true
18
+ end
19
+
20
+ it "should have set app root path" do
21
+ RMceUploadr::App.root.should =~ /.*\/lib\/rmce_uploadr$/
22
+ end
23
+
24
+ it "should have set a public dir" do
25
+ RMceUploadr::App.public.should =~ /.*\/lib\/rmce_uploadr\/public$/
26
+ end
27
+
28
+ it "should have set views dir" do
29
+ RMceUploadr::App.views.should =~ /.*\/lib\/rmce_uploadr\/views$/
30
+ end
31
+
32
+ it "should call main module's dbconf= method" do
33
+ RMceUploadr.should_receive(:dbconf=).with({:adapter => 'myadapter', :database => 'mydb'}).and_return(true)
34
+ RMceUploadr::App.new do |app|
35
+ app.dbconf = {:adapter => 'myadapter', :database => 'mydb'}
36
+ end
37
+ end
38
+ end
5
39
  end
@@ -1,13 +1,65 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RMceUploadr::Image do
3
+ describe RMceUploadr::Image do
4
4
  before(:each) do
5
- RMceUploadr::Image.stub!(:columns).and_return([])
6
- @image = RMceUploadr::Image.new
5
+ @tmpfile = mock("uploaded image file")
6
+ @image = RMceUploadr::Image.new(:data => @tmpfile, :tempfile => "temp file path")
7
+ @image.stub!(:data).and_return(@tmpfile)
8
+ @image.stub!(:save_attached_files).and_return(true)
7
9
  end
8
10
 
9
11
  it "should have :data- methods" do
10
12
  @image.should respond_to(:data)
11
13
  @image.should respond_to(:data=)
12
- end
14
+ end
15
+
16
+ it "should return its dimensions" do
17
+ @image.stub!(:width).and_return(23)
18
+ @image.stub!(:height).and_return(45)
19
+ @image.geometry.should == "23x45"
20
+ end
21
+
22
+ it "should return empty string if either width or height isn't set" do
23
+ @image.geometry.should be_empty
24
+
25
+ @image.stub!(:width).and_return(10)
26
+ @image.geometry.should be_empty
27
+
28
+ @image.stub!(:width).and_return(nil)
29
+ @image.stub!(:height).and_return(10)
30
+ @image.geometry.should be_empty
31
+ end
32
+
33
+ it "should return image file size in human format" do
34
+ @image.stub!(:data_file_size).and_return(1000)
35
+ @image.size_in_bytes.should == "1000B"
36
+
37
+ @image.stub!(:data_file_size).and_return(10000)
38
+ @image.size_in_bytes.should == "10Kb"
39
+
40
+ @image.stub!(:data_file_size).and_return(2000000)
41
+ @image.size_in_bytes.should == "2Mb"
42
+
43
+ @image.stub!(:data_file_size).and_return(30000000000)
44
+ @image.size_in_bytes.should == "28Gb"
45
+ end
46
+
47
+ describe "saving an object" do
48
+ before(:each) do
49
+ @geometry = mock("geometry", :width => 10, :height => "11")
50
+ Paperclip::Geometry.stub!(:from_file).and_return(@geometry)
51
+ end
52
+
53
+ it "should have a callback to calculate original image geometry" do
54
+ @image.should_receive(:update_image_geometry)
55
+ @image.save
56
+ end
57
+
58
+ it "should use Paperclip::Geometry to calculate width and height" do
59
+ Paperclip::Geometry.should_receive(:from_file).with("temp file path")
60
+ @image.should_receive(:width=).with(@geometry.width.to_i)
61
+ @image.should_receive(:height=).with(@geometry.height.to_i)
62
+ @image.save
63
+ end
64
+ end
13
65
  end
@@ -1,5 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sinatra::RMceUploadr::ImagesController, :type => :controller do
4
- it "should work"
4
+ before(:each) do
5
+ @image_data = mock("image data", :url => "image url")
6
+ @image = mock("image", :data => @image_data, :size_in_bytes => "10Kb", :geometry => "10x11")
7
+
8
+ RMceUploadr::Image.stub!(:find).and_return(@image)
9
+ RMceUploadr::Image.stub!(:all).and_return([@image])
10
+ end
11
+
12
+ it "should find all images" do
13
+ RMceUploadr::Image.should_receive(:all)
14
+ get '/rmce_uploadr/images'
15
+ end
16
+
17
+ it "should render found images" do
18
+ get '/rmce_uploadr/images'
19
+ last_response.body.gsub(/[\n\r]/, '').should =~ /<img .*src="image url" .*data-src-original="image url"/
20
+ end
21
+
22
+ it "should display image size and geometry" do
23
+ get '/rmce_uploadr/images'
24
+ last_response.body.should =~ /<span .*>#{@image.size_in_bytes}, #{@image.geometry}/
25
+ end
26
+
27
+ it "should say something of no images found" do
28
+ RMceUploadr::Image.stub!(:all).and_return([])
29
+ get '/rmce_uploadr/images'
30
+ last_response.body.should =~ /no images found/i
31
+ end
5
32
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Main layout", :type => :controller do
4
+ before(:all) do
5
+ RMceUploadr::Image.stub!(:all).and_return([])
6
+ app.set :cdn_host, "http://mycdn.host.com/"
7
+ end
8
+
9
+ it "should set javascript global cdn host variable" do
10
+ get '/rmce_uploadr/images'
11
+ last_response.body.should =~ /var +uploadrCdnHost += +["']http:\/\/mycdn\.host\.com\/["'];/
12
+ end
13
+ end
@@ -15,19 +15,24 @@ require 'spec/autorun'
15
15
 
16
16
  module RMceUploadr; module Test; module Controllers
17
17
  def app
18
- @app ||= ::RMCEUploadr::App
18
+ @app ||= ::RMceUploadr::App
19
19
  end
20
20
  end; end; end
21
21
 
22
22
  Spec::Runner.configure do |config|
23
23
  Rake.application = Rake::Application.new
24
- # load File.join(File.dirname(__FILE__), '..', 'Rakefile')
24
+
25
+ # before all tests begin
25
26
  config.before(:all) do
26
- # before :all tests config
27
+ test_db = File.join(File.dirname(__FILE__), 'dummy.sqlite3')
28
+ FileUtils.cp File.join(File.dirname(__FILE__), 'test.sqlite3'), test_db
29
+
30
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => test_db)
27
31
  end
28
32
 
33
+ # after :all tests end
29
34
  config.after(:all) do
30
- # after :all tests config
35
+ FileUtils.rm File.join(File.dirname(__FILE__), 'dummy.sqlite3')
31
36
  end
32
37
 
33
38
  config.include(Rack::Test::Methods, RMceUploadr::Test::Controllers, :type => :controller)
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Vagin
@@ -73,6 +73,20 @@ dependencies:
73
73
  version: 1.2.9
74
74
  type: :development
75
75
  version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: rack-test
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 5
86
+ - 3
87
+ version: 0.5.3
88
+ type: :development
89
+ version_requirements: *id005
76
90
  description: Written in Ruby, using Sinatra + ActiveRecord and Paperclip
77
91
  email: alex@cloudware.it
78
92
  executables: []
@@ -118,7 +132,6 @@ files:
118
132
  - examples/rails/db/migrate/20100417132216_create_posts.rb
119
133
  - examples/rails/db/schema.rb
120
134
  - examples/rails/db/seeds.rb
121
- - examples/rails/doc/README_FOR_APP
122
135
  - examples/rails/public/404.html
123
136
  - examples/rails/public/422.html
124
137
  - examples/rails/public/500.html
@@ -393,6 +406,7 @@ files:
393
406
  - examples/shared/uploads/.gitignore
394
407
  - examples/sinatra/.bundle/config
395
408
  - examples/sinatra/Gemfile
409
+ - examples/sinatra/README
396
410
  - examples/sinatra/app/post.rb
397
411
  - examples/sinatra/app/posts_controller.rb
398
412
  - examples/sinatra/boot.rb
@@ -669,9 +683,11 @@ files:
669
683
  - spec/core_ext_spec.rb
670
684
  - spec/image_spec.rb
671
685
  - spec/images_controller_spec.rb
686
+ - spec/layout_spec.rb
672
687
  - spec/rcov.opts
673
688
  - spec/spec.opts
674
689
  - spec/spec_helper.rb
690
+ - spec/test.sqlite3
675
691
  has_rdoc: true
676
692
  homepage: http://github.com/crhym3/rmce_uploadr
677
693
  licenses: []
@@ -707,6 +723,7 @@ test_files:
707
723
  - spec/core_ext_spec.rb
708
724
  - spec/image_spec.rb
709
725
  - spec/images_controller_spec.rb
726
+ - spec/layout_spec.rb
710
727
  - spec/spec_helper.rb
711
728
  - examples/rails/app/controllers/application_controller.rb
712
729
  - examples/rails/app/controllers/posts_controller.rb
@@ -735,3 +752,4 @@ test_files:
735
752
  - examples/sinatra/app/posts_controller.rb
736
753
  - examples/sinatra/boot.rb
737
754
  - examples/sinatra/scripts/console.rb
755
+ - spec/test.sqlite3
@@ -1,2 +0,0 @@
1
- Use this README file to introduce your application and point to useful places in the API for learning more.
2
- Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.