rails_blog_engine 0.0.1

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.
Files changed (54) hide show
  1. data/BOOTSTRAP-LICENSE.txt +13 -0
  2. data/MIT-LICENSE +20 -0
  3. data/PYGMENTS-LICENSE.txt +28 -0
  4. data/RAILS-LICENSE.txt +22 -0
  5. data/README.md +165 -0
  6. data/Rakefile +79 -0
  7. data/app/assets/javascripts/rails_blog_engine/comments.js +2 -0
  8. data/app/assets/javascripts/rails_blog_engine/posts.js +3 -0
  9. data/app/assets/javascripts/rails_blog_engine.js +3 -0
  10. data/app/assets/stylesheets/rails_blog_engine/bootstrap_extracts.css.scss +252 -0
  11. data/app/assets/stylesheets/rails_blog_engine/code.css.scss +71 -0
  12. data/app/assets/stylesheets/rails_blog_engine/comments.css.scss +29 -0
  13. data/app/assets/stylesheets/rails_blog_engine/posts.css.scss +46 -0
  14. data/app/assets/stylesheets/rails_blog_engine/simple_form.css.scss +70 -0
  15. data/app/assets/stylesheets/rails_blog_engine.css +6 -0
  16. data/app/controllers/rails_blog_engine/application_controller.rb +26 -0
  17. data/app/controllers/rails_blog_engine/comments_controller.rb +47 -0
  18. data/app/controllers/rails_blog_engine/posts_controller.rb +67 -0
  19. data/app/helpers/rails_blog_engine/application_helper.rb +52 -0
  20. data/app/helpers/rails_blog_engine/comments_helper.rb +4 -0
  21. data/app/helpers/rails_blog_engine/posts_helper.rb +13 -0
  22. data/app/models/rails_blog_engine/comment.rb +74 -0
  23. data/app/models/rails_blog_engine/post.rb +73 -0
  24. data/app/views/rails_blog_engine/comments/_comment.html.haml +10 -0
  25. data/app/views/rails_blog_engine/comments/_form.html.haml +6 -0
  26. data/app/views/rails_blog_engine/comments/_tools.html.haml +10 -0
  27. data/app/views/rails_blog_engine/comments/new.html.haml +6 -0
  28. data/app/views/rails_blog_engine/posts/_comments_section.html.haml +11 -0
  29. data/app/views/rails_blog_engine/posts/_form.html.haml +7 -0
  30. data/app/views/rails_blog_engine/posts/_post.html.haml +20 -0
  31. data/app/views/rails_blog_engine/posts/_tools.html.haml +2 -0
  32. data/app/views/rails_blog_engine/posts/edit.html.haml +5 -0
  33. data/app/views/rails_blog_engine/posts/index.atom.builder +14 -0
  34. data/app/views/rails_blog_engine/posts/index.html.haml +15 -0
  35. data/app/views/rails_blog_engine/posts/new.html.haml +5 -0
  36. data/app/views/rails_blog_engine/posts/show.html.haml +8 -0
  37. data/config/locales/rails_blog_engine.en.yml +15 -0
  38. data/config/locales/simple_form.en.yml +24 -0
  39. data/config/routes.rb +24 -0
  40. data/db/migrate/20110912153527_create_rails_blog_engine_posts.rb +10 -0
  41. data/db/migrate/20110913190319_add_fields_to_rails_blog_engine_post.rb +12 -0
  42. data/db/migrate/20111125111958_create_rails_blog_engine_comments.rb +21 -0
  43. data/lib/generators/rails_blog_engine/install/USAGE +11 -0
  44. data/lib/generators/rails_blog_engine/install/install_generator.rb +51 -0
  45. data/lib/generators/rails_blog_engine/install/templates/rails_blog_engine.rb +13 -0
  46. data/lib/rails_blog_engine/ability.rb +16 -0
  47. data/lib/rails_blog_engine/engine.rb +5 -0
  48. data/lib/rails_blog_engine/filters/base.rb +17 -0
  49. data/lib/rails_blog_engine/filters/code.rb +21 -0
  50. data/lib/rails_blog_engine/filters.rb +53 -0
  51. data/lib/rails_blog_engine/version.rb +3 -0
  52. data/lib/rails_blog_engine.rb +18 -0
  53. data/lib/tasks/rails_blog_engine_tasks.rake +4 -0
  54. metadata +384 -0
