Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial

  • Loading branch information...
commit c3ba98db4ae9d1819112f92e3d36aa6435395f7f 1 parent 82ab53a
Travis D. Warlick, Jr authored
Showing with 463 additions and 0 deletions.
  1. +120 −0 Rakefile
  2. +3 −0  app/controllers/admin/links_controller.rb
  3. +2 −0  app/controllers/admin/links_controller.rb~
  4. +2 −0  app/helpers/admin/links_helper.rb
  5. +10 −0 app/models/link.rb
  6. +10 −0 app/models/link.rb~
  7. +24 −0 app/views/admin/links/_form.html.erb
  8. +24 −0 app/views/admin/links/_form.html.erb~
  9. +4 −0 app/views/admin/links/edit.html.haml
  10. +4 −0 app/views/admin/links/edit.html.haml~
  11. +32 −0 app/views/admin/links/index.html.erb~
  12. +21 −0 app/views/admin/links/index.html.haml
  13. +21 −0 app/views/admin/links/index.html.haml~
  14. +5 −0 app/views/admin/links/new.html.erb~
  15. +4 −0 app/views/admin/links/new.html.haml
  16. +13 −0 db/migrate/20090823040143_create_links.rb
  17. +14 −0 db/migrate/20090823040143_create_links.rb~
  18. +28 −0 lib/tasks/links_extension_tasks.rake
  19. +24 −0 links_extension.rb
  20. +24 −0 links_extension.rb~
  21. +10 −0 spec/controllers/admin/links_controller_spec.rb
  22. +11 −0 spec/helpers/admin/links_helper_spec.rb
  23. +11 −0 spec/models/link_spec.rb
  24. +6 −0 spec/spec.opts
  25. +36 −0 spec/spec_helper.rb
