Permalink
Browse files

first commit, extracted from working Teldra project and sanitized for…

… your protection
  • Loading branch information...
0 parents commit ad846852d344dbf3f64da28257be1f0f5172ef1b @joshsusser committed May 26, 2008
Showing with 16,076 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +3 −0 README
  3. +10 −0 Rakefile
  4. +67 −0 app/controllers/admin/articles_controller.rb
  5. +19 −0 app/controllers/admin/comments_controller.rb
  6. +7 −0 app/controllers/admin/panel_controller.rb
  7. +10 −0 app/controllers/application.rb
  8. +87 −0 app/controllers/blog_controller.rb
  9. +30 −0 app/controllers/sessions_controller.rb
  10. +11 −0 app/controllers/stylesheets_controller.rb
  11. +2 −0 app/helpers/admin/articles_helper.rb
  12. +2 −0 app/helpers/admin/panel_helper.rb
  13. +52 −0 app/helpers/application_helper.rb
  14. +43 −0 app/helpers/blog_helper.rb
  15. +2 −0 app/helpers/sessions_helper.rb
  16. +2 −0 app/helpers/stylesheets_helper.rb
  17. +143 −0 app/models/article.rb
  18. +26 −0 app/models/article_sweeper.rb
  19. +46 −0 app/models/comment.rb
  20. +3 −0 app/models/reject.rb
  21. +52 −0 app/models/tag.rb
  22. +42 −0 app/models/tagging.rb
  23. +86 −0 app/models/user.rb
  24. +16 −0 app/views/admin/articles/_form.html.erb
  25. +11 −0 app/views/admin/articles/edit.html.erb
  26. +32 −0 app/views/admin/articles/index.html.erb
  27. +10 −0 app/views/admin/articles/new.html.erb
  28. +32 −0 app/views/admin/articles/show.html.erb
  29. +15 −0 app/views/admin/comments/_comment.html.erb
  30. +6 −0 app/views/admin/comments/index.html.erb
  31. +12 −0 app/views/admin/panel/index.html.erb
  32. +12 −0 app/views/blog/_article.atom.builder
  33. +80 −0 app/views/blog/_article.html.erb
  34. +6 −0 app/views/blog/_article_list.html.erb
  35. +10 −0 app/views/blog/_comment.html.erb
  36. +5 −0 app/views/blog/index.atom.builder
  37. +6 −0 app/views/blog/index.html.erb
  38. +1 −0 app/views/blog/results.html.erb
  39. +3 −0 app/views/blog/show.html.erb
  40. +5 −0 app/views/blog/tag.atom.builder
  41. +10 −0 app/views/blog/tag.html.erb
  42. +5 −0 app/views/blog/tags.html.erb
  43. +21 −0 app/views/layouts/admin.html.erb
  44. +58 −0 app/views/layouts/blog.html.erb
  45. +12 −0 app/views/sessions/new.html.erb
  46. +573 −0 app/views/stylesheets/blog.ncss
  47. +108 −0 config/boot.rb
  48. +23 −0 config/database.yml.example
  49. +59 −0 config/environment.rb
  50. +18 −0 config/environments/development.rb
  51. +18 −0 config/environments/development_cached.rb
  52. +19 −0 config/environments/production.rb
  53. +22 −0 config/environments/test.rb
  54. +22 −0 config/geminstaller.yml
  55. +2 −0 config/initializers/dependencies.rb
  56. +10 −0 config/initializers/inflections.rb
  57. +5 −0 config/initializers/mime_types.rb
  58. +1 −0 config/initializers/site_settings.rb
  59. +37 −0 config/routes.rb
  60. +97 −0 db/migrate/001_initial_schema.rb
  61. +98 −0 db/schema.rb
  62. +2 −0 doc/README_FOR_APP
  63. +128 −0 lib/authenticated_system.rb
  64. +10 −0 lib/authenticated_test_helper.rb
  65. +25 −0 lib/tasks/teldra.rake
  66. +1 −0 log/.gitemptydir
  67. +40 −0 public/.htaccess
  68. +30 −0 public/404.html
  69. +30 −0 public/422.html
  70. +30 −0 public/500.html
  71. +10 −0 public/dispatch.cgi
  72. +24 −0 public/dispatch.fcgi
  73. +10 −0 public/dispatch.rb
  74. 0 public/favicon.ico
  75. BIN public/images/background.gif
  76. BIN public/images/delete.png
  77. BIN public/images/eye.png
  78. BIN public/images/feed16x16.png
  79. BIN public/images/gravatar.gif
  80. BIN public/images/header_shadow.gif
  81. BIN public/images/rails.png
  82. BIN public/images/spinner.gif
  83. +2 −0 public/javascripts/application.js
  84. +963 −0 public/javascripts/controls.js
  85. +972 −0 public/javascripts/dragdrop.js
  86. +1,120 −0 public/javascripts/effects.js
  87. +4,225 −0 public/javascripts/prototype.js
  88. +65 −0 public/javascripts/showdown-gui.js
  89. +421 −0 public/javascripts/showdown.js
  90. +140 −0 public/stylesheets/admin.css
  91. +609 −0 public/stylesheets/blog.css
  92. +3 −0 script/about
  93. +3 −0 script/console
  94. +3 −0 script/destroy
  95. +3 −0 script/generate
  96. +3 −0 script/performance/benchmarker
  97. +3 −0 script/performance/profiler
  98. +3 −0 script/performance/request
  99. +3 −0 script/plugin
  100. +3 −0 script/process/inspector
  101. +3 −0 script/process/reaper
  102. +3 −0 script/process/spawner
  103. +3 −0 script/runner
  104. +3 −0 script/server
  105. +102 −0 script/spec_server
  106. +20 −0 test/fixtures/basic/articles.yml
  107. +74 −0 test/fixtures/blog/articles.yml
  108. +32 −0 test/fixtures/blog/comments.yml
  109. +16 −0 test/fixtures/blog/taggings.yml
  110. +8 −0 test/fixtures/blog/tags.yml
  111. +40 −0 test/fixtures/tags/articles.yml
  112. +20 −0 test/fixtures/tags/taggings.yml
  113. +16 −0 test/fixtures/tags/tags.yml
  114. +15 −0 test/fixtures/user_authentication/users.yml
  115. +9 −0 test/fixtures/users.yml
  116. +79 −0 test/functional/admin/articles_controller_test.rb
  117. +38 −0 test/functional/admin/comments_controller_test.rb
  118. +8 −0 test/functional/admin/panel_controller_test.rb
  119. +188 −0 test/functional/blog_controller_test.rb
  120. +75 −0 test/functional/sessions_controller_test.rb
  121. +8 −0 test/functional/stylesheets_controller_test.rb
  122. +11 −0 test/more_helpers.rb
  123. +47 −0 test/test_helper.rb
  124. +218 −0 test/unit/article_test.rb
  125. +109 −0 test/unit/authenticated_user_test.rb
  126. +33 −0 test/unit/comment_test.rb
  127. +8 −0 test/unit/reject_test.rb
  128. +40 −0 test/unit/tag_test.rb
  129. +1 −0 test/unit/tagging_test.rb
  130. +9 −0 test/unit/user_test.rb
  131. +2 −0 vendor/plugins/fixture_scenarios/History.txt
  132. +20 −0 vendor/plugins/fixture_scenarios/MIT-LICENSE
  133. +123 −0 vendor/plugins/fixture_scenarios/README
  134. +22 −0 vendor/plugins/fixture_scenarios/Rakefile
  135. +5 −0 vendor/plugins/fixture_scenarios/init.rb
  136. +1 −0 vendor/plugins/fixture_scenarios/install.rb
  137. +268 −0 vendor/plugins/fixture_scenarios/lib/fixture_scenarios.rb
  138. +86 −0 vendor/plugins/fixture_scenarios/tasks/fixture_scenarios_tasks.rake
  139. +8 −0 vendor/plugins/fixture_scenarios/test/fixture_scenarios_test.rb
  140. +1 −0 vendor/plugins/fixture_scenarios/uninstall.rb
  141. +20 −0 vendor/plugins/simply_versioned/CHANGES
  142. +20 −0 vendor/plugins/simply_versioned/MIT-LICENSE
  143. +93 −0 vendor/plugins/simply_versioned/README
  144. +31 −0 vendor/plugins/simply_versioned/Rakefile
  145. +11 −0 ...ns/simply_versioned/generators/simply_versioned_migration/simply_versioned_migration_generator.rb
  146. +18 −0 vendor/plugins/simply_versioned/generators/simply_versioned_migration/templates/migration.rb
  147. +1 −0 vendor/plugins/simply_versioned/init.rb
  148. +1 −0 vendor/plugins/simply_versioned/install.rb
  149. +162 −0 vendor/plugins/simply_versioned/lib/simply_versioned.rb
  150. +47 −0 vendor/plugins/simply_versioned/lib/version.rb
  151. +122 −0 vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics.html
  152. +111 −0 vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord.html
  153. +149 −0 vendor/plugins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned.html
  154. +159 −0 ...ins/simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/ClassMethods.html
  155. +178 −0 .../simply_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/InstanceMethods.html
  156. +286 −0 ...ly_versioned/rdoc/classes/SoftwareHeretics/ActiveRecord/SimplyVersioned/VersionsProxyMethods.html
  157. +1 −0 vendor/plugins/simply_versioned/rdoc/created.rid
  158. +216 −0 vendor/plugins/simply_versioned/rdoc/files/README.html
  159. +112 −0 vendor/plugins/simply_versioned/rdoc/files/lib/simply_versioned_rb.html
  160. +112 −0 vendor/plugins/simply_versioned/rdoc/files/lib/version_rb.html
  161. +32 −0 vendor/plugins/simply_versioned/rdoc/fr_class_index.html
  162. +29 −0 vendor/plugins/simply_versioned/rdoc/fr_file_index.html
  163. +36 −0 vendor/plugins/simply_versioned/rdoc/fr_method_index.html
  164. +24 −0 vendor/plugins/simply_versioned/rdoc/index.html
  165. +208 −0 vendor/plugins/simply_versioned/rdoc/rdoc-style.css
  166. +4 −0 vendor/plugins/simply_versioned/tasks/simply_versioned_tasks.rake
  167. +214 −0 vendor/plugins/simply_versioned/test/simply_versioned_test.rb
  168. +56 −0 vendor/plugins/simply_versioned/test/test_helper.rb
  169. +1 −0 vendor/plugins/simply_versioned/uninstall.rb
  170. +20 −0 vendor/plugins/teldra_importer/MIT-LICENSE
  171. +13 −0 vendor/plugins/teldra_importer/README
  172. +22 −0 vendor/plugins/teldra_importer/Rakefile
  173. +9 −0 vendor/plugins/teldra_importer/init.rb
  174. +11 −0 vendor/plugins/teldra_importer/lib/mephisto/article.rb
  175. +7 −0 vendor/plugins/teldra_importer/lib/mephisto/assigned_section.rb
  176. +6 −0 vendor/plugins/teldra_importer/lib/mephisto/comment.rb
  177. +6 −0 vendor/plugins/teldra_importer/lib/mephisto/content.rb
  178. +53 −0 vendor/plugins/teldra_importer/lib/mephisto/importer.rb
  179. +5 −0 vendor/plugins/teldra_importer/lib/mephisto/section.rb
  180. +6 −0 vendor/plugins/teldra_importer/lib/mephisto/tag.rb
  181. +7 −0 vendor/plugins/teldra_importer/lib/mephisto/tagging.rb
  182. +5 −0 vendor/plugins/teldra_importer/lib/mephisto/user.rb
  183. 0 vendor/plugins/teldra_importer/lib/teldra_importer.rb
  184. +4 −0 vendor/plugins/teldra_importer/tasks/teldra_importer_tasks.rake
  185. +8 −0 vendor/plugins/teldra_importer/test/teldra_importer_test.rb
  186. +120 −0 vendor/plugins/test_spec_on_rails/README
  187. +24 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails.rb
  188. +21 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/dummy_response.rb
  189. +33 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/should_redirect.rb
  190. +42 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/should_select.rb
  191. +16 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/should_validate.rb
  192. +38 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/test_dummy.rb
  193. +29 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/test_spec_ext.rb
  194. +15 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/test_status.rb
  195. +14 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/test_template.rb
  196. +29 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/test_unit_ext.rb
  197. +25 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/test_url.rb
  198. +37 −0 vendor/plugins/test_spec_on_rails/lib/test/spec/rails/use_controller.rb
  199. +20 −0 vendor/plugins/validates_existence/MIT-LICENSE
  200. +22 −0 vendor/plugins/validates_existence/README
  201. +22 −0 vendor/plugins/validates_existence/Rakefile
  202. +1 −0 vendor/plugins/validates_existence/init.rb
  203. +47 −0 vendor/plugins/validates_existence/lib/validates_existence.rb
