simple-pages 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Run the specs'
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
11
+ t.spec_files = FileList['spec/**/*_spec.rb']
12
+ end
13
+
14
+ namespace :spec do
15
+ desc "Run all specs with RCov"
16
+ Spec::Rake::SpecTask.new(:rcov) do |t|
17
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
18
+ t.spec_files = FileList['spec/**/*_spec.rb']
19
+ t.rcov = true
20
+ t.rcov_opts = ['--exclude', 'spec,/Users/']
21
+ end
22
+ end
23
+
24
+ desc 'Generate documentation for the simple_navigation plugin.'
25
+ Rake::RDocTask.new(:rdoc) do |rdoc|
26
+ rdoc.rdoc_dir = 'rdoc'
27
+ rdoc.title = 'Simple Pages'
28
+ rdoc.options << '--line-numbers' << '--inline-source'
29
+ rdoc.rdoc_files.include('README')
30
+ rdoc.rdoc_files.include('lib/**/*.rb')
31
+ end
32
+
33
+ begin
34
+ require 'jeweler'
35
+ Jeweler::Tasks.new do |gemspec|
36
+ gemspec.name = "simple-pages"
37
+ gemspec.summary = "simple-pages is a ruby library to easily render static pages in your Ruby on Rails application."
38
+ gemspec.email = "andreas.schacke@gmail.com"
39
+ gemspec.homepage = "http://github.com/andi/simple-navigation"
40
+ gemspec.description = "simple-pages is a ruby library to easily render static pages in your Ruby on Rails application."
41
+ gemspec.add_development_dependency('rspec', '>= 1.2.8')
42
+ gemspec.authors = ["Andi Schacke"]
43
+ gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
44
+ gemspec.files = FileList["[A-Z]*", "{lib,spec,rails,generators}/**/*"] - FileList["**/*.log"]
45
+ # gemspec.rubyforge_project = 'andi'
46
+ end
47
+ Jeweler::GemcutterTasks.new
48
+ # Jeweler::RubyforgeTasks.new do |rubyforge|
49
+ # rubyforge.doc_task = "rdoc"
50
+ # end
51
+ rescue LoadError => e
52
+ puts "Jeweler not available (#{e}). Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,49 @@
1
+ class SimplePagesGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+
5
+ if options[:add_route]
6
+ add_to_file "config/routes.rb", "ActionController::Routing::Routes.draw do |map|", "\n SimplePages.add_route(map, '#{route_name}')\n"
7
+ end
8
+
9
+ record do |m|
10
+ m.directory File.join(%w(app controllers))
11
+ m.directory File.join(%w(app views simple_pages))
12
+ m.file "simple_pages_controller.rb", File.join(%w(app controllers simple_pages_controller.rb))
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def add_to_file(filename, after_line, new_line)
19
+ filename = File.join(RAILS_ROOT, filename)
20
+ src = File.read filename
21
+ unless src.include? new_line
22
+ src.sub!(after_line, after_line + "\n" + new_line)
23
+ File.open(filename, 'w') {|f| f.write(src) }
24
+ end
25
+ end
26
+
27
+ def banner
28
+ "Usage: #{$0} #{spec.name} [--add-route] [--route-name NAME]"
29
+ end
30
+
31
+ def add_options!(opt)
32
+ opt.separator ''
33
+ opt.separator 'Options:'
34
+ opt.on("--add-route",
35
+ "Add simple-pages route to config/routes.rb") { |v| options[:add_route] = v }
36
+ opt.on("--route-name NAME ",
37
+ "name for the simple-pages route in config/routes.rb") { |v| options[:route_name] = v }
38
+ end
39
+
40
+ def route_name
41
+ options[:route_name] || "pages"
42
+ end
43
+
44
+
45
+ end
46
+
47
+
48
+
49
+
@@ -0,0 +1,3 @@
1
+ class SimplePagesController < ApplicationController
2
+ include SimplePages::ControllerMethods
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'simple_pages/controller_methods'
2
+
3
+ module SimplePages
4
+
5
+ def self.add_route(map, route_name)
6
+ map.send(route_name, "#{route_name}/:page", :controller => 'simple_pages', :action => 'show_page')
7
+ end
8
+
9
+ end
@@ -0,0 +1,24 @@
1
+ module SimplePages
2
+
3
+ module ControllerMethods
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ include InstanceMethods
8
+ end
9
+ end
10
+
11
+ module InstanceMethods
12
+
13
+ def show_page
14
+ target = params[:page]
15
+ render_options = {:template => "simple_pages/#{target.to_s}"}
16
+ render_options[:layout] = params[:layout] if params[:layout]
17
+ render(render_options)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SimplePages do
4
+
5
+ describe 'self.add_route' do
6
+ before(:each) do
7
+ @map = stub :map
8
+ end
9
+ it "should call route_name on map with correct params" do
10
+ @map.should_receive('pages').with("pages/:page", :controller => 'simple_pages', :action => 'show_page')
11
+ end
12
+ after(:each) do
13
+ SimplePages.add_route(@map, 'pages')
14
+ end
15
+ end
16
+
17
+
18
+ def self.add_route(map, route_name)
19
+ map.send(route_name, "#{route_name}/:page", :controller => 'simple_pages', :action => 'show_page')
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe SimplePages::ControllerMethods do
4
+
5
+ before(:each) do
6
+ @controller = Class.new {include SimplePages::ControllerMethods}.new
7
+ end
8
+
9
+ describe 'inclusion of module' do
10
+ it "should have the show_page action" do
11
+ @controller.should respond_to(:show_page)
12
+ end
13
+ end
14
+
15
+ describe 'show_page' do
16
+ context 'without layout specified' do
17
+ before(:each) do
18
+ @controller.stub!(:params => {:page => 'my_page'})
19
+ end
20
+ it {@controller.should_receive(:render).with(:template => 'simple_pages/my_page')}
21
+ end
22
+ context 'with layout specified' do
23
+ before(:each) do
24
+ @controller.stub!(:params => {:page => 'my_page', :layout => 'my_layout'})
25
+ end
26
+ it {@controller.should_receive(:render).with(:template => 'simple_pages/my_page', :layout => 'my_layout')}
27
+ end
28
+ after(:each) do
29
+ @controller.show_page
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,12 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require 'rubygems'
3
+ require 'spec'
4
+
5
+ $:.unshift File.dirname(__FILE__)
6
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
7
+
8
+ require 'simple-pages'
9
+
10
+ # Spec::Runner.configure do |config|
11
+ # no special config
12
+ # endx
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-pages
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andi Schacke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-21 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.8
24
+ version:
25
+ description: simple-pages is a ruby library to easily render static pages in your Ruby on Rails application.
26
+ email: andreas.schacke@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - Rakefile
35
+ - VERSION
36
+ - generators/simple_pages/simple_pages_generator.rb
37
+ - generators/simple_pages/templates/simple_pages_controller.rb
38
+ - lib/simple-pages.rb
39
+ - lib/simple_pages/controller_methods.rb
40
+ - spec/lib/simple-pages_spec.rb
41
+ - spec/lib/simple_pages/controller_methods_spec.rb
42
+ - spec/spec_helper.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/andi/simple-navigation
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --inline-source
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: simple-pages is a ruby library to easily render static pages in your Ruby on Rails application.
72
+ test_files:
73
+ - spec/lib/simple-pages_spec.rb
74
+ - spec/lib/simple_pages/controller_methods_spec.rb
75
+ - spec/spec_helper.rb