radiant-file_system_resources-extension 1.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.
data/README.textile ADDED
@@ -0,0 +1,31 @@
1
+ h1. File System Resources
2
+
3
+ This enables the use of Radius-based layouts and snippets on the file system. Layouts go in RAILS_ROOT/radiant/layouts, and snippets go in RAILS_ROOT/radiant/snippets.
4
+
5
+ h2. Quickstart
6
+
7
+ h3. Install it
8
+
9
+ h4. Radiant ~1.0
10
+
11
+ 1. add <code>gem 'radiant-file_system_resources-extension'</code>
12
+ to your Gemfile
13
+ 2. Run <code>rake radiant:extensions:update_all</code> to initialise
14
+ the extension
15
+ 3. Run <code>rake radiant:extensions:file_system_resources:migrate</code>
16
+ 4. Restart Webserver
17
+
18
+ h4. Older versions of Radiant (without Gemfile)
19
+
20
+ 1. <code>git submodule add git://github.com/saturnflyer/radiant-file-system-resources-extension.git vendor/extensions/file_system_resources</code>
21
+ 2. Migrate it: <code>rake radiant:extensions:file_system_resources:migrate</code>
22
+ 3. Restart webserver
23
+
24
+ h3. Use it
25
+
26
+ * Create your file-based layouts/snippets
27
+ <pre>RAILS_ROOT/radiant/layouts/your-layout-name.radius
28
+ RAILS_ROOT/radiant/snippets/your-snippet-name.radius</pre>
29
+ * Register your layouts/snippets. (needed only when add/remove, not on edit)
30
+ <pre>rake radiant:extensions:file_system_resources:register</pre>
31
+ * Your newly created layouts/snippets are now available to use in admin panel.
data/Rakefile ADDED
@@ -0,0 +1,120 @@
1
+ # I think this is the one that should be moved to the extension Rakefile template
2
+
3
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
4
+ # Check to see if the rspec plugin is installed first and require
5
+ # it if it is. If not, use the gem version.
6
+
7
+ # Determine where the RSpec plugin is by loading the boot
8
+ unless defined? RADIANT_ROOT
9
+ ENV["RAILS_ENV"] = "test"
10
+ case
11
+ when ENV["RADIANT_ENV_FILE"]
12
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
13
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
14
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
15
+ else
16
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
17
+ end
18
+ end
19
+
20
+ require 'rake'
21
+ require 'rake/rdoctask'
22
+ require 'rake/testtask'
23
+
24
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
25
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
26
+ require 'spec/rake/spectask'
27
+ # require 'spec/translator'
28
+
29
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
30
+ Object.send(:remove_const, :RADIANT_ROOT)
31
+
32
+ extension_root = File.expand_path(File.dirname(__FILE__))
33
+
34
+ task :default => :spec
35
+ task :stats => "spec:statsetup"
36
+
37
+ desc "Run all specs in spec directory"
38
+ Spec::Rake::SpecTask.new(:spec) do |t|
39
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
40
+ t.spec_files = FileList['spec/**/*_spec.rb']
41
+ end
42
+
43
+ namespace :spec do
44
+ desc "Run all specs in spec directory with RCov"
45
+ Spec::Rake::SpecTask.new(:rcov) do |t|
46
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
47
+ t.spec_files = FileList['spec/**/*_spec.rb']
48
+ t.rcov = true
49
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
50
+ end
51
+
52
+ desc "Print Specdoc for all specs"
53
+ Spec::Rake::SpecTask.new(:doc) do |t|
54
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
55
+ t.spec_files = FileList['spec/**/*_spec.rb']
56
+ end
57
+
58
+ [:models, :controllers, :views, :helpers].each do |sub|
59
+ desc "Run the specs under spec/#{sub}"
60
+ Spec::Rake::SpecTask.new(sub) do |t|
61
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
62
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
63
+ end
64
+ end
65
+
66
+ # Hopefully no one has written their extensions in pre-0.9 style
67
+ # desc "Translate specs from pre-0.9 to 0.9 style"
68
+ # task :translate do
69
+ # translator = ::Spec::Translator.new
70
+ # dir = RAILS_ROOT + '/spec'
71
+ # translator.translate(dir, dir)
72
+ # end
73
+
74
+ # Setup specs for stats
75
+ task :statsetup do
76
+ require 'code_statistics'
77
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
78
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
79
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
80
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
81
+ ::CodeStatistics::TEST_TYPES << "Model specs"
82
+ ::CodeStatistics::TEST_TYPES << "View specs"
83
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
84
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
85
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
86
+ end
87
+
88
+ namespace :db do
89
+ namespace :fixtures do
90
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
91
+ task :load => :environment do
92
+ require 'active_record/fixtures'
93
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
94
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
95
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ desc 'Generate documentation for the file_system_resources extension.'
103
+ Rake::RDocTask.new(:rdoc) do |rdoc|
104
+ rdoc.rdoc_dir = 'rdoc'
105
+ rdoc.title = 'FileSystemResourcesExtension'
106
+ rdoc.options << '--line-numbers' << '--inline-source'
107
+ rdoc.rdoc_files.include('README')
108
+ rdoc.rdoc_files.include('lib/**/*.rb')
109
+ end
110
+
111
+ # For extensions that are in transition
112
+ desc 'Test the file_system_resources extension.'
113
+ Rake::TestTask.new(:test) do |t|
114
+ t.libs << 'lib'
115
+ t.pattern = 'test/**/*_test.rb'
116
+ t.verbose = true
117
+ end
118
+
119
+ # Load any custom rakefiles for extension
120
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,17 @@
1
+ - if @layout.new_record? || !@layout.file_system_resource?
2
+ = defaults[:edit_form]
3
+ - else
4
+ - if admin?
5
+ %p File System Resources are not editable in the admin UI. You'll need to edit them on the file system.
6
+ - else
7
+ %p This is a standard Layout and is not editable.
8
+ .form-area
9
+ %p
10
+ %strong Layout Location:
11
+ = @layout.path
12
+ %p
13
+ %strong Content
14
+ %div{:style => 'overflow: auto;'}
15
+ %pre
16
+ =h @layout.content
17
+ %p= link_to "Return to Layouts", admin_layouts_path
@@ -0,0 +1 @@
1
+ %td= layout.file_system_resource? ? 'Standard' : 'Editable'
@@ -0,0 +1 @@
1
+ %th.layout Type
@@ -0,0 +1,17 @@
1
+ - if @snippet.new_record? || !@snippet.file_system_resource?
2
+ = defaults[:edit_form]
3
+ - else
4
+ - if admin?
5
+ %p File System Resources are not editable in the admin UI. You'll need to edit them on the file system.
6
+ - else
7
+ %p This is a standard Snippet and is not editable.
8
+ .form-area
9
+ %p
10
+ %strong Snippet Location:
11
+ = @snippet.path
12
+ %p
13
+ %strong Content
14
+ %div{:style => 'overflow: auto;'}
15
+ %pre
16
+ =h @snippet.content
17
+ %p= link_to "Return to Snippets", admin_snippets_path
@@ -0,0 +1 @@
1
+ %td= snippet.file_system_resource? ? 'Standard' : 'Editable'
@@ -0,0 +1 @@
1
+ %th.layout Type
@@ -0,0 +1,11 @@
1
+ class AddFileSystemResources < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :layouts, :file_system_resource, :boolean
4
+ add_column :snippets, :file_system_resource, :boolean
5
+ end
6
+
7
+ def self.down
8
+ remove_column :layouts, :file_system_resource
9
+ remove_column :snippets, :file_system_resource
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'radiant-file_system_resources-extension'
3
+
4
+ class FileSystemResourcesExtension < Radiant::Extension
5
+ version RadiantFileSystemResourcesExtension::VERSION
6
+ description RadiantFileSystemResourcesExtension::DESCRIPTION
7
+ url RadiantFileSystemResourcesExtension::URL
8
+
9
+ def activate
10
+ Layout.send(:include, FileSystemResource)
11
+ Snippet.send(:include, FileSystemResource)
12
+
13
+ # Radiant chokes on these files...
14
+ # admin.layouts.index.add :thead, 'layout_type_head', :before => 'modify_header'
15
+ # admin.layouts.index.add :tbody, 'layout_type_column', :before => 'modify_cell'
16
+ # admin.snippets.index.add :thead, 'snippet_type_head', :before => 'modify_header'
17
+ # admin.snippets.index.add :tbody, 'snippet_type_column', :before => 'modify_cell'
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ module FileSystemResource
2
+ def self.included(klass)
3
+ klass.class_eval do
4
+ def content
5
+ if file_system_resource?
6
+ File.read(path)
7
+ else
8
+ self[:content]
9
+ end
10
+ end
11
+
12
+ def name
13
+ file_system_resource? ? self[:name] + '_fs' : self[:name]
14
+ end
15
+
16
+ def path
17
+ RAILS_ROOT + "/radiant/#{self.class.name.downcase.pluralize}/#{filename}.radius"
18
+ end
19
+
20
+ def content=(value)
21
+ raise "File System Resources are read-only from the admin." if file_system_resource?
22
+ self[:content] = value
23
+ end
24
+
25
+ def filename
26
+ raise "#filename should not be called unless a file_system_resource." unless file_system_resource?
27
+ self[:content]
28
+ end
29
+
30
+ def filename=(value)
31
+ self[:content] = value
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module RadiantFileSystemResourcesExtension
3
+ VERSION = '1.1'
4
+ DESCRIPTION = 'This enables the use of Radius-based layouts and snippets on the file system. Layouts go in RAILS_ROOT/radiant/layouts, and snippets go in RAILS_ROOT/radiant/snippets.'
5
+ SUMMARY = 'Adds support file system based layouts and snippets.'
6
+ URL = 'http://terralien.com/'
7
+ end
@@ -0,0 +1,71 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :file_system_resources do
4
+
5
+ desc "Runs the migration of the Fs Resources extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ FileSystemResourcesExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ p FileSystemResourcesExtension.migrations_path
12
+ FileSystemResourcesExtension.migrator.migrate
13
+ end
14
+ end
15
+
16
+ namespace :migrate do
17
+ task :rollback => :environment do
18
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
19
+ FileSystemResourcesExtension.migrator.rollback(FileSystemResourcesExtension.migrations_path, step)
20
+ end
21
+ end
22
+
23
+ desc "Copies public assets of the Fs Resources to the instance public/ directory."
24
+ task :update => :environment do
25
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
26
+ puts "Copying assets from FileSystemResourcesExtension"
27
+ Dir[FileSystemResourcesExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
28
+ path = file.sub(FileSystemResourcesExtension.root, '')
29
+ directory = File.dirname(path)
30
+ mkdir_p RAILS_ROOT + directory, :verbose => false
31
+ cp file, RAILS_ROOT + path, :verbose => false
32
+ end
33
+ unless FileSystemResourcesExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
34
+ puts "Copying rake tasks from FileSystemResourcesExtension"
35
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
36
+ mkdir_p local_tasks_path, :verbose => false
37
+ Dir[File.join FileSystemResourcesExtension.root, %w(lib tasks *.rake)].each do |file|
38
+ cp file, local_tasks_path, :verbose => false
39
+ end
40
+ end
41
+ %w(layouts snippets).each do |dir|
42
+ FileUtils.mkdir_p(RAILS_ROOT + "/radiant/#{dir}")
43
+ end
44
+ end
45
+
46
+ desc "Registers file system resources in the database (needed only when added/removed, not on edit)."
47
+ task :register => :environment do
48
+ [Layout, Snippet].each do |klass|
49
+ seen = []
50
+ fs_name = klass.name.downcase.pluralize
51
+ Dir[RAILS_ROOT + "/radiant/#{fs_name}/*.radius"].each do |f|
52
+ filename = File.basename(f, ".radius")
53
+ seen << filename
54
+ if klass.find_by_file_system_resource_and_content(true, filename)
55
+ puts "Skipped #{klass.name} #{filename} (already registered)."
56
+ next
57
+ else
58
+ name = "#{filename}"
59
+ klass.create!(:name => name, :filename => filename, :file_system_resource => true)
60
+ puts "Registered #{klass.name} #{filename}."
61
+ end
62
+ end
63
+ klass.find_all_by_file_system_resource(true).reject{|e| seen.include?(e.filename)}.each do |e|
64
+ e.destroy
65
+ puts "Removed #{klass.name} #{e.filename} (no longer exists on file system)."
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'radiant-file_system_resources-extension'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-file_system_resources-extension"
7
+ s.version = RadiantFileSystemResourcesExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Nathaniel Talbott', 'Jim Gay', 'John Muhl']
10
+ s.email = 'nathaniel@talbott.ws'
11
+ s.homepage = RadiantFileSystemResourcesExtension::URL
12
+ s.summary = RadiantFileSystemResourcesExtension::SUMMARY
13
+ s.description = RadiantFileSystemResourcesExtension::DESCRIPTION
14
+
15
+ ignores = if File.exist?('.gitignore')
16
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
17
+ else
18
+ []
19
+ end
20
+
21
+ s.files = Dir['**/*'] - ignores
22
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
23
+ s.require_paths = ["lib"]
24
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-file_system_resources-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 1
9
+ version: "1.1"
10
+ platform: ruby
11
+ authors:
12
+ - Nathaniel Talbott
13
+ - Jim Gay
14
+ - John Muhl
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-10-21 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: This enables the use of Radius-based layouts and snippets on the file system. Layouts go in RAILS_ROOT/radiant/layouts, and snippets go in RAILS_ROOT/radiant/snippets.
24
+ email: nathaniel@talbott.ws
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - app/views/admin/layouts/_edit_form.html.haml
33
+ - app/views/admin/layouts/_layout_type_column.html.haml
34
+ - app/views/admin/layouts/_layout_type_head.html.haml
35
+ - app/views/admin/snippets/_edit_form.html.haml
36
+ - app/views/admin/snippets/_snippet_type_column.html.haml
37
+ - app/views/admin/snippets/_snippet_type_head.html.haml
38
+ - db/migrate/20090824193729_add_file_system_resources.rb
39
+ - file_system_resources_extension.rb
40
+ - lib/file_system_resource.rb
41
+ - lib/radiant-file_system_resources-extension.rb
42
+ - lib/tasks/file_system_resources_extension_tasks.rake
43
+ - radiant-file_system_resources-extension.gemspec
44
+ - Rakefile
45
+ - README.textile
46
+ has_rdoc: true
47
+ homepage: http://terralien.com/
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.4.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Adds support file system based layouts and snippets.
80
+ test_files: []
81
+