@@ -0,0 +1,24 @@
1
+ en:
2
+ simple_form:
3
+ "yes": 'Yes'
4
+ "no": 'No'
5
+ required:
6
+ text: 'required'
7
+ mark: '*'
8
+ # You can uncomment the line below if you need to overwrite the whole required html.
9
+ # When using html, text and mark won't be used.
10
+ # html: '<abbr title="required">*</abbr>'
11
+ error_notification:
12
+ default_message: "Some errors were found, please take a look:"
13
+ # Labels and hints examples
14
+ # labels:
15
+ # password: 'Password'
16
+ # user:
17
+ # new:
18
+ # email: 'E-mail para efetuar o sign in.'
19
+ # edit:
20
+ # email: 'E-mail.'
21
+ # hints:
22
+ # username: 'User name to sign in.'
23
+ # password: 'No special characters, please.'
24
+
data/config/routes.rb ADDED
@@ -0,0 +1,24 @@
1
+ RailsBlogEngine::Engine.routes.draw do
2
+ # Atom feed.
3
+ get 'posts.:format' => 'posts#index', :constraints => { :format => 'atom' }
4
+
5
+ # Extra pages.
6
+ get 'page/:page' => 'posts#index', :constraints => { :page => /\d+/ }
7
+
8
+ # Home page.
9
+ root :to => 'posts#index'
10
+
11
+ # Public article pages.
12
+ get(':year/:month/:day/:permalink' => 'posts#show',
13
+ :constraints => { :year => /\d{4,}/, :month => /\d\d/, :day => /\d\d/ })
14
+
15
+ # A regular resource interface for everything else.
16
+ resources :posts, :except => [:index, :show, :delete] do
17
+ resources :comments, :only => [:create] do
18
+ member do
19
+ post :mark_as_ham
20
+ post :mark_as_spam
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ class CreateRailsBlogEnginePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :rails_blog_engine_posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ class AddFieldsToRailsBlogEnginePost < ActiveRecord::Migration
2
+ def change
3
+ add_column :rails_blog_engine_posts, :state, :string
4
+ add_column :rails_blog_engine_posts, :published_at, :datetime
5
+ add_column :rails_blog_engine_posts, :permalink, :string
6
+ add_column :rails_blog_engine_posts, :author_id, :integer
7
+ add_column :rails_blog_engine_posts, :author_type, :string
8
+ add_column :rails_blog_engine_posts, :author_byline, :string
9
+
10
+ add_index :rails_blog_engine_posts, :permalink
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ class CreateRailsBlogEngineComments < ActiveRecord::Migration
2
+ def change
3
+ create_table :rails_blog_engine_comments do |t|
4
+ t.references :post
5
+ t.string :author_byline
6
+ t.string :author_email
7
+ t.string :author_url
8
+ t.string :author_ip
9
+ t.string :author_user_agent
10
+ t.boolean :author_can_post
11
+ t.string :referrer
12
+ t.string :state
13
+ t.text :body
14
+
15
+ t.timestamps
16
+ end
17
+
18
+ add_index :rails_blog_engine_comments, :post_id
19
+ add_index :rails_blog_engine_comments, :author_email
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Install rails_blog_engine
3
+
4
+ Example:
5
+ rails generate rails_blog_engine:install
6
+
7
+ This will create:
8
+ config/initializers/rails_blog_engine.rb
9
+ config/locales/rails_blog_engine.*.yml
10
+ config/routes.rb (A new route for "/blog")
11
+ db/migrate/*.rb
@@ -0,0 +1,51 @@
1
+ class RailsBlogEngine::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_initializer_file
5
+ copy_file "rails_blog_engine.rb", "config/initializers/rails_blog_engine.rb"
6
+ end
7
+
8
+ def add_route
9
+ route 'mount RailsBlogEngine::Engine => "/blog"'
10
+ end
11
+
12
+ def copy_migrations
13
+ # Normally, we'd just call 'rake
14
+ # "rails_blog_engine:install:migrations"' to do this for us, but it's
15
+ # much more difficult to test. So we roll our own version.
16
+ copy_matching_files_from_gem('db/migrate/*.rb')
17
+ end
18
+
19
+ def copy_locales
20
+ copy_matching_files_from_gem('config/locales/rails_blog_engine.*.yml')
21
+ end
22
+
23
+ def register_javascripts
24
+ in_root do
25
+ append_file("app/assets/javascripts/application.js",
26
+ "//= require rails_blog_engine\n",
27
+ :before => /^\/\/= require/)
28
+ end
29
+ end
30
+
31
+ def register_stylesheets
32
+ in_root do
33
+ inject_into_file("app/assets/stylesheets/application.css",
34
+ " *= require rails_blog_engine\n",
35
+ :before => /^\*\//)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def gem_path(path)
42
+ File.expand_path("../../../../../#{path}", __FILE__)
43
+ end
44
+
45
+ def copy_matching_files_from_gem(pattern)
46
+ matches = gem_path(pattern)
47
+ Dir[matches].each do |path|
48
+ copy_file path, "#{File.dirname(pattern)}/#{File.basename(path)}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,13 @@
1
+ # Configure RailsBlogEngine here.
2
+
3
+ # If you want to activate the built-in spam filter, visit http://akismet.com/
4
+ # and sign up for an API key.
5
+ Rails.application.config.rakismet.key = ENV['RAKISMET_KEY']
6
+
7
+ # The URL of your blog, for use by Akismet's spam filter.
8
+ Rails.application.config.rakismet.url = ENV['RAKISMET_URL']
9
+
10
+ # Disable the Akismet middleware, because it isn't needed by
11
+ # rails_blog_engine. If you use Akismet elsewhere in your application, you
12
+ # may to set this back to true.
13
+ Rails.application.config.rakismet.use_middleware = false
@@ -0,0 +1,16 @@
1
+ module RailsBlogEngine
2
+ module Ability
3
+ def can_read_blog
4
+ can :read, RailsBlogEngine::Post
5
+ can [:read, :create], RailsBlogEngine::Comment
6
+ end
7
+
8
+ def can_manage_blog
9
+ alias_action :mark_as_spam, :to => :update
10
+ alias_action :mark_as_ham, :to => :update
11
+
12
+ can :manage, RailsBlogEngine::Post
13
+ can :update, RailsBlogEngine::Comment
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module RailsBlogEngine
2
+ class Engine < Rails::Engine
3
+ isolate_namespace RailsBlogEngine
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module RailsBlogEngine::Filters
2
+ # A modular text filter that is applied to blog text before markdown
3
+ # processing.
4
+ class Base
5
+ # Override this method to transform +text+, using any supplied
6
+ # +arguments+.
7
+ def process(text, arguments)
8
+ raise "Please override #{self.class.name}#process"
9
+ end
10
+
11
+ class << self
12
+ def register_filter(name)
13
+ RailsBlogEngine::Filters.register_filter(name, self)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # This is a strictly optional dependency.
2
+ begin
3
+ require "pygments"
4
+ rescue LoadError => e
5
+ # Optional dependency.
6
+ end
7
+
8
+ module RailsBlogEngine::Filters
9
+ # Syntax highlighting for code blocks.
10
+ class Code < Base
11
+ register_filter :code
12
+
13
+ def process(text, options)
14
+ if defined?(Pygments)
15
+ Pygments.new(text, options[:lang] || 'ruby').colorize
16
+ else
17
+ raise "Install pygments-gem to enable syntax highlighting"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,53 @@
1
+ module RailsBlogEngine::Filters
2
+
3
+ # :nodoc: All registered filters.
4
+ FILTERS = {}
5
+
6
+ # Register a filter class to be used by #apply_all_to.
7
+ def self.register_filter(name, filter_class)
8
+ FILTERS[name] = filter_class.new
9
+ end
10
+
11
+ # Look up a registered filter class. Raises an error if the filter
12
+ # can't be found.
13
+ def self.find(name)
14
+ FILTERS[name] or raise "Text filter not installed: #{name}"
15
+ end
16
+
17
+ # Apply all registered filters to the specified text.
18
+ def self.apply_all_to(text)
19
+ text.gsub(/<(filter|macro|typo):([_a-zA-z0-9]+)([^>]*)\/>/m) do
20
+ trap_filter_errors do
21
+ find($2.to_sym).process(nil, parse_arguments($3))
22
+ end
23
+ end.gsub(/<(filter|macro|typo):([_a-zA-z0-9]+)([^>]*)>(.*?)<\/\1:\2>/m) do
24
+ trap_filter_errors do
25
+ find($2.to_sym).process($4, parse_arguments($3))
26
+ end
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ # :nodoc: Trap a filter's errors and return an error message.
33
+ def self.trap_filter_errors
34
+ yield rescue "<p><strong>#{$!.to_s}</strong></p>"
35
+ end
36
+
37
+ # :nodoc: Parse a filter arugment string.
38
+ def self.parse_arguments(arg_string)
39
+ unparsed = arg_string.strip
40
+ pattern = /\A([_a-zA-z0-9]+)\s*=\s*("([^"]*)"|'([^']*)')\s*(.*)\z/m
41
+ args = {}
42
+ until unparsed == ''
43
+ m = unparsed.match(pattern)
44
+ m or raise "Can't parse filter arguments: {{#{arg_string}}}"
45
+ args[m[1].to_sym] = m[3] || m[4]
46
+ unparsed = m[5]
47
+ end
48
+ args
49
+ end
50
+ end
51
+
52
+ require 'rails_blog_engine/filters/base'
53
+ require 'rails_blog_engine/filters/code'
@@ -0,0 +1,3 @@
1
+ module RailsBlogEngine
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ # Manually require gems, because Bundler won't auto-require them when we're
2
+ # running inside a gem.
3
+ require "state_machine"
4
+ require "cancan"
5
+ require "jquery-rails"
6
+ require "haml"
7
+ require "rdiscount"
8
+ require "sanitize"
9
+ require "simple_form"
10
+ require "kaminari"
11
+ require "rakismet"
12
+
13
+ require "rails_blog_engine/engine"
14
+ require "rails_blog_engine/ability"
15
+ require "rails_blog_engine/filters"
16
+
17
+ module RailsBlogEngine
18
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_blog_engine do
3
+ # # Task goes here
4
+ # end