120 Rakefile
View
@@ -0,0 +1,120 @@
+# I think this is the one that should be moved to the extension Rakefile template
+
+# In rails 1.2, plugins aren't available in the path until they're loaded.
+# Check to see if the rspec plugin is installed first and require
+# it if it is. If not, use the gem version.
+
+# Determine where the RSpec plugin is by loading the boot
+unless defined? RADIANT_ROOT
+ ENV["RAILS_ENV"] = "test"
+ case
+ when ENV["RADIANT_ENV_FILE"]
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
+ else
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
+ end
+end
+
+require 'rake'
+require 'rake/rdoctask'
+require 'rake/testtask'
+
+rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
+$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
+require 'spec/rake/spectask'
+# require 'spec/translator'
+
+# Cleanup the RADIANT_ROOT constant so specs will load the environment
+Object.send(:remove_const, :RADIANT_ROOT)
+
+extension_root = File.expand_path(File.dirname(__FILE__))
+
+task :default => :spec
+task :stats => "spec:statsetup"
+
+desc "Run all specs in spec directory"
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+namespace :spec do
+ desc "Run all specs in spec directory with RCov"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
+ end
+
+ desc "Print Specdoc for all specs"
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+
+ [:models, :controllers, :views, :helpers].each do |sub|
+ desc "Run the specs under spec/#{sub}"
+ Spec::Rake::SpecTask.new(sub) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
+ end
+ end
+
+ # Hopefully no one has written their extensions in pre-0.9 style
+ # desc "Translate specs from pre-0.9 to 0.9 style"
+ # task :translate do
+ # translator = ::Spec::Translator.new
+ # dir = RAILS_ROOT + '/spec'
+ # translator.translate(dir, dir)
+ # end
+
+ # Setup specs for stats
+ task :statsetup do
+ require 'code_statistics'
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
+ ::CodeStatistics::TEST_TYPES << "Model specs"
+ ::CodeStatistics::TEST_TYPES << "View specs"
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
+ end
+
+ namespace :db do
+ namespace :fixtures do
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
+ task :load => :environment do
+ require 'active_record/fixtures'
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
+ end
+ end
+ end
+ end
+end
+
+desc 'Generate documentation for the links extension.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'LinksExtension'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+# For extensions that are in transition
+desc 'Test the links extension.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+# Load any custom rakefiles for extension
+Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
3  app/controllers/admin/links_controller.rb
View
@@ -0,0 +1,3 @@
+class Admin::LinksController < Admin::ResourceController
+ model_class Link
+end
2  app/controllers/admin/links_controller.rb~
View
@@ -0,0 +1,2 @@
+class Admin::LinksController < Admin::ResourceController
+end
2  app/helpers/admin/links_helper.rb
View
@@ -0,0 +1,2 @@
+module Admin::LinksHelper
+end
10 app/models/link.rb
View
@@ -0,0 +1,10 @@
+class Link < ActiveRecord::Base
+ validates_presence_of :title
+ validates_presence_of :url
+ validates_format_of :url, :with => URI.regexp, :allow_blank => true
+
+ def link_html( options = {})
+ options = options.reverse_merge({:title => self.title, :href => self.url})
+ %(<a href="#{options[:href]}" title="#{options[:title]}">#{options[:title]}</a>)
+ end
+end
10 app/models/link.rb~
View
@@ -0,0 +1,10 @@
+class Link < ActiveRecord::Base
+ validates_presence_of :title
+ validates_presence_of :url
+ validates_format_of :url, :with => URI.regexp, :allow_blank => true
+
+ def link_html( options = {})
+ options = options.reverse_merge({:title => self.title, :href => self.url})
+ %(<a href="#{options[:href}]" title="#{options[:title]}">#{options[:title]}</a>)
+ end
+end
24 app/views/admin/links/_form.html.erb
View
@@ -0,0 +1,24 @@
+<% form_for [:admin, @link] do |f| %>
+ <div class="form-area">
+ <div id="link_form_area">
+ <p class="title">
+ <label for="link_title">Title</label>
+ <%= f.text_field "title", :class => 'textbox', :maxlength => 255 %>
+ </p>
+
+ <p class="url">
+ <label for="link_url">URL</label>
+ <%= f.text_field "url", :class => 'textbox', :maxlength => 255 %>
+ </p>
+
+ <span class="clear">&nbsp;</span>
+ </div>
+ </div>
+
+ <p class="buttons">
+ <%= save_model_button(@link) %>
+ <%= save_model_and_continue_editing_button(@link) %>
+ or
+ <%= link_to "Cancel", {:action => :index} %>
+ </p>
+<% end %>
24 app/views/admin/links/_form.html.erb~
View
@@ -0,0 +1,24 @@
+<% form_for [:admin, @link] do |f| %>
+ <div class="form-area">
+ <div id="link_form_area">
+ <p class="title">
+ <label for="link_title">Title</label>
+ <%= f.text_field "title", :class => 'textbox', :maxlength => 255 %>
+ </p>
+
+ <p class="url">
+ <label for="link_url">URL</label>
+ <%= f.text_field "url", :class => 'textbox', :maxlength => 255 %>
+ </p>
+
+ <span class="clear">&nbsp;</span>
+ </div>
+ </div>
+
+ <p class="buttons">
+ <%= save_model_button(@link) %>
+ <%= save_model_and_continue_editing_button(@link) %>
+ or
+ <%= link_to "Cancel", {:action => :index} %>
+ </p>
+<% end %>
4 app/views/admin/links/edit.html.haml
View
@@ -0,0 +1,4 @@
+=# include_stylesheet 'admin/links/links'
+
+%h1 Edit Link
+= render :partial => 'form'
4 app/views/admin/links/edit.html.haml~
View
@@ -0,0 +1,4 @@
+=# include_stylesheet 'admin/links/links'
+
+%h1 New Link
+= render :partial => 'form'
32 app/views/admin/links/index.html.erb~
View
@@ -0,0 +1,32 @@
+<% include_stylesheet 'admin/links/links' %>
+
+<h1>Links</h1>
+
+<p>You can enter links here, which will show up on the public side of your website.</p>
+
+<table cellspacing="0" cellpadding="0" border="0" class="index" id="links">
+
+ <thead>
+ <tr>
+ <th class="link">Link</th>
+ <th class="modify">Modify</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @links.each do |link| %>
+ <tr class="node level-1">
+ <td class="link">
+ <%= image('links/link') %>
+ <%= link_to link.title, edit_admin_link_url(:id => link.id) %>
+ </td>
+ <td class="remove">
+ <%= link_to image('remove', :alt => 'Remove link'), remove_admin_link_url(:id => link.id) %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+
+</table>
+
+<p><%= link_to image("links/new-link", :alt => "New link"), {:action => :new} %></p>
21 app/views/admin/links/index.html.haml
View
@@ -0,0 +1,21 @@
+-# include_stylesheet 'admin/links/links'
+
+%h1 Links
+
+%p You can enter links here, which will show up on the public side of your website.
+
+%table{:cellspacing => 0, :cellpadding => 0, :border => 0, :class => 'index', :id => 'links'
+ %thead
+ %tr
+ %th{:class => "link"}Link
+ %th{:class => "modify"} Modify
+ %tbody
+ - @links.each do |link|
+ %tr{:class=>"node level-1"}
+ %td{:class=>"link"}
+ = image('links/link')
+ = link_to link.title, edit_admin_link_url(:id => link.id)
+ %td{:class="remove"}
+ = link_to image('remove', :alt => 'Remove link'), remove_admin_link_url(:id => link.id)
+
+%p= link_to(image("links/new-link", :alt => "New link"), {:action => :new})
21 app/views/admin/links/index.html.haml~
View
@@ -0,0 +1,21 @@
+-# include_stylesheet 'admin/links/links'
+
+%h1 Links
+
+%p You can enter links here, which will show up on the public side of your website.
+
+%table{:cellspacing => 0, :cellpadding => 0, :border => 0, :class => 'index', :id => 'links'
+ %thead
+ %tr
+ %th{:class => "link"}Link
+ %th{:class => "modify"} Modify
+ %tbody
+ - @links.each do |link|
+ %tr{:class=>"node level-1"}
+ %td{:class=>"link"}
+ = image('links/link')
+ = link_to link.title, edit_admin_link_url(:id => link.id)
+ %td{:class="remove"}
+ = link_to image('remove', :alt => 'Remove link'), remove_admin_link_url(:id => link.id)
+
+%p= link_to(image("links/new-link", :alt => "New link"), {:action => :new})
5 app/views/admin/links/new.html.erb~
View
@@ -0,0 +1,5 @@
+<% include_stylesheet 'admin/links/links' %>
+
+<h1>New Link</h1>
+<%= render :partial => 'form' %>
+
4 app/views/admin/links/new.html.haml
View
@@ -0,0 +1,4 @@
+=# include_stylesheet 'admin/links/links'
+
+%h1 New Link
+= render :partial => 'form'
13 db/migrate/20090823040143_create_links.rb
View
@@ -0,0 +1,13 @@
+class CreateLinks < ActiveRecord::Migration
+ def self.up
+ create_table :links do |t|
+ t.string :title
+ t.string :url
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :links
+ end
+end
14 db/migrate/20090823040143_create_links.rb~
View
@@ -0,0 +1,14 @@
+class CreateLinks < ActiveRecord::Migration
+ def self.up
+ create_table :links do |t|
+ t.string :title
+ t.string :url
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :links
+ end
+end
28 lib/tasks/links_extension_tasks.rake
View
@@ -0,0 +1,28 @@
+namespace :radiant do
+ namespace :extensions do
+ namespace :links do
+
+ desc "Runs the migration of the Links extension"
+ task :migrate => :environment do
+ require 'radiant/extension_migrator'
+ if ENV["VERSION"]
+ LinksExtension.migrator.migrate(ENV["VERSION"].to_i)
+ else
+ LinksExtension.migrator.migrate
+ end
+ end
+
+ desc "Copies public assets of the Links to the instance public/ directory."
+ task :update => :environment do
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
+ puts "Copying assets from LinksExtension"
+ Dir[LinksExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
+ path = file.sub(LinksExtension.root, '')
+ directory = File.dirname(path)
+ mkdir_p RAILS_ROOT + directory, :verbose => false
+ cp file, RAILS_ROOT + path, :verbose => false
+ end
+ end
+ end
+ end
+end
24 links_extension.rb
View
@@ -0,0 +1,24 @@
+# Uncomment this if you reference any of your controllers in activate
+# require_dependency 'application'
+
+class LinksExtension < Radiant::Extension
+ version "1.0"
+ description "Store a list of links in Radiant 0.8"
+ url "http://github.com/tekwiz/radiant-links-extension"
+
+ define_routes do |map|
+ map.namespace :admin, :member => { :remove => :get } do |admin|
+ admin.resources :links
+ end
+ end
+
+ def activate
+ admin.tabs.add "Links", "/admin/links", :after => "Layouts", :visibility => [:all]
+ end
+
+ def deactivate
+ # admin.tabs.remove "Links"
+ end
+
+end
+
24 links_extension.rb~
View
@@ -0,0 +1,24 @@
+# Uncomment this if you reference any of your controllers in activate
+# require_dependency 'application'
+
+class LinksExtension < Radiant::Extension
+ version "1.0"
+ description "Store a list of links in Radiant 0.8"
+ url "http://github.com/tekwiz/radiant-links-extension"
+
+ define_routes do |map|
+ map.namespace :admin, :member => { :remove => :get } do |admin|
+ admin.resources :links
+ end
+ end
+
+ def activate
+ admin.tabs.add "Links", "/admin/links", :after => "Layouts", :visibility => [:all]
+ end
+
+ def deactivate
+ # admin.tabs.remove "Links"
+ end
+
+end
+
10 spec/controllers/admin/links_controller_spec.rb
View
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Admin::LinksController do
+
+ #Delete this example and add some real ones
+ it "should use Admin::LinksController" do
+ controller.should be_an_instance_of(Admin::LinksController)
+ end
+
+end
11 spec/helpers/admin/links_helper_spec.rb
View
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Admin::LinksHelper do
+
+ #Delete this example and add some real ones or delete this file
+ it "should include the Admin::LinksHelper" do
+ included_modules = self.metaclass.send :included_modules
+ included_modules.should include(Admin::LinksHelper)
+ end
+
+end
11 spec/models/link_spec.rb
View
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe Link do
+ before(:each) do
+ @link = Link.new
+ end
+
+ it "should be valid" do
+ @link.should be_valid
+ end
+end
6 spec/spec.opts
View
@@ -0,0 +1,6 @@
+--colour
+--format
+progress
+--loadby
+mtime
+--reverse
36 spec/spec_helper.rb
View
@@ -0,0 +1,36 @@
+unless defined? RADIANT_ROOT
+ ENV["RAILS_ENV"] = "test"
+ case
+ when ENV["RADIANT_ENV_FILE"]
+ require ENV["RADIANT_ENV_FILE"]
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
+ else
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
+ end
+end
+require "#{RADIANT_ROOT}/spec/spec_helper"
+
+Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
+
+if File.directory?(File.dirname(__FILE__) + "/matchers")
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
+end
+
+Spec::Runner.configure do |config|
+ # config.use_transactional_fixtures = true
+ # config.use_instantiated_fixtures = false
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
+
+ # You can declare fixtures for each behaviour like this:
+ # describe "...." do
+ # fixtures :table_a, :table_b
+ #
+ # Alternatively, if you prefer to declare them only once, you can
+ # do so here, like so ...
+ #
+ # config.global_fixtures = :table_a, :table_b
+ #
+ # If you declare global fixtures, be aware that they will be declared
+ # for all of your examples, even those that don't use them.
+end
Please sign in to comment.
Something went wrong with that request. Please try again.