ryan_francis_blog 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +32 -0
  5. data/lib/blog.rb +12 -0
  6. data/lib/blog/app/controllers/blog_admin/blog_posts_controller.rb +66 -0
  7. data/lib/blog/app/controllers/blog_posts_controller.rb +23 -0
  8. data/lib/blog/app/helpers/application_helper.rb +9 -0
  9. data/lib/blog/app/models/blog_post.rb +11 -0
  10. data/lib/blog/app/views/blog_admin/blog_posts/_form.html.erb +39 -0
  11. data/lib/blog/app/views/blog_admin/blog_posts/edit.html.erb +11 -0
  12. data/lib/blog/app/views/blog_admin/blog_posts/index.html.erb +33 -0
  13. data/lib/blog/app/views/blog_admin/blog_posts/new.html.erb +78 -0
  14. data/lib/blog/app/views/blog_admin/blog_posts/show.html.erb +14 -0
  15. data/lib/blog/app/views/blog_posts/_post.html.erb +15 -0
  16. data/lib/blog/app/views/blog_posts/index.html.erb +25 -0
  17. data/lib/blog/app/views/blog_posts/show.html.erb +1 -0
  18. data/lib/blog/config/routes.rb +13 -0
  19. data/lib/blog/version.rb +3 -0
  20. data/lib/tasks/blog_tasks.rake +4 -0
  21. data/test/blog_test.rb +7 -0
  22. data/test/dummy/README.rdoc +28 -0
  23. data/test/dummy/Rakefile +6 -0
  24. data/test/dummy/app/assets/javascripts/application.js +13 -0
  25. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  26. data/test/dummy/app/controllers/application_controller.rb +5 -0
  27. data/test/dummy/app/helpers/application_helper.rb +2 -0
  28. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  29. data/test/dummy/bin/bundle +3 -0
  30. data/test/dummy/bin/rails +4 -0
  31. data/test/dummy/bin/rake +4 -0
  32. data/test/dummy/config.ru +4 -0
  33. data/test/dummy/config/application.rb +23 -0
  34. data/test/dummy/config/boot.rb +5 -0
  35. data/test/dummy/config/database.yml +25 -0
  36. data/test/dummy/config/environment.rb +5 -0
  37. data/test/dummy/config/environments/development.rb +29 -0
  38. data/test/dummy/config/environments/production.rb +80 -0
  39. data/test/dummy/config/environments/test.rb +36 -0
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/test/dummy/config/initializers/inflections.rb +16 -0
  43. data/test/dummy/config/initializers/mime_types.rb +5 -0
  44. data/test/dummy/config/initializers/secret_token.rb +12 -0
  45. data/test/dummy/config/initializers/session_store.rb +3 -0
  46. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  47. data/test/dummy/config/locales/en.yml +23 -0
  48. data/test/dummy/config/routes.rb +56 -0
  49. data/test/dummy/public/404.html +58 -0
  50. data/test/dummy/public/422.html +58 -0
  51. data/test/dummy/public/500.html +57 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/test_helper.rb +15 -0
  54. metadata +212 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b3803d1a6048a6dd30ced25ab3b8e6d02afc5ef
