diff --git a/.gitignore b/.gitignore index 4aa91a6..23c7dd6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ /tmp *.swp + +/public/uploads/* diff --git a/Gemfile b/Gemfile index a8303f3..55cbe8d 100644 --- a/Gemfile +++ b/Gemfile @@ -40,3 +40,5 @@ gem 'jquery-rails' gem "redcarpet" gem "simple_form" gem 'database_cleaner' +gem "mini_magick" +gem 'carrierwave-mongoid' diff --git a/Gemfile.lock b/Gemfile.lock index 4c0fbcf..6f02b4b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,6 +33,12 @@ GEM bson_ext (1.6.4) bson (~> 1.6.4) builder (3.0.0) + carrierwave (0.6.2) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + carrierwave-mongoid (0.2.1) + carrierwave (~> 0.6.1) + mongoid (~> 2.1) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -57,6 +63,8 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) + mini_magick (3.4) + subexec (~> 0.2.1) mongo (1.6.2) bson (~> 1.6.2) mongoid (2.4.11) @@ -116,6 +124,7 @@ GEM hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + subexec (0.2.2) thor (0.15.3) tilt (1.3.3) treetop (1.4.10) @@ -131,9 +140,11 @@ PLATFORMS DEPENDENCIES bson_ext + carrierwave-mongoid coffee-rails (~> 3.2.1) database_cleaner jquery-rails + mini_magick mongoid rails (= 3.2.6) redcarpet diff --git a/app/assets/images/rss.png b/app/assets/images/rss.png new file mode 100644 index 0000000..77eaa99 Binary files /dev/null and b/app/assets/images/rss.png differ diff --git a/app/assets/javascripts/admin/posts.js.coffee b/app/assets/javascripts/admin/posts.js.coffee index d63051a..8308138 100644 --- a/app/assets/javascripts/admin/posts.js.coffee +++ b/app/assets/javascripts/admin/posts.js.coffee @@ -23,3 +23,14 @@ $(document).ready -> $.post $(this).attr('url'), text: content.val(), (data)-> preview.html(data) + $('a#upload_photo').click -> + $('input[type=file]').show().focus().click().hide() + + opt = + type: 'POST' + url: "/photos" + success: (data,status,xhr)-> + insertAtCaret('post_content', data) + + + $('input[type=file]').fileUpload opt diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9097d83..077f5c5 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,4 +12,5 @@ // //= require jquery //= require jquery_ujs +//= require 'jquery.html5-fileupload' //= require_tree . diff --git a/app/assets/javascripts/home.js.coffee b/app/assets/javascripts/home.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/home.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/insert.js b/app/assets/javascripts/insert.js new file mode 100644 index 0000000..209ff8b --- /dev/null +++ b/app/assets/javascripts/insert.js @@ -0,0 +1,34 @@ +function insertAtCaret(areaId,text) { + var txtarea = document.getElementById(areaId); + var scrollPos = txtarea.scrollTop; + var strPos = 0; + var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? + "ff" : (document.selection ? "ie" : false ) ); + if (br == "ie") { + txtarea.focus(); + var range = document.selection.createRange(); + range.moveStart ('character', -txtarea.value.length); + strPos = range.text.length; + } + else if (br == "ff") strPos = txtarea.selectionStart; + + var front = (txtarea.value).substring(0,strPos); + var back = (txtarea.value).substring(strPos,txtarea.value.length); + txtarea.value=front+text+back; + strPos = strPos + text.length; + if (br == "ie") { + txtarea.focus(); + var range = document.selection.createRange(); + range.moveStart ('character', -txtarea.value.length); + range.moveStart ('character', strPos); + range.moveEnd ('character', 0); + range.select(); + } + else if (br == "ff") { + txtarea.selectionStart = strPos; + txtarea.selectionEnd = strPos; + txtarea.focus(); + } + txtarea.scrollTop = scrollPos; +} + diff --git a/app/assets/javascripts/photos.js.coffee b/app/assets/javascripts/photos.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/photos.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/admin/posts.css.scss b/app/assets/stylesheets/admin/posts.css.scss index 8470b37..246a86a 100644 --- a/app/assets/stylesheets/admin/posts.css.scss +++ b/app/assets/stylesheets/admin/posts.css.scss @@ -59,3 +59,6 @@ div.preview { display: none; } +#upload_photo { + float: right; +} diff --git a/app/assets/stylesheets/blogs.css.scss b/app/assets/stylesheets/blogs.css.scss index 8c4f941..e0e078d 100644 --- a/app/assets/stylesheets/blogs.css.scss +++ b/app/assets/stylesheets/blogs.css.scss @@ -2,6 +2,11 @@ // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ +div.blogs { + width: 700px; + float: left; +} + div.blog { background: url('bg_fn_blog_corner.png') no-repeat; padding: 2em 19px; @@ -20,7 +25,6 @@ div.blog { } strong { font-size: 10px; - line-height: 40px; margin-left: 1em; display: none; } diff --git a/app/assets/stylesheets/home.css.scss b/app/assets/stylesheets/home.css.scss new file mode 100644 index 0000000..f0ddc68 --- /dev/null +++ b/app/assets/stylesheets/home.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/photos.css.scss b/app/assets/stylesheets/photos.css.scss new file mode 100644 index 0000000..1a3e082 --- /dev/null +++ b/app/assets/stylesheets/photos.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the photos controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/slide.css.scss b/app/assets/stylesheets/slide.css.scss new file mode 100644 index 0000000..0adb1db --- /dev/null +++ b/app/assets/stylesheets/slide.css.scss @@ -0,0 +1,25 @@ +div.slide { + display: block; + float: left; + width: 400px; + .subscribe { + margin-bottom: 19px; + padding: 9px 0 16px 9px; + border: 1px solid #CCC; + border-radius: 3px; + background-color: #E9F2F5; + clear: both; + .subscribe_descrip { + width: 290px; + display: inline-block; + line-height: 20px; + font-size: 16px; + } + a { + img { + float: right; + margin-right: 20px; + } + } + } +} diff --git a/app/controllers/admin/posts_controller.rb b/app/controllers/admin/posts_controller.rb index 65e1143..8d46f67 100644 --- a/app/controllers/admin/posts_controller.rb +++ b/app/controllers/admin/posts_controller.rb @@ -28,7 +28,8 @@ class Admin::PostsController < ApplicationController def preview text = params[:text] || "" - md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink=>true) + rd = Redcarpet::Render::HTML.new(:hard_wrap=>true) + md = Redcarpet::Markdown.new(rd, :autolink=>true) render :text => md.render(text) end end diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index eb5d7ce..4cc9505 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -9,6 +9,12 @@ class BlogsController < ApplicationController end end + def rss + @posts = Post.all.limit(10) + render :layout=>false + response.headers["Content-Type"] = "application/xml; charset=utf-8" + end + def show @post = Post.find(params[:id]) end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..95f2992 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,4 @@ +class HomeController < ApplicationController + def index + end +end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb new file mode 100644 index 0000000..f5be7f7 --- /dev/null +++ b/app/controllers/photos_controller.rb @@ -0,0 +1,12 @@ +class PhotosController < ApplicationController + def create + @photo = Photo.new + @photo.image = params["Filedata"] + @photo.save! + render :text=> md_url(@photo.image.url) + end + + def md_url(url) + "![](#{url})" + end +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/helpers/photos_helper.rb b/app/helpers/photos_helper.rb new file mode 100644 index 0000000..0a10d47 --- /dev/null +++ b/app/helpers/photos_helper.rb @@ -0,0 +1,2 @@ +module PhotosHelper +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..4915691 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,6 @@ +class Comment + include Mongoid::Document + include Mongoid::Timestamps + field :content, :type => String + validates :content, presence: true +end diff --git a/app/models/photo.rb b/app/models/photo.rb new file mode 100644 index 0000000..c4c8268 --- /dev/null +++ b/app/models/photo.rb @@ -0,0 +1,9 @@ +class Photo + include Mongoid::Document + include Mongoid::Timestamps + field :image + + attr_accessible :image + + mount_uploader :image, PhotoUploader +end diff --git a/app/models/post.rb b/app/models/post.rb index 33c8220..09325a6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -14,4 +14,10 @@ class Post validates :title, :presence=>true, :uniqueness=> true validates :content, :presence=>true, :length => { :minimum=> 30 } validates :type, :presence=>true, :inclusion => { :in => [ TECH, LIFE, CREATOR ] } + + def content_html + rd = Redcarpet::Render::HTML.new(:hard_wrap=>true) + md = Redcarpet::Markdown.new(rd, :autolink=>true) + md.render(self.content) + end end diff --git a/app/uploaders/photo_uploader.rb b/app/uploaders/photo_uploader.rb new file mode 100644 index 0000000..5288bd7 --- /dev/null +++ b/app/uploaders/photo_uploader.rb @@ -0,0 +1,55 @@ +# encoding: utf-8 + +class PhotoUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: + # include Sprockets::Helpers::RailsHelper + # include Sprockets::Helpers::IsolatedHelper + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + process :resize_to_limit => [680,nil] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process :scale => [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_white_list + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/admin/posts/_form.html.erb b/app/views/admin/posts/_form.html.erb index 6cd20c4..7067f1c 100644 --- a/app/views/admin/posts/_form.html.erb +++ b/app/views/admin/posts/_form.html.erb @@ -4,6 +4,8 @@
+为什么会有这里? +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 745cb95..df580d3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,10 +19,12 @@