@@ -0,0 +1,4 @@
+.DS_Store
+config/database.yml
+routes.txt
+log/*.log
3 README
@@ -0,0 +1,3 @@
+# Teldra #
+
+a blogging system by Josh Susser
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,67 @@
+class Admin::ArticlesController < ApplicationController
+ layout "admin"
+
+ before_filter :login_required
+
+ cache_sweeper :article_sweeper, :only => [:create, :update, :destroy]
+
+ # GET /admin/articles
+ def index
+ @articles = Article.find(:all, :order => "created_at DESC")
+ end
+
+ # GET /admin/articles/:id
+ def show
+ @article = Article.find(params[:id])
+ @comments = @article.comments
+ end
+
+ # GET /admin/articles/new
+ def new
+ @article = Article.new
+ end
+
+ # GET /admin/articles/:id/edit
+ def edit
+ @article = Article.find(params[:id])
+ end
+
+ # POST /admin/articles
+ def create
+ @article = Article.new(params[:article])
+ @article.user_id = session[:user_id]
+
+ @article.published_at = Time.now
+
+ if @article.save
+ flash[:success] = 'Article was successfully created.'
+ redirect_to([:admin, @article])
+ else
+ # flash[:warning] = 'Article could not be created.'
+ render :action => "new"
+ end
+ end
+
+ # PUT /admin/articles/:id
+ def update
+ @article = Article.find(params[:id])
+
+ save_new_version = !(params[:commit].to_s !~ /save new version/i)
+ if @article.with_versioning(save_new_version) { |a| a.update_attributes(params[:article]) }
+ flash[:success] = 'Article was successfully updated.'
+ redirect_to edit_admin_article_url(@article)
+ else
+ # flash[:warning] = 'Article could not be updated.'
+ render :action => "edit"
+ end
+ end
+
+ # DELETE /admin/articles/:id
+ def destroy
+ @article = Article.find(params[:id])
+ @article.destroy
+
+ flash[:success] = 'Article was deleted.'
+ redirect_to(admin_articles_url)
+ end
+end
@@ -0,0 +1,19 @@
+class Admin::CommentsController < ApplicationController
+ layout "admin"
+
+ before_filter :login_required
+
+ cache_sweeper :article_sweeper, :only => [:destroy]
+
+ # GET /admin/comments
+ def index
+ @comments = Comment.paginate(:all, :page => params[:page], :order => "created_at DESC")
+ end
+
+ # DELETE /admin/comments/:id
+ def destroy
+ @comment = Comment.find(params[:id])
+ @comment.destroy
+ redirect_to request.referer || admin_comments_url # nil in tests
+ end
+end
@@ -0,0 +1,7 @@
+class Admin::PanelController < ApplicationController
+ layout "admin"
+ before_filter :login_required
+
+ def index
+ end
+end
@@ -0,0 +1,10 @@
+
+class ApplicationController < ActionController::Base
+ include AuthenticatedSystem
+
+ helper :all # include all helpers, all the time
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ protect_from_forgery # :secret => '436456a364e065c4bd3cb0ac2622be70'
+end
@@ -0,0 +1,87 @@
+class BlogController < ApplicationController
+
+ caches_page :index, :tags, :tag, :show, :page
+ cache_sweeper :article_sweeper, :only => [:create_comment]
+
+ before_filter :setup_sidebar, :except => [:create_comment]
+
+ # main blog page - show recent posts (short form)
+ def index
+ respond_to do |format|
+ format.html do
+ @articles = Article.posts.recent.limit(5)
+ @archives = Article.posts.recent
+ end
+ format.atom { @articles = Article.posts.recent.limit(10) }
+ end
+ end
+
+ # list all tags
+ def tags
+ @tags = Tag.find_all_popular
+ end
+
+ # show posts for :tag (result list form)
+ def tag
+ if @tag = Tag.find_by_name(params[:tag])
+ @articles = Article.find_all_by_tag_list([@tag])
+ respond_to do |format|
+ format.html
+ format.atom
+ end
+ else
+ head :not_found
+ end
+ end
+
+ def search
+ @articles = Article.search(params[:q])
+ render :action => 'results'
+ end
+
+ # show post (extended form)
+ def show
+ @article = Article.find_post_by_date_and_slug(params[:year], params[:month], params[:day], params[:slug])
+ @page_title = @article.title
+ end
+
+ # show page
+ def page
+ @article = Article.find_page_by_slug(params[:slug])
+ @page_title = @article.title
+ render :action => 'show'
+ end
+
+ def create_comment
+ @article = Article.find(params[:article_id])
+ params[:comment].merge!(:author_ip => request.remote_ip, :user_id => session[:user_id])
+ if check_comment_spam(params[:comment])
+ @comment = @article.comments.build(params[:comment])
+ if @comment.save
+ redirect_to post_url(*@article.post_path_params)
+ else
+ flash[:warning] = "COMMENT ERROR" # FIXME comment missing something
+ redirect_to post_url(*@article.post_path_params)
+ end
+ else
+ Reject.create(params[:comment].merge(:article_id => @article.id))
+ redirect_to post_url(*@article.post_path_params)
+ end
+ end
+
+ private
+
+ def setup_sidebar
+ unless request.format.to_sym == :atom
+ @tag_cloud = Tag.find_all_popular
+ end
+ end
+
+ def check_comment_spam(data)
+ if data[:body].blank?
+ data[:body] = data.delete(:tofu)
+ else
+ false
+ end
+ end
+end
@@ -0,0 +1,30 @@
+# This controller handles the login/logout function of the site.
+class SessionsController < ApplicationController
+ layout false
+
+ # render new.rhtml
+ def new
+ end
+
+ def create
+ self.current_user = User.authenticate(params[:login], params[:password])
+ if logged_in?
+ if params[:remember_me] == "1"
+ self.current_user.remember_me
+ cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
+ end
+ redirect_back_or_default(panel_url)
+ flash[:success] = "You have been logged in successfully"
+ else
+ render :action => 'new'
+ end
+ end
+
+ def destroy
+ self.current_user.forget_me if logged_in?
+ cookies.delete :auth_token
+ reset_session
+ flash[:success] = "You have been logged out."
+ redirect_to root_url
+ end
+end
@@ -0,0 +1,11 @@
+class StylesheetsController < ApplicationController
+ before_filter :set_headers
+ after_filter { |c| c.cache_page }
+ session :off
+ layout nil
+
+ private
+ def set_headers
+ headers['Content-Type'] = 'text/css; charset=utf-8'
+ end
+end
@@ -0,0 +1,2 @@
+module Admin::ArticlesHelper
+end
@@ -0,0 +1,2 @@
+module Admin::PanelHelper
+end
@@ -0,0 +1,52 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+ def if_blank(str, alternate)
+ str.blank? ? alternate : str
+ end
+
+ # flash_div
+ # use to display specified flash messages
+ # defaults to standard set: [:success, :message, :warning]
+ # example:
+ # <%= flash_div %>
+ # example with other keys:
+ # <%= flash_div :notice, :violation %>
+ # renders like:
+ # <div class="flash flash-success">Positive - successful action</div>
+ # <div class="flash flash-message">Neutral - reminders, status</div>
+ # <div class="flash flash-warning">Negative - error, unsuccessful action</div>
+ def flash_div(*keys)
+ keys = [:success, :message, :warning] if keys.empty?
+ keys.compact.collect do |key|
+ flash[key].blank? ? nil : content_tag(:div, flash[key], :class => "flash flash-#{key}")
+ end.compact.join("\n")
+ end
+
+ def current_user_name
+ session[:user_id] ? User.find(session[:user_id]).name : "beautiful stranger"
+ end
+
+ def comment_period_options
+ [['Never expire', -1],
+ ['Are not allowed', 0],
+ ['Expire 24 hours after publishing', 1],
+ ['Expire 1 week after publishing', 7],
+ ['Expire 1 month after publishing', 30],
+ ['Expire 3 months after publishing', 90]]
+ end
+
+ # defeat spam links by adding a rel="nofollow" attribute to <a> tags in submitted comments
+ def nofollowize
+ tokenizer = HTML::Tokenizer.new(text)
+ out = ""
+ while token = tokenizer.next
+ node = HTML::Node.parse(nil, 0, 0, token, false)
+ if node.tag? && node.name.downcase == "a"
+ node.attributes["rel"] = "nofollow" unless node.attributes.nil?
+ end
+ out << node.to_s
+ end
+ out
+ end
+
+end
@@ -0,0 +1,43 @@
+module BlogHelper
+
+ def doc_title
+ if @page_title
+ h("#{SITE_TITLE} - #{@page_title}")
+ else
+ h(SITE_TITLE)
+ end
+ end
+
+ def link_to_article(article)
+ link_to h(article.title), article.post? ? post_path(*article.post_path_params) : page_path(article.slug)
+ end
+
+ def links_to_tags(tags)
+ if tags.blank?
+ "[none]"
+ else
+ tags.collect { |tag| link_to h(tag.name), tag_path(tag) }.join(", ")
+ end
+ end
+
+ def tag_cloud
+ @tag_cloud.collect { |tag| link_to(h(tag.name), tag_path(tag)) }.join(" ")
+ # content_tag(:ul,
+ # @tag_cloud.collect { |tag| content_tag(:li, link_to(h(tag.name), tag_path(tag))) }.join("\n"),
+ # :id => "tags")
+ end
+
+ def archive_list
+ current_date = nil
+ list = []
+ @archives.each do |post|
+ date = Date.new(post.published_at.year, post.published_at.month, 1)
+ if date != current_date
+ current_date = date
+ list << content_tag(:li, current_date.strftime("%B %Y"), :class => "month")
+ end
+ list << content_tag(:li, link_to(h(post.title), post_path(*post.post_path_params)), :class => "post")
+ end
+ list.join("\n")
+ end
+end
@@ -0,0 +1,2 @@
+module SessionsHelper
+end
@@ -0,0 +1,2 @@
+module StylesheetsHelper
+end
Oops, something went wrong.

0 comments on commit ad84685

Please sign in to comment.