4
+ data.tar.gz: 9477084b179dbc9342484140baa4cffce523182c
5
+ SHA512:
6
+ metadata.gz: 71b981d433abaffb17f0e721424c64b01fc6ceeaaffad794cebd51e1734c2510ffb358e9f07ef8dff067631bf3daf7dbad90430acff7d14bd4c6e8ccd48929d1
7
+ data.tar.gz: b5c900e8a3b6331e099cffae54c50424a5a42cc35cac254d0d53db64b087b5db7d6687351aa54c3d84d443bb1642ff224cc092302b78aa42bb14d3da06893cc9
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Blog
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Blog'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,12 @@
1
+ module Blog
2
+ end
3
+
4
+ # load Blog components
5
+ require 'blog'
6
+
7
+ %w{ models controllers }.each do |dir|
8
+ path = File.join(File.dirname(__FILE__), 'app', dir)
9
+ $LOAD_PATH << path
10
+ ActiveSupport::Dependencies.load_paths << path
11
+ ActiveSupport::Dependencies.load_once_paths.delete(path)
12
+ end
@@ -0,0 +1,66 @@
1
+ class BlogAdmin::BlogPostsController < ApplicationController
2
+ http_basic_authenticate_with name: "admin", password: "password"
3
+ before_filter :find_post, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @blogposts = BlogPost.order('updated_at DESC')
7
+ end
8
+
9
+ def show
10
+ end
11
+
12
+ def new
13
+ @blogpost = BlogPost.new
14
+ @authors = authorized_authors
15
+ end
16
+
17
+ def edit
18
+ @authors = authorized_authors
19
+ end
20
+
21
+ def create
22
+ @blogpost = BlogPost.new(params[:blog_post])
23
+ @authors = authorized_authors
24
+
25
+ if @blogpost.save
26
+ if params[:commit] == "Save Draft"
27
+ @blogpost.update_attribute(:published, false)
28
+ redirect_to blog_admin_blog_post_url(@blogpost), notice: "Post was saved as a draft"
29
+ else
30
+ redirect_to blog_admin_blog_post_url(@blogpost), notice: 'Post was successfully created.'
31
+ end
32
+ else
33
+ render action: "new"
34
+ end
35
+ end
36
+
37
+ def update
38
+ if @blogpost.update_attributes(params[:blog_post])
39
+ if params[:commit] == "Save Draft"
40
+ @blogpost.update_attribute(:published, false)
41
+ redirect_to blog_admin_blog_post_url(@blogpost), notice: "Post was updated as a draft"
42
+ else
43
+ @blogpost.update_attribute(:published, true)
44
+ redirect_to blog_admin_blog_post_url(@blogpost), notice: 'Post was successfully updated.'
45
+ end
46
+ else
47
+ render action: "edit"
48
+ end
49
+ end
50
+
51
+ def destroy
52
+ @blogpost.destroy
53
+ redirect_to admin_posts_url
54
+ end
55
+
56
+ private
57
+
58
+ def find_post
59
+ @blogpost = BlogPost.find_by_slug!(params[:id])
60
+ end
61
+
62
+ def authorized_authors
63
+ ["Tom","Scott","Brendan","Ryan"]
64
+ end
65
+
66
+ end
@@ -0,0 +1,23 @@
1
+ class BlogPostsController < ApplicationController
2
+ before_filter :find_post, only: [:show]
3
+
4
+ def index
5
+ @blogposts = BlogPost.where(published: true).order('updated_at DESC').page(params[:page]).per(10)
6
+ @title = "LaunchPad Lab's blog about web development"
7
+ end
8
+
9
+ def show
10
+ @title = @blogpost.title
11
+ end
12
+
13
+ def edit
14
+ end
15
+
16
+
17
+ private
18
+
19
+ def find_post
20
+ @blogpost = BlogPost.find_by_slug!(params[:id])
21
+ end
22
+
23
+ end
@@ -0,0 +1,9 @@
1
+ module ApplicationHelper
2
+
3
+ def markdown(text)
4
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
5
+ :autolink => true, :space_after_headers => true)
6
+ raw markdown.render(text)
7
+ end
8
+
9
+ end
@@ -0,0 +1,11 @@
1
+ class BlogPost < ActiveRecord::Base
2
+ attr_accessible :author, :content, :published, :slug, :tag, :title
3
+
4
+ extend FriendlyId
5
+ friendly_id :title, use: :slugged
6
+
7
+ def should_generate_new_friendly_id?
8
+ new_record?
9
+ end
10
+
11
+ end
@@ -0,0 +1,39 @@
1
+ <%= form_for([:blog_admin, @blogpost]) do |f| %>
2
+ <% if @blogpost.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@blogpost.errors.count, "error") %> prohibited this post from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @blogpost.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+ <div class="field">
14
+ <%= f.label :title %>
15
+ <%= f.text_field :title, size: "80" %>
16
+ </div>
17
+ <!-- <div class="field">
18
+ <%= f.label :slug %>
19
+ <%= f.text_field :slug, size: "80" %>
20
+ </div> -->
21
+ <div class="field">
22
+ <%= f.label :content %>
23
+ <%= f.text_area :content, cols: "80", rows: "20" %>
24
+ </div>
25
+ <div class="field">
26
+ <%= f.label :tag %>
27
+ <%= f.select :tag, options_for_select(%w(Coding Business Strategy Tech), @blogpost.tag) %>
28
+ </div>
29
+ <br>
30
+ <div class="field">
31
+ <%= f.label :author %>
32
+ <%= f.select :author, options_for_select(@authors, @blogpost.author) %>
33
+ </div>
34
+
35
+ <div class="actions">
36
+ <%= f.submit class: 'btn' %>
37
+ <%= f.submit "Save Draft", :class => 'btn save'%>
38
+ </div>
39
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <div class="row">
2
+ <div class="ten columns centered">
3
+ <br>
4
+ <br>
5
+ <p><%= link_to '&#8592;'.html_safe + 'Back to posts', blog_admin_blog_post_path %></p>
6
+ <h1>Edit post</h1>
7
+ <br>
8
+ <br>
9
+ <%= render 'form' %>
10
+ </div>
11
+ </div>
@@ -0,0 +1,33 @@
1
+ <div class="row">
2
+ <div class="twelve columns centered">
3
+
4
+ <h1>Blog Admin Panel</h1>
5
+ <br>
6
+ <%= link_to 'New Post', new_blog_admin_blog_post_path %>
7
+ <br>
8
+ <br>
9
+
10
+ <table class="table">
11
+ <tr>
12
+ <th>Date</th>
13
+ <th>Post</th>
14
+ <th>Edit</th>
15
+ <th>Delete</th>
16
+ </tr>
17
+
18
+ <% @blogposts.each do |post| %>
19
+ <tr>
20
+ <td class="date"><%= post.created_at.strftime('%b %d %Y') %></td>
21
+ <td class="post"><%= link_to post.title, blog_post_path(post) %></td>
22
+ <% if post.published == false %>
23
+ <td><%= link_to 'draft', edit_blog_admin_blog_post_path(post), class: 'draft' %></td>
24
+ <% else %>
25
+ <td><%= link_to 'edit', edit_blog_admin_blog_post_path(post) %></td>
26
+ <% end %>
27
+ <td><%= link_to 'delete', blog_admin_blog_post_path(post), method: :delete, data: { confirm: 'Are you sure you want to delete this post?'} %></td>
28
+ </tr>
29
+ <% end %>
30
+ </table>
31
+
32
+ </div>
33
+ </div>
@@ -0,0 +1,78 @@
1
+ <div class="row">
2
+ <div class="ten columns centered">
3
+ <div class="panel" style="margin-top: 40px">
4
+ <p>
5
+ Hey, look at you writing a blog post - nice job! This blog let's you write in a very special & awesome format called Markdown. So don't go pasting any ugly html shit in here, ok. Cool.
6
+ </p>
7
+ <p>
8
+ But, "how do I do ______ in markdown?" I'm glad you asked. Check out
9
+ <%= link_to 'our handy Markdown reference', '#', :'data-reveal-id' => 'mdModal' %>.
10
+ <!-- <a href="#" class="button" data-reveal-id="myModal2">Click Me For A Modal</a> -->
11
+ </p>
12
+ </div>
13
+
14
+ <p><%= link_to '&#8592;'.html_safe + 'Back to posts', blog_admin_blog_posts_path %></p>
15
+ <h1>New post</h1>
16
+ <%= render 'form' %>
17
+ <br/>
18
+
19
+ </div>
20
+ </div>
21
+
22
+ <div id="mdModal" class="reveal-modal xlarge">
23
+
24
+ <div class="markdown">
25
+ <h2>This is Markdown</h2>
26
+ <p>Full Markdown docs: <%= link_to 'http://daringfireball.net/projects/markdown/', 'http://daringfireball.net/projects/markdown/', :target => 'blank' %><p>
27
+ <pre>
28
+
29
+ This is a normal paragraph (just type)
30
+
31
+ # This is an H1
32
+
33
+ ## This is an H2
34
+
35
+ ### This is an H3
36
+
37
+ > This is a blockquote
38
+
39
+ # Lists can use any of these
40
+ * Red
41
+ + Blue
42
+ - Green
43
+
44
+ # Ordered lists use numbers
45
+ 1. Red
46
+ 2. Blue
47
+ 3. Green
48
+
49
+ # Links
50
+ This is [an example](http://example.com/ "Title") inline link.
51
+
52
+ [This link](http://example.net/) has no title attribute.
53
+
54
+ # Images
55
+ ![Alt text](/path/to/img.jpg)
56
+
57
+ ![Alt text](/path/to/img.jpg "Optional title")
58
+
59
+ ## Not covered by markdown
60
+ For any markup that is not covered by Markdown’s syntax, you simply use HTML.
61
+ There’s no need to preface it or delimit it to indicate that you’re switching
62
+ from Markdown to HTML; you just use the tags.
63
+
64
+ The only restrictions are that block-level HTML elements — e.g. div, table,
65
+ pre, p, etc. — must be separated from surrounding content by blank lines,
66
+ and the start and end tags of the block should not be indented with tabs or
67
+ spaces. Markdown is smart enough not to add extra (unwanted) p tags around
68
+ HTML block-level tags.
69
+
70
+ Span-level HTML tags — e.g. span, cite, or del —
71
+ can be used anywhere in a Markdown paragraph, list item, or header.
72
+ If you want, you can even use HTML tags instead of Markdown formatting;
73
+ e.g. if you’d prefer to use HTML a or img tags instead of Markdown’s link
74
+ or image syntax, go right ahead.
75
+ </pre>
76
+ <a class="close-reveal-modal">&#215;</a>
77
+
78
+ </div>
@@ -0,0 +1,14 @@
1
+ <div class="container">
2
+
3
+ <%= render '/blog_posts/post', post: @blogpost %>
4
+
5
+ <div class="row">
6
+ <div class="eight columns">
7
+ <p id="notice"><%= notice %></p>
8
+ <%= link_to 'Back to posts index', blog_admin_blog_posts_path, :class => 'button radius success' %>&nbsp;&nbsp;
9
+ <%= link_to 'Edit', edit_blog_admin_blog_post_path(@blogpost), :class => 'button radius secondary' %>&nbsp;&nbsp;
10
+ <%= link_to 'Delete', blog_admin_blog_post_path(@blogpost), :class => 'button radius secondary', method: :delete, data: { confirm: 'Are you sure?' } %>
11
+ </div>
12
+ </div>
13
+
14
+ </div>
@@ -0,0 +1,15 @@
1
+ <div class="tagline">
2
+ <h1 class="tagline"><%= link_to 'Blog', blog_path %></h2>
3
+ </div>
4
+
5
+ <div class="row">
6
+ <div class="eight columns">
7
+ <p><%= link_to '&#8592;'.html_safe + 'Back to Blog', blog_path %></p>
8
+ <article class="post_show">
9
+ <h2 class="post_title"><%= post.title %></h1>
10
+ <div class="date"><%= post.created_at.strftime('%b %d, %Y') %></div>
11
+ <div class="author">By <%= post.author %></div>
12
+ <%= render '/blog_posts/tweet', post: post, url: blog_post_url(post) %>
13
+ <div class="post_content"><%= markdown(post.content).html_safe %></div>
14
+ </article>
15
+ </div>
@@ -0,0 +1,25 @@
1
+ <div class="tagline">
2
+ <h1 class="tagline">Blog</h1>
3
+ </div>
4
+
5
+ <% if @blogposts %>
6
+ <section class="posts">
7
+ <% @blogposts.each do |post| %>
8
+ <article class="post">
9
+ <h2><%= link_to post.title, blog_post_url(post) %></h3>
10
+ <div class="date"><%= post.created_at.strftime('%b %d, %Y') %> - </div>
11
+ <div class="author">By <%= post.author %></div>
12
+ <%= render 'tweet', post: post, url: blog_post_url(post) %>
13
+ <div class="post_content">
14
+ <%= markdown(truncate post.content, length: 800).html_safe %>
15
+ </div>
16
+ <% if post.content.length > 800 %>
17
+ <p><%= link_to 'Read more', blog_post_url(post) %></p>
18
+ <% end %>
19
+ </article>
20
+ <% end %>
21
+ </section>
22
+ <div class="pagination">
23
+ <%= paginate @blogposts %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'post', post: @blogpost %>
@@ -0,0 +1,13 @@
1
+ Blog::Application.routes.draw do
2
+
3
+ root to: 'blog_posts#index'
4
+
5
+ get "blog" => 'blog_posts#index', as: 'blog'
6
+ get "blog/:id" => "blog_posts#show", as: 'blog_post'
7
+
8
+ namespace :blog_admin do
9
+ root to: 'blog_posts#index'
10
+ resources :blog_posts
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ module Blog
2
+ VERSION = "0.0.2"
3
+ end