Skip to content

Commit

Permalink
Integrate Rails scss scaffolding from sass-rails.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnomalousBit committed Nov 14, 2018
1 parent f5ab1cb commit 1a7c6ba
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/rails/generators/sass/assets/assets_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "rails/generators/named_base"

module Sass
module Generators
class AssetsGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)

def copy_sass
template "stylesheet.sass", File.join('app/assets/stylesheets', class_path, "#{file_name}.sass")
end
end
end
end
3 changes: 3 additions & 0 deletions lib/rails/generators/sass/assets/templates/stylesheet.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the <%= name %> controller here.
// They will automatically be included in application.css.
// You can use Sass here: http://sass-lang.com/
9 changes: 9 additions & 0 deletions lib/rails/generators/sass/scaffold/scaffold_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "rails/generators/sass_scaffold"

module Sass
module Generators
class ScaffoldGenerator < ::Sass::Generators::ScaffoldBase
def syntax() :sass end
end
end
end
15 changes: 15 additions & 0 deletions lib/rails/generators/sass_scaffold.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "sass/css"
require "rails/generators/named_base"

module Sass
module Generators
class ScaffoldBase < ::Rails::Generators::NamedBase
def copy_stylesheet
dir = ::Rails::Generators::ScaffoldGenerator.source_root
file = File.join(dir, "scaffold.css")
converted_contents = ::Sass::CSS.new(File.read(file)).render(syntax)
create_file "app/assets/stylesheets/scaffolds.#{syntax}", converted_contents
end
end
end
end
13 changes: 13 additions & 0 deletions lib/rails/generators/scss/assets/assets_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "rails/generators/named_base"

module Scss
module Generators
class AssetsGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)

def copy_scss
template "stylesheet.scss", File.join('app/assets/stylesheets', class_path, "#{file_name}.scss")
end
end
end
end
3 changes: 3 additions & 0 deletions lib/rails/generators/scss/assets/templates/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the <%= name %> controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
10 changes: 10 additions & 0 deletions lib/rails/generators/scss/scaffold/scaffold_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "rails/generators/sass_scaffold"

module Scss
module Generators
class ScaffoldGenerator < ::Sass::Generators::ScaffoldBase
def syntax() :scss end
end
end
end

0 comments on commit 1a7c6ba

Please sign in to comment.