<commit_before># Meteor Generate
# Copyright(c) 2014 <NAME> <<EMAIL>>
# MIT Licensed
#
# Generate a component folder containing an HTML template, JavaScript file
# and a Sass file. The Sass file import is also appended to /client/sass/comps


fs = require 'fs-extra'
transformVariables = require './rename'
parseName = require './parse_name'


class Component
  constructor: (compName, opts) ->
    @compName = parseName(compName)
    @compName.original = compName
    @templatePath = templatePath + 'component/'
    @destPath = opts.directory + @compName.snake + '/'

    @copyAllTemplates()
    @renameAllTemplates()
    

  copyAllTemplates: () ->
    fs.copySync(@templatePath, @destPath)
    puts "\nComponent"
    puts "    Created: #{@compName.snake}.html"
    puts "    Created: #{@compName.snake}.js"
    puts "    Created: _#{@compName.snake}.scss"


  renameAllTemplates: (compName) ->
    for extension in [".html", ".js", ".scss"]
      filePath = @destPath + "comp_name" + extension
      @renameTempateVariables(filePath, extension)


  renameTempateVariables: (filePath, extension) ->
    oldFileStr = fs.readFileSync(filePath, {encoding: 'utf-8'})
    newFileStr = transformVariables(@compName.original, oldFileStr)
    fs.writeFileSync(filePath, newFileStr)
    @renameFile(filePath, extension)


  renameFile: (oldFilePath, ext) ->
    needsUnder = (ext == '.scss')
    fileName = if needsUnder then "_#{@compName.snake}" else @compName.snake
    newFilePath = @destPath + fileName + ext
    fs.renameSync(oldFilePath, newFilePath)


module.exports = Component
<commit_msg>add sass partial imports<commit_after># Meteor Generate
# Copyright(c) 2014 <NAME> <<EMAIL>>
# MIT Licensed
#
# Generate a component folder containing an HTML template, JavaScript file
# and a Sass file. The Sass file import is also appended to /client/sass/comps


fs = require 'fs-extra'
transformVariables = require './rename'
parseName = require './parse_name'


class Component
  constructor: (compName, opts) ->
    @compName = parseName(compName)
    @compName.original = compName
    @templatePath = templatePath + 'component/'
    @destPath = opts.directory + @compName.snake + '/'

    @copyAllTemplates()
    @renameAllTemplates()
    @appendStylesheetImport(@compName.snake)
    

  copyAllTemplates: () ->
    fs.copySync(@templatePath, @destPath)
    puts "\nComponent"
    puts "    Created: #{@compName.snake}.html"
    puts "    Created: #{@compName.snake}.js"
    puts "    Created: _#{@compName.snake}.scss"


  renameAllTemplates: () ->
    for extension in [".html", ".js", ".scss"]
      filePath = @destPath + "comp_name" + extension
      @renameTempateVariables(filePath, extension)


  renameTempateVariables: (filePath, extension) ->
    oldFileStr = fs.readFileSync(filePath, {encoding: 'utf-8'})
    newFileStr = transformVariables(@compName.original, oldFileStr)
    fs.writeFileSync(filePath, newFileStr)
    @renameFile(filePath, extension)


  renameFile: (oldFilePath, ext) ->
    needsUnder = (ext == '.scss')
    fileName = if needsUnder then "_#{@compName.snake}" else @compName.snake
    newFilePath = @destPath + fileName + ext
    fs.renameSync(oldFilePath, newFilePath)


  appendStylesheetImport: (fileName) ->
    importStr = "@import '../components/#{fileName}/#{fileName}';\n"
    fs.appendFileSync('client/styles/_components.scss', importStr)
    

module.exports = Component

{'fraction_non_alphanumeric': 0.13122437024018746, 'fraction_numerical': 0.0029291154071470417, 'mean_word_length': 3.8785714285714286, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7516943', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1080, 'n_words